Sha256: e281bdd92c2f74d5617980a98942de98637991c40f489d8bb70d8e35cb31370d
Contents?: true
Size: 1.3 KB
Versions: 13
Compression:
Stored size: 1.3 KB
Contents
require "social_avatar_proxy/remote_file_resolver" module SocialAvatarProxy class Avatar attr_reader :identifier def initialize(identifier) @identifier = identifier end # downloads the avatar from the remote server def body response.body end # returns whether the avatar returns a successful response def exist? @exists ||= begin # ensure the response is success/redirect response.code.to_i.between?(200, 399) end end alias_method :exists?, :exist? # returns the last modified timestamp def last_modified @last_modified ||= begin response["last-modified"] && Time.parse(response["last-modified"]) or Time.now end end # returns the content type of the file def content_type @content_type ||= begin response["content-type"] || "image/jpeg" end end # returns whether the avatar has changed def modified_since?(timestamp) last_modified > timestamp end # in the base Avatar class, we'll use the identifier as the URL def remote_url identifier end private # request the remote file def response @response ||= RemoteFileResolver.new(remote_url).resolve end end end
Version data entries
13 entries across 13 versions & 1 rubygems