Class: MonkeyParty::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/monkey_party/account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, get

Constructor Details

#initialize(attrs = {}) ⇒ Account

Returns a new instance of Account.



5
6
7
8
9
# File 'lib/monkey_party/account.rb', line 5

def initialize(attrs = {})
  self.keys ||= []
  self.keys << attrs.delete(:api_key) if attrs[:api_key]
  super
end

Instance Attribute Details

#keysObject

Returns the value of attribute keys.



3
4
5
# File 'lib/monkey_party/account.rb', line 3

def keys
  @keys
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/monkey_party/account.rb', line 3

def password
  @password
end

#user_nameObject

Returns the value of attribute user_name.



3
4
5
# File 'lib/monkey_party/account.rb', line 3

def user_name
  @user_name
end

Class Method Details

.login(user_name, password) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/monkey_party/account.rb', line 16

def (user_name, password)
  response = get("", :query => {
    :method   => "login", 
    :username => user_name, 
    :password => password
  })["MCAPI"]

   = new
  
  .keys << response
  .user_name = user_name
  .password = password

  #set a global api key
  configatron.mailchimp.api_key = response

  
end

Instance Method Details

#add_api_keyObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/monkey_party/account.rb', line 36

def add_api_key
  response = self.class.get("", :query => {
    :method   => "apikeyAdd",
    :username => self.user_name,
    :password => self.password,
    :apikey   => self.api_key
  })["MCAPI"]

  self.keys << response
  response
end

#api_keyObject



11
12
13
# File 'lib/monkey_party/account.rb', line 11

def api_key
  self.keys[0]
end