Class: MLS::Photo

Inherits:
Resource show all
Defined in:
lib/mls/models/photo.rb

Defined Under Namespace

Classes: Parser

Instance Attribute Summary

Attributes inherited from Resource

#errors, #persisted

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #create!, inherited, #initialize, #new_record?, #persisted?, #properties, #properties_excluded_from_comparison, #properties_for_comparison, #save, #save!, #set_default_values, #to_hash, #to_key, #update!, #update_attributes

Constructor Details

This class inherits a constructor from MLS::Resource

Class Method Details

.create(attrs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/mls/models/photo.rb', line 18

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

Instance Method Details

#url(style = 'large', protocol = 'http') ⇒ Object



14
15
16
# File 'lib/mls/models/photo.rb', line 14

def url(style='large', protocol='http')
  "#{protocol}://#{MLS.asset_host}/photos/#{style}/#{@digest}.jpg"
end