Class: EasyMailchimp::Base
- Inherits:
-
Object
- Object
- EasyMailchimp::Base
- Defined in:
- lib/easy_mailchimp/base.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #create_member(list_id, info = {}) ⇒ Object
- #get_list_name(list_id) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/easy_mailchimp/base.rb', line 3 def initialize @config = ::EasyMailchimp.config @logger = ::EasyMailchimp::Logger.new(@config.logger) @gibbon = ::Gibbon::Request.new({ api_key: @config.api_key, api_endpoint: endpoint, timeout: 60 }) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/easy_mailchimp/base.rb', line 14 def logger @logger end |
Instance Method Details
#create_member(list_id, info = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/easy_mailchimp/base.rb', line 16 def create_member(list_id, info = {}) email = info[:email] || '' first_name = info[:first_name] || '' last_name = info[:last_name] || '' begin @gibbon.lists(list_id).members.create({ body: { email_address: email, status: 'subscribed', merge_fields: {FNAME: first_name, LNAME: last_name} } }) rescue ::Gibbon::MailChimpError => ex logger.info("ERROR: #{ex.} - #{ex.raw_body}", 'Mailchimp::Base#create_member') raise end end |
#get_list_name(list_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/easy_mailchimp/base.rb', line 36 def get_list_name(list_id) list_map = {} lists = @gibbon.lists.retrieve['lists'] lists.map { |hsh| list_map[hsh["id"]] = hsh["name"] } list_map.select { |k,v| k == list_id }.values.first rescue => ex logger.info("ERROR: #{ex.}", 'Mailchimp::Base#get_list_name') raise end |