Class: Lettr::ApiMailing

Inherits:
Struct
  • Object
show all
Includes:
Deliverable, ObjectConverter, Resource
Defined in:
lib/lettr/api_mailing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute delivery_options to.



8
9
10
# File 'lib/lettr/api_mailing.rb', line 8

def delivery_options=(value)
  @delivery_options = value
end

#identifierObject

Returns the value of attribute identifier

Returns:

  • (Object)

    the current value of identifier



1
2
3
# File 'lib/lettr/api_mailing.rb', line 1

def identifier
  @identifier
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



1
2
3
# File 'lib/lettr/api_mailing.rb', line 1

def subject
  @subject
end

#variablesObject

Returns the value of attribute variables

Returns:

  • (Object)

    the current value of variables



1
2
3
# File 'lib/lettr/api_mailing.rb', line 1

def variables
  @variables
end

Instance Method Details

#append_used_variablesObject



26
27
28
# File 'lib/lettr/api_mailing.rb', line 26

def append_used_variables
  @hash.merge! :variables => variables
end

#group_variablesObject



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_optionsObject



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
  # 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!(options_to_hash(name))
    end
  end
end

#reloadObject



22
23
24
# File 'lib/lettr/api_mailing.rb', line 22

def reload
  self.send(:initialize, 'api_mailing' => self.class.find(identifier).attributes)
end