Class: MonkeyWrench::Config

Inherits:
Base
  • Object
show all
Defined in:
lib/monkey_wrench/config.rb

Instance Method Summary collapse

Methods inherited from Base

apikey, base_uri, datacenter, default_options, get, handle_errors, post

Constructor Details

#initialize(credentials) ⇒ Config

Establishes a connection to the Mailchimp API.

Can be called with either a path to a file containing credentials, or a hash of credentials. The formats of each are:

File:

mailchimp:
  datacenter: us1 # Or whatever DC you use
  apikey: your-api-key-goes-here

Hash:

{ :datacenter => "us1", :apikey => "your-api-key-goes-here"}

containing the credentials, or a hash of credentials.

Examples:

MonkeyWrench::Config.new(:datacenter => "us1", 
                         :apikey => "your-api-key-goes-here")

Parameters:

  • credentials (String, Hash)

    accepts either a String pointing to a file



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/monkey_wrench/config.rb', line 22

def initialize(credentials)
  if credentials.is_a?(String)
    config = YAML.load_file(credentials)["mailchimp"]
    config.collect_kv!{|k,v| [k.to_sym, v]}
  else
    config = credentials
  end
  @@apikey = config[:apikey]
  @@datacenter = config[:datacenter]
  super({})
end