Sha256: 5c0553e8771302542ff338f6b5752f5993b954537962ad0580847105ca1250a2

Contents?: true

Size: 937 Bytes

Versions: 16

Compression:

Stored size: 937 Bytes

Contents

require 'restclient'

class MLS::Photo < MLS::Resource

  property :id, Fixnum
  property :digest, String
  property :created_at, DateTime
  property :updated_at, DateTime
  property :file_content_type, String
  property :file_name, String
  property :file_size, Fixnum
  property :url_template, String
  property :caption, String
  property :similar_subject_id, Fixnum, :serialize => false

  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, {:file => attrs[:file]}, MLS.headers)
    attrs[:file].close unless attrs[:file].closed?

    MLS::Photo::Parser.parse(response.body)
  end
  
end

class MLS::Photo::Parser < MLS::Parser

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mls-0.7.1 lib/mls/models/photo.rb
mls-0.7.0 lib/mls/models/photo.rb
mls-0.6.7 lib/mls/models/photo.rb
mls-0.6.6 lib/mls/models/photo.rb
mls-0.6.5 lib/mls/models/photo.rb
mls-0.6.4 lib/mls/models/photo.rb
mls-0.6.3 lib/mls/models/photo.rb
mls-0.6.2 lib/mls/models/photo.rb
mls-0.6.1 lib/mls/models/photo.rb
mls-0.6.0 lib/mls/models/photo.rb
mls-0.5.12 lib/mls/models/photo.rb
mls-0.5.11 lib/mls/models/photo.rb
mls-0.5.10 lib/mls/models/photo.rb
mls-0.5.9 lib/mls/models/photo.rb
mls-0.5.8 lib/mls/models/photo.rb
mls-0.5.7 lib/mls/models/photo.rb