Class: MonkeyParty::Subscriber
- Inherits:
-
Object
- Object
- MonkeyParty::Subscriber
- Defined in:
- lib/monkey_party/subscriber.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#error ⇒ Object
Returns the value of attribute error.
-
#merge_fields ⇒ Object
Returns the value of attribute merge_fields.
Instance Method Summary collapse
-
#initialize(email, merge_fields = {}) ⇒ Subscriber
constructor
A new instance of Subscriber.
- #to_h ⇒ Object
- #to_mailchimp_hash ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(email, merge_fields = {}) ⇒ Subscriber
Returns a new instance of Subscriber.
5 6 7 8 9 |
# File 'lib/monkey_party/subscriber.rb', line 5 def initialize(email, merge_fields = {}) self.email = email self.merge_fields = merge_fields self.error = nil end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/monkey_party/subscriber.rb', line 3 def email @email end |
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/monkey_party/subscriber.rb', line 3 def error @error end |
#merge_fields ⇒ Object
Returns the value of attribute merge_fields.
3 4 5 |
# File 'lib/monkey_party/subscriber.rb', line 3 def merge_fields @merge_fields end |
Instance Method Details
#to_h ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/monkey_party/subscriber.rb', line 11 def to_h { :email => self.email, }.merge(self.merge_fields).tap do |h| h[:error] = self.error.to_h if self.error end end |
#to_mailchimp_hash ⇒ Object
19 20 21 22 23 24 |
# File 'lib/monkey_party/subscriber.rb', line 19 def to_mailchimp_hash self.to_h.keys.inject({}) do |chimp_hash, key| chimp_hash[key.to_s.upcase[0..9]] = self.to_h[key] unless key == :error chimp_hash end end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/monkey_party/subscriber.rb', line 26 def valid? self.error.nil? end |