Class: Lettr::ApiMailing
- Inherits:
-
Struct
- Object
- Struct
- Lettr::ApiMailing
- Includes:
- Deliverable, ObjectConverter, Resource
- Defined in:
- lib/lettr/api_mailing.rb
Instance Attribute Summary collapse
-
#delivery_options ⇒ Object
writeonly
Sets the attribute delivery_options.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #append_used_variables ⇒ Object
- #group_variables ⇒ Object
- #handle_options ⇒ Object
-
#initialize(attributes = {}) ⇒ ApiMailing
constructor
A new instance of ApiMailing.
- #reload ⇒ Object
Methods included from Deliverable
#build_delivery_record, #build_initial_delivery_hash, #deliver, included, #recipient?
Methods included from ObjectConverter
#evaluate_collections, #handle_collection_variable, #handle_methods, #handle_new_collection, #is_collection_variable?, #options_to_hash
Methods included from Resource
#attributes, #client, #destroy, included, #path, #resource_name, #save, #to_json, #to_payload
Constructor Details
#initialize(attributes = {}) ⇒ ApiMailing
Returns a new instance of ApiMailing.
10 11 12 13 14 |
# File 'lib/lettr/api_mailing.rb', line 10 def initialize attributes={} attributes['api_mailing'].each do |key, value| send("#{key}=", value) end end |
Instance Attribute Details
#delivery_options=(options) ⇒ Object (writeonly)
Sets the attribute delivery_options
8 9 10 |
# File 'lib/lettr/api_mailing.rb', line 8 def (value) @delivery_options = value end |
#identifier ⇒ Object
Returns the value of attribute identifier
1 2 3 |
# File 'lib/lettr/api_mailing.rb', line 1 def identifier @identifier end |
#subject ⇒ Object
Returns the value of attribute subject
1 2 3 |
# File 'lib/lettr/api_mailing.rb', line 1 def subject @subject end |
#variables ⇒ Object
Returns the value of attribute variables
1 2 3 |
# File 'lib/lettr/api_mailing.rb', line 1 def variables @variables end |
Instance Method Details
#append_used_variables ⇒ Object
26 27 28 |
# File 'lib/lettr/api_mailing.rb', line 26 def append_used_variables @hash.merge! :variables => variables end |
#group_variables ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/lettr/api_mailing.rb', line 30 def group_variables @vars = {} variables.each do |var| methods = var.match(/^(\w+)\..+/) @vars[methods[1]] ||= [] @vars[methods[1]] << var end end |
#handle_options ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lettr/api_mailing.rb', line 39 def # handle options @delivery_options.each do |name, object| case when object.is_a?( Hash ) # variablen als @hash übergeben @hash.merge!( name => object ) when object.respond_to?( :to_nb_hash ) # object liefert variablen @hash.merge!( name => object.to_nb_hash) when object.is_a?( String ) if name.to_s == 'text' || name.to_s == 'html' raise ArgumentError.new 'You cannot use Delivery Method, Lettr::Mailer or Manual Mailing with existing identifiers.' end @files.merge!( name => File.new(object, 'rb')) else # do magic stuff @hash.merge!((name)) end end end |
#reload ⇒ Object
22 23 24 |
# File 'lib/lettr/api_mailing.rb', line 22 def reload self.send(:initialize, 'api_mailing' => self.class.find(identifier).attributes) end |