Method: MLS::Flyer.create

Defined in:
lib/mls/models/flyer.rb

.create(attrs) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mls/models/flyer.rb', line 19

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