Class: GdsApi::AccountApi
Overview
Adapter for the Account API
Constant Summary collapse
- AUTH_HEADER_NAME =
"GOVUK-Account-Session".freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#check_for_email_subscription(govuk_account_session:) ⇒ Hash
Check if a user has an email subscription for the Transition Checker.
-
#create_registration_state(attributes:) ⇒ Hash
Register some initial state, to pass to get_sign_in_url, which is used to initialise the account if the user signs up.
-
#get_attributes(attributes:, govuk_account_session:) ⇒ Hash
Look up the values of a user’s attributes.
-
#get_sign_in_url(redirect_path: nil, state_id: nil) ⇒ Hash
Get an OAuth sign-in URL to redirect the user to.
-
#set_attributes(attributes:, govuk_account_session:) ⇒ Hash
Create or update attributes for a user.
-
#set_email_subscription(govuk_account_session:, slug:) ⇒ Hash
Create or update a user’s email subscription for the Transition Checker.
-
#validate_auth_response(code:, state:) ⇒ Hash
Validate an OAuth authentication response.
Methods inherited from Base
#client, #create_client, #get_list, #initialize, #url_for_slug
Constructor Details
This class inherits a constructor from GdsApi::Base
Instance Method Details
#check_for_email_subscription(govuk_account_session:) ⇒ Hash
Check if a user has an email subscription for the Transition Checker
46 47 48 |
# File 'lib/gds_api/account_api.rb', line 46 def check_for_email_subscription(govuk_account_session:) get_json("#{endpoint}/api/transition-checker-email-subscription", auth_headers(govuk_account_session)) end |
#create_registration_state(attributes:) ⇒ Hash
Register some initial state, to pass to get_sign_in_url, which is used to initialise the account if the user signs up
37 38 39 |
# File 'lib/gds_api/account_api.rb', line 37 def create_registration_state(attributes:) post_json("#{endpoint}/api/oauth2/state", attributes: attributes) end |
#get_attributes(attributes:, govuk_account_session:) ⇒ Hash
Look up the values of a user’s attributes
66 67 68 69 |
# File 'lib/gds_api/account_api.rb', line 66 def get_attributes(attributes:, govuk_account_session:) querystring = nested_query_string({ attributes: attributes }.compact) get_json("#{endpoint}/api/attributes?#{querystring}", auth_headers(govuk_account_session)) end |
#get_sign_in_url(redirect_path: nil, state_id: nil) ⇒ Hash
Get an OAuth sign-in URL to redirect the user to
17 18 19 20 |
# File 'lib/gds_api/account_api.rb', line 17 def get_sign_in_url(redirect_path: nil, state_id: nil) querystring = nested_query_string({ redirect_path: redirect_path, state_id: state_id }.compact) get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}") end |
#set_attributes(attributes:, govuk_account_session:) ⇒ Hash
Create or update attributes for a user
77 78 79 |
# File 'lib/gds_api/account_api.rb', line 77 def set_attributes(attributes:, govuk_account_session:) patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session)) end |
#set_email_subscription(govuk_account_session:, slug:) ⇒ Hash
Create or update a user’s email subscription for the Transition Checker
56 57 58 |
# File 'lib/gds_api/account_api.rb', line 56 def set_email_subscription(govuk_account_session:, slug:) post_json("#{endpoint}/api/transition-checker-email-subscription", { slug: slug }, auth_headers(govuk_account_session)) end |
#validate_auth_response(code:, state:) ⇒ Hash
Validate an OAuth authentication response
28 29 30 |
# File 'lib/gds_api/account_api.rb', line 28 def validate_auth_response(code:, state:) post_json("#{endpoint}/api/oauth2/callback", code: code, state: state) end |