Class: LaunchrockSync::SyncClient::MailChimpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/launchrock-sync/models/sync_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ MailChimpClient

Returns a new instance of MailChimpClient.



64
65
66
# File 'lib/launchrock-sync/models/sync_client.rb', line 64

def initialize(attributes)
  self.attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



62
63
64
# File 'lib/launchrock-sync/models/sync_client.rb', line 62

def attributes
  @attributes
end

Instance Method Details

#add(email) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/launchrock-sync/models/sync_client.rb', line 68

def add(email)
  api.listSubscribe( {
    :id            => list['id'], 
    :email_address => email, 
    :merge_vars    => Hash.new,
    :double_optin  => false,
    :send_welcome  => false
  } )
end

#apiObject



82
83
84
# File 'lib/launchrock-sync/models/sync_client.rb', line 82

def api
  @api ||= Mailchimp::API.new(attributes[:api_key])
end

#listObject



78
79
80
# File 'lib/launchrock-sync/models/sync_client.rb', line 78

def list
  @list ||= api.lists['data'].find {|a| a['name'] == attributes[:list] }
end