Class: Mailchimpv3::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mailchimpv3.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ API

Returns a new instance of API.



11
12
13
14
15
16
17
18
# File 'lib/mailchimpv3.rb', line 11

def initialize(api_key)
  unless api_key =~ /\w+-\w{3}/
    raise StandardError
  end
  server = api_key.split('-')[1]
  self.class.base_uri "https://#{server}.api.mailchimp.com/3.0"
  @auth = {username: 'apikey', password: api_key}
end

Instance Method Details

#account_detailsObject



20
21
22
# File 'lib/mailchimpv3.rb', line 20

def 
  self.class.get('/', :basic_auth => @auth).parsed_response
end

#get(url, recieve_params = "") ⇒ Object



41
42
43
44
45
46
# File 'lib/mailchimpv3.rb', line 41

def get(url, recieve_params="")
  self.class.get(url,
    :basic_auth => @auth,
    :query => {fields: recieve_params}
  ).parsed_response
end

#list(name = "", contact = {}, permission_reminder = "", campaign_defaults = {}, member_count = 0, email_type_option = true) ⇒ Object



28
29
30
31
32
# File 'lib/mailchimpv3.rb', line 28

def list(name ="", contact={}, permission_reminder="",
              campaign_defaults={},member_count=0, email_type_option=true)
  List.new(self, name, contact, permission_reminder,
                campaign_defaults,member_count, email_type_option=true)
end

#listsObject



24
25
26
# File 'lib/mailchimpv3.rb', line 24

def lists
  Lists.new self
end

#post(url, params = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/mailchimpv3.rb', line 34

def post(url, params={})
  self.class.post(url,
    :basic_auth => @auth,
    :headers => @headers,
    :body => params.to_json
  ).parsed_response
end