Class: CampactUserService::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/campact_user_service/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/campact_user_service/account.rb', line 3

def client
  @client
end

#user_idObject (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

#addressObject



33
34
35
# File 'lib/campact_user_service/account.rb', line 33

def address
  ['postaladdress']
end

#allow_prefill?Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/campact_user_service/account.rb', line 20

def allow_prefill?
  prefill = .dig('preferences', 'prefill_forms')
  prefill.to_s == 'allowed'
end

#emailObject



29
30
31
# File 'lib/campact_user_service/account.rb', line 29

def email
  .dig('emailaddress', 'emailaddress')
end

#exists?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/campact_user_service/account.rb', line 11

def exists?
   && !['external_id'].nil?
end

#nameObject



25
26
27
# File 'lib/campact_user_service/account.rb', line 25

def name
  ['name']
end

#preferencesObject



37
38
39
# File 'lib/campact_user_service/account.rb', line 37

def preferences
  ['preferences']
end

#subscribed_to_newsletter?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/campact_user_service/account.rb', line 15

def subscribed_to_newsletter?
  subscriptions = .dig('emailaddress', 'subscriptions') || []
  subscriptions.any? {|s| s['type'] == 'newsletter' }
end