require 'restclient' class MLS::Photo < MLS::Resource attribute :id, Fixnum attribute :digest, String attribute :created_at, DateTime attribute :updated_at, DateTime attribute :file_content_type, String attribute :file_name, String attribute :file_size, Fixnum attribute :url_template, String attribute :caption, String attribute :subject_id, Fixnum def url(style=nil, protocol='http') result = "#{protocol}://#{MLS.image_host}/#{digest}.jpg" if style result = result + "?s=#{URI.escape(style)}" end result end def self.create(attrs) attrs[:file].rewind url = MLS.url.dup url.user = nil url.path = "/api/photos" response = RestClient.post(url.to_s, {:photo => attrs}, MLS.headers) attrs[:file].close unless attrs[:file].closed? MLS::Photo::Parser.parse(response.body) end end class MLS::Photo::Parser < MLS::Parser end