Module: MailchimpSubscriber
- Defined in:
- lib/mailchimp_subscriber/railtie.rb,
lib/mailchimp_subscriber/extensions.rb
Defined Under Namespace
Modules: ClassMethods Classes: Railtie
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#delete_member ⇒ Object
Returns the value of attribute delete_member.
-
#double_optin ⇒ Object
Returns the value of attribute double_optin.
-
#email ⇒ Object
Returns the value of attribute email.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#replace_interests ⇒ Object
Returns the value of attribute replace_interests.
-
#send_goodbye ⇒ Object
Returns the value of attribute send_goodbye.
-
#send_notify ⇒ Object
Returns the value of attribute send_notify.
-
#send_welcome ⇒ Object
Returns the value of attribute send_welcome.
-
#update_existing ⇒ Object
Returns the value of attribute update_existing.
Class Method Summary collapse
- .connect(mailchimp_api_key) ⇒ Object
- .included(base) ⇒ Object
- .parse_options(record, options) ⇒ Object
- .subscribe(record, list_name, options) ⇒ Object
- .unsubscribe(record, list_name, options) ⇒ Object
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def api_key @api_key end |
#content_type ⇒ Object
Returns the value of attribute content_type.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def content_type @content_type end |
#delete_member ⇒ Object
Returns the value of attribute delete_member.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def delete_member @delete_member end |
#double_optin ⇒ Object
Returns the value of attribute double_optin.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def double_optin @double_optin end |
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def email @email end |
#fields ⇒ Object
Returns the value of attribute fields.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def fields @fields end |
#replace_interests ⇒ Object
Returns the value of attribute replace_interests.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def replace_interests @replace_interests end |
#send_goodbye ⇒ Object
Returns the value of attribute send_goodbye.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def send_goodbye @send_goodbye end |
#send_notify ⇒ Object
Returns the value of attribute send_notify.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def send_notify @send_notify end |
#send_welcome ⇒ Object
Returns the value of attribute send_welcome.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def send_welcome @send_welcome end |
#update_existing ⇒ Object
Returns the value of attribute update_existing.
3 4 5 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 3 def update_existing @update_existing end |
Class Method Details
.connect(mailchimp_api_key) ⇒ Object
27 28 29 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 27 def self.connect(mailchimp_api_key) Hominid::API.new(mailchimp_api_key) end |
.included(base) ⇒ Object
5 6 7 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 5 def self.included(base) base.extend(ClassMethods) end |
.parse_options(record, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 31 def self.(record,) @api_key = [:using][:api_key] @email = record.send([:using][:email]) @fields = [:using][:fields] ? [:using][:fields].inject({}) { |h, (k, v)| h[k] = record.send(v); h } : {} @content_type = [:using][:content_type] || 'html' @double_optin = [:using][:double_optin] || false @update_existing = [:using][:update_existing] || true @replace_interests = [:using][:replace_interests] || false @send_welcome = [:using][:send_welcome] || false @delete_member = [:using][:delete_member] || true @send_goodbye = [:using][:send_goodbye] || false @send_notify = [:using][:send_notify] || false end |
.subscribe(record, list_name, options) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 45 def self.subscribe(record,list_name,) (record, ) client = connect(@api_key) list_id = client.find_list_by_name(list_name)['id'] client.list_subscribe(list_id, @email, @fields, @content_type, @double_optin, @update_existing, @replace_interests, @send_welcome) end |
.unsubscribe(record, list_name, options) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/mailchimp_subscriber/extensions.rb', line 52 def self.unsubscribe(record,list_name,) (record, ) client = connect(@api_key) list_id = client.find_list_by_name(list_name)["id"] client.list_unsubscribe(list_id, @email, @delete_member, @send_goodbye, @send_notify) end |