Class: Mailchimp::Mandrill

Inherits:
Base
  • Object
show all
Defined in:
lib/mailchimp/mandrill.rb

Class Attribute Summary collapse

Attributes inherited from Base

#api_key, #options, #timeout

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#dc_from_api_key

Constructor Details

#initialize(api_key = nil, default_parameters = {}) ⇒ Mandrill

Returns a new instance of Mandrill.



9
10
11
12
13
14
15
16
17
# File 'lib/mailchimp/mandrill.rb', line 9

def initialize(api_key = nil, default_parameters = {})
  super(api_key, {
    :key => api_key,
    :options => {
      :track_opens => true,
      :track_clicks => true
    }
  }.merge(default_parameters))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



27
28
29
30
31
# File 'lib/mailchimp/mandrill.rb', line 27

def method_missing(method, *args)
  match = method.to_s.match(/([a-z]*)_([a-z]*)_?([a-z]*)/)
  method = "#{match[1]}/#{match[2]}#{match[3] == '' ? "" : "-"+match[3]}"
  call(method, *args)
end

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



35
36
37
# File 'lib/mailchimp/mandrill.rb', line 35

def api_key
  @api_key
end

Class Method Details

.method_missing(sym, *args, &block) ⇒ Object



37
38
39
# File 'lib/mailchimp/mandrill.rb', line 37

def method_missing(sym, *args, &block)
  new(self.api_key).send(sym, *args, &block)
end

Instance Method Details

#call(method, params = {}) ⇒ Object



23
24
25
# File 'lib/mailchimp/mandrill.rb', line 23

def call(method, params = {})
  super("#{base_api_url}#{method}",@default_params.merge(params))
end

#valid_api_key?(*args) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/mailchimp/mandrill.rb', line 19

def valid_api_key?(*args)
  '"PONG!"' == self.users_ping
end