Sha256: 2be0e7430413a62302175c40218506cdffdee81b7f24ef3d6f44e0c97df45d96

Contents?: true

Size: 975 Bytes

Versions: 9

Compression:

Stored size: 975 Bytes

Contents

require 'restclient'

class MLS::Flyer < MLS::Resource

  property :id, Fixnum
  property :subject_id, Fixnum
  property :subject_type, String
  property :created_at, DateTime
  property :updated_at, DateTime
  property :file_content_type, String
  property :file_name, String
  property :file_size, Fixnum
  property :url, String

  def self.create(attrs)
    attrs[:file].rewind
    url = MLS.url.dup
    url.user = nil
    url.path = "/api/flyers"
    
    if attrs[:subject]
      attrs[:subject_id] = attrs[:subject].id
      attrs[:subject_type] = attrs[:subject].class.name.split("::").last
      attrs.delete(:subject)
    end
    response = RestClient.post(url.to_s, {:flyer => attrs}, MLS.headers)
    attrs[:file].close unless attrs[:file].closed?

    MLS::Flyer::Parser.parse(response.body)
  end
  
  def self.find(id)
    response = MLS.get("/flyers/#{id}")
    MLS::Flyer::Parser.parse(response.body)
  end
  
end

class MLS::Flyer::Parser < MLS::Parser

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mls-0.2.9 lib/mls/models/flyer.rb
mls-0.2.8.2 lib/mls/models/flyer.rb
mls-0.2.8.1 lib/mls/models/flyer.rb
mls-0.2.8 lib/mls/models/flyer.rb
mls-0.2.7 lib/mls/models/flyer.rb
mls-0.2.6 lib/mls/models/flyer.rb
mls-0.2.5 lib/mls/models/flyer.rb
mls-0.2.4 lib/mls/models/flyer.rb
mls-0.2.3 lib/mls/models/flyer.rb