Class: ChimpLight::Api

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

Instance Method Summary collapse

Constructor Details

#initialize(apikey, opts = {}) ⇒ Api

Returns a new instance of Api.



3
4
5
6
7
8
9
10
# File 'lib/chimp_light.rb', line 3

def initialize( apikey, opts = {})
  opts[:dc] ||= 'us1'
  opts[:version] ||= '1.3'
  opts[:protocol] = opts[:ssl] ? "https" : "http"

  @apikey = apikey
  @base_url = "%s://%s.api.mailchimp.com/%s/" % opts.values_at(:protocol, :dc, :version)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, opts = {}) ⇒ Object



12
13
14
# File 'lib/chimp_light.rb', line 12

def method_missing(meth, opts = {})
  Curl::Easy.http_post "%s?method=%s" % [@base_url, meth], CGI.escape( opts.reverse_merge( :apikey => @apikey ).to_json)
end