Class: Chimpy::EmailService
- Inherits:
-
Object
- Object
- Chimpy::EmailService
- Defined in:
- lib/chimpy/email_service.rb
Instance Attribute Summary collapse
-
#mailchimp ⇒ Object
readonly
Returns the value of attribute mailchimp.
-
#mailchimp_api_key ⇒ Object
readonly
Returns the value of attribute mailchimp_api_key.
-
#mailchimp_list_id ⇒ Object
readonly
Returns the value of attribute mailchimp_list_id.
Instance Method Summary collapse
-
#initialize ⇒ EmailService
constructor
A new instance of EmailService.
- #sync(users) ⇒ Object
Constructor Details
#initialize ⇒ EmailService
Returns a new instance of EmailService.
7 8 9 10 11 |
# File 'lib/chimpy/email_service.rb', line 7 def initialize @mailchimp_api_key = Chimpy.configuration.mailchimp_api_key @mailchimp_list_id = Chimpy.configuration.mailchimp_list_id @mailchimp = create_mailchimp_client end |
Instance Attribute Details
#mailchimp ⇒ Object (readonly)
Returns the value of attribute mailchimp.
5 6 7 |
# File 'lib/chimpy/email_service.rb', line 5 def mailchimp @mailchimp end |
#mailchimp_api_key ⇒ Object (readonly)
Returns the value of attribute mailchimp_api_key.
5 6 7 |
# File 'lib/chimpy/email_service.rb', line 5 def mailchimp_api_key @mailchimp_api_key end |
#mailchimp_list_id ⇒ Object (readonly)
Returns the value of attribute mailchimp_list_id.
5 6 7 |
# File 'lib/chimpy/email_service.rb', line 5 def mailchimp_list_id @mailchimp_list_id end |
Instance Method Details
#sync(users) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/chimpy/email_service.rb', line 13 def sync(users) struct = users.map { |user| { email: { email: user.email } } } response = mailchimp.lists.batch_subscribe(id: mailchimp_list_id, batch: struct, update_existing: true, double_optin: false) synced_users(response) end |