Class: Lettr::Delivery

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/lettr/delivery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Resource

#client, #destroy, included, #path, #resource_name, #to_json, #to_payload

Constructor Details

#initialize(a_hash, files) ⇒ Delivery

Returns a new instance of Delivery.



5
6
7
8
9
# File 'lib/lettr/delivery.rb', line 5

def initialize a_hash, files
  super
  @params = a_hash
  @files = files
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



3
4
5
# File 'lib/lettr/delivery.rb', line 3

def files
  @files
end

Instance Method Details

#attributesObject



11
12
13
# File 'lib/lettr/delivery.rb', line 11

def attributes
  @params
end

#collection_pathObject



30
31
32
# File 'lib/lettr/delivery.rb', line 30

def collection_path
  "api_mailings/#{attributes[:api_mailing_id]}/deliveries"
end

#dump_jsonObject



21
22
23
24
25
26
27
28
# File 'lib/lettr/delivery.rb', line 21

def dump_json
  if defined? Rails
    path = File.join(Rails.root, 'log')
    File.open(File.join(path, "lettr-delivery-#{Time.now}.json"), 'w') do |f|
      f.write attributes.to_json
    end
  end
end

#saveObject



15
16
17
18
19
# File 'lib/lettr/delivery.rb', line 15

def save
  unless super
    dump_json
  end
end