Class: CampactUserService::Account
- Inherits:
-
Object
- Object
- CampactUserService::Account
- Defined in:
- lib/campact_user_service/account.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #address ⇒ Object
- #allow_prefill? ⇒ Boolean
- #email ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(client, user_id) ⇒ Account
constructor
user_id can either be the user's external_account_id or their email address.
- #name ⇒ Object
- #preferences ⇒ Object
- #subscribed_to_newsletter? ⇒ Boolean
Constructor Details
#initialize(client, user_id) ⇒ Account
user_id can either be the user's external_account_id or their email address
6 7 8 9 |
# File 'lib/campact_user_service/account.rb', line 6 def initialize(client, user_id) @client = client @user_id = user_id end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/campact_user_service/account.rb', line 3 def client @client end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
3 4 5 |
# File 'lib/campact_user_service/account.rb', line 3 def user_id @user_id end |
Instance Method Details
#address ⇒ Object
33 34 35 |
# File 'lib/campact_user_service/account.rb', line 33 def address account['postaladdress'] end |
#allow_prefill? ⇒ Boolean
20 21 22 23 |
# File 'lib/campact_user_service/account.rb', line 20 def allow_prefill? prefill = account.dig('preferences', 'prefill_forms') prefill.to_s == 'allowed' end |
#email ⇒ Object
29 30 31 |
# File 'lib/campact_user_service/account.rb', line 29 def email account.dig('emailaddress', 'emailaddress') end |
#exists? ⇒ Boolean
11 12 13 |
# File 'lib/campact_user_service/account.rb', line 11 def exists? account && !account['external_id'].nil? end |
#name ⇒ Object
25 26 27 |
# File 'lib/campact_user_service/account.rb', line 25 def name account['name'] end |
#preferences ⇒ Object
37 38 39 |
# File 'lib/campact_user_service/account.rb', line 37 def preferences account['preferences'] end |
#subscribed_to_newsletter? ⇒ Boolean
15 16 17 18 |
# File 'lib/campact_user_service/account.rb', line 15 def subscriptions = account.dig('emailaddress', 'subscriptions') || [] subscriptions.any? {|s| s['type'] == 'newsletter' } end |