Class: FailMail::Member
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(email, name, client = FailMail.client) ⇒ Member
constructor
A new instance of Member.
- #subscribe!(list_name) ⇒ Object
- #subscriptions ⇒ Object
- #unsubscribe!(list_name) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(email, name, client = FailMail.client) ⇒ Member
Returns a new instance of Member.
5 6 7 8 9 |
# File 'lib/fail_mail/member.rb', line 5 def initialize email, name, client=FailMail.client super client @email = email @name = name end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
3 4 5 |
# File 'lib/fail_mail/member.rb', line 3 def email @email end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/fail_mail/member.rb', line 3 def name @name end |
Instance Method Details
#subscribe!(list_name) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/fail_mail/member.rb', line 11 def subscribe! list_name create_member list_name rescue Savon::SOAPFault => exception member_id = extract_member_id_from_exception exception., list_name subscribe_member member_id, list_name if member_id end |
#subscriptions ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fail_mail/member.rb', line 23 def subscriptions @subscriptions ||= begin response = call :select_members_ex, message: { FieldsToFetch: { string: %w[MemberID ListName MemberType] }, FilterCriteriaArray: { string: ["EmailAddress = #{email}", "MemberType = normal"] } } result = response.body[:select_members_ex_response] || {} subscriptions = result.fetch(:return, {}).fetch(:item, []) subscriptions.shift subscriptions.map do |list| member_id, list_name, _ = list[:item] FailMail::Subscription.new list_name, member_id, self end end end |
#unsubscribe!(list_name) ⇒ Object
18 19 20 21 |
# File 'lib/fail_mail/member.rb', line 18 def unsubscribe! list_name subscription = subscriptions.find { |sub| sub.list_name == list_name } subscription.unsubscribe! if subscription end |