Sha256: 0705180ecbb30f6c166fb4f13b85057e326201549babbb0554b32b4d8fff721d

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module MonkeyParty
  class Account < Base
    attr_accessor :user_name, :password, :keys
    
    def initialize(attrs = {})
      self.keys ||= []
      self.keys << attrs.delete(:api_key) if attrs[:api_key]
      super
    end

    def api_key
      self.keys[0]
    end

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

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

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

        account
      end
    end

    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
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
dpickett-monkey_party-0.0.1 lib/monkey_party/account.rb
dpickett-monkey_party-0.0.3 lib/monkey_party/account.rb
dpickett-monkey_party-0.1.0 lib/monkey_party/account.rb
monkey_party-0.2.0 lib/monkey_party/account.rb