Class: MaleChimp::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/malechimp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, url = API::URL) ⇒ Base

Try to grab the API key out of env and use the default end-point URL



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

def initialize(api_key, url=API::URL)
  @api_key, @url = api_key, url
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



16
17
18
# File 'lib/malechimp.rb', line 16

def api_key
  @api_key
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/malechimp.rb', line 16

def url
  @url
end

Instance Method Details

#list(name) ⇒ Object

Find a list by name.



32
33
34
# File 'lib/malechimp.rb', line 32

def list(name)
  lists.find{ |l| l.name == name }
end

#listsObject

Returns all of the mailing lists in Chimp.



24
25
26
27
28
29
# File 'lib/malechimp.rb', line 24

def lists
  # In MailChimps infinite wisdom, they implemented REST inside of RPC, so you see stupid stuff like the .data root key.
  @lists ||= call('lists')['data'].map do |list|
    List.new(self, list)
  end
end

#serverObject

Zie oh so wunderful API shinannigans



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

def server
  @server ||= XMLRPC::Client.new2(url)
end