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
-
#delete_email_subscription(name:, govuk_account_session:) ⇒ Object
Unsubscribe and delete an account-linked email subscription.
-
#delete_saved_page(page_path:, govuk_account_session:) ⇒ GdsApi::Response
Delete a single saved page entry from a users account.
-
#delete_user_by_subject_identifier(subject_identifier:) ⇒ Object
Delete a users account.
-
#get_attributes(attributes:, govuk_account_session:) ⇒ Hash
Look up the values of a user’s attributes.
-
#get_email_subscription(name:, govuk_account_session:) ⇒ Hash
Get the details of an account-linked email subscription.
-
#get_end_session_url(govuk_account_session: nil) ⇒ Hash
Get an OIDC end-session URL to redirect the user to.
-
#get_saved_page(page_path:, govuk_account_session:) ⇒ Hash
Return a single page by unique URL.
-
#get_saved_pages(govuk_account_session:) ⇒ Hash
Look up all pages saved by a user in their Account.
-
#get_sign_in_url(redirect_path: nil, mfa: false) ⇒ Hash
Get an OAuth sign-in URL to redirect the user to.
-
#get_user(govuk_account_session:) ⇒ Hash
Get all the information about a user needed to render the account home page.
-
#put_email_subscription(name:, topic_slug:, govuk_account_session:) ⇒ Hash
Create or update an account-linked email subscription.
-
#save_page(page_path:, govuk_account_session:) ⇒ Hash
Upsert a single saved page entry in a users account.
-
#set_attributes(attributes:, govuk_account_session:) ⇒ Hash
Create or update attributes for a user.
-
#update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil) ⇒ Hash
Update the user record with privileged information from the auth service.
-
#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
#delete_email_subscription(name:, govuk_account_session:) ⇒ Object
Unsubscribe and delete an account-linked email subscription.
126 127 128 |
# File 'lib/gds_api/account_api.rb', line 126 def delete_email_subscription(name:, govuk_account_session:) delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session)) end |
#delete_saved_page(page_path:, govuk_account_session:) ⇒ GdsApi::Response
Delete a single saved page entry from a users account
166 167 168 |
# File 'lib/gds_api/account_api.rb', line 166 def delete_saved_page(page_path:, govuk_account_session:) delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session)) end |
#delete_user_by_subject_identifier(subject_identifier:) ⇒ Object
Delete a users account
58 59 60 |
# File 'lib/gds_api/account_api.rb', line 58 def delete_user_by_subject_identifier(subject_identifier:) delete_json("#{endpoint}/api/oidc-users/#{subject_identifier}") end |
#get_attributes(attributes:, govuk_account_session:) ⇒ Hash
Look up the values of a user’s attributes
86 87 88 89 |
# File 'lib/gds_api/account_api.rb', line 86 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_email_subscription(name:, govuk_account_session:) ⇒ Hash
Get the details of an account-linked email subscription.
107 108 109 |
# File 'lib/gds_api/account_api.rb', line 107 def get_email_subscription(name:, govuk_account_session:) get_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", auth_headers(govuk_account_session)) end |
#get_end_session_url(govuk_account_session: nil) ⇒ Hash
Get an OIDC end-session URL to redirect the user to
42 43 44 |
# File 'lib/gds_api/account_api.rb', line 42 def get_end_session_url(govuk_account_session: nil) get_json("#{endpoint}/api/oauth2/end-session", auth_headers(govuk_account_session)) end |
#get_saved_page(page_path:, govuk_account_session:) ⇒ Hash
Return a single page by unique URL
145 146 147 |
# File 'lib/gds_api/account_api.rb', line 145 def get_saved_page(page_path:, govuk_account_session:) get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session)) end |
#get_saved_pages(govuk_account_session:) ⇒ Hash
Look up all pages saved by a user in their Account
135 136 137 |
# File 'lib/gds_api/account_api.rb', line 135 def get_saved_pages(govuk_account_session:) get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session)) end |
#get_sign_in_url(redirect_path: nil, mfa: false) ⇒ Hash
Get an OAuth sign-in URL to redirect the user to
17 18 19 20 21 22 23 24 25 |
# File 'lib/gds_api/account_api.rb', line 17 def get_sign_in_url(redirect_path: nil, mfa: false) querystring = nested_query_string( { redirect_path: redirect_path, mfa: mfa, }.compact, ) get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}") end |
#get_user(govuk_account_session:) ⇒ Hash
Get all the information about a user needed to render the account home page
51 52 53 |
# File 'lib/gds_api/account_api.rb', line 51 def get_user(govuk_account_session:) get_json("#{endpoint}/api/user", auth_headers(govuk_account_session)) end |
#put_email_subscription(name:, topic_slug:, govuk_account_session:) ⇒ Hash
Create or update an account-linked email subscription.
118 119 120 |
# File 'lib/gds_api/account_api.rb', line 118 def put_email_subscription(name:, topic_slug:, govuk_account_session:) put_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", { topic_slug: topic_slug }, auth_headers(govuk_account_session)) end |
#save_page(page_path:, govuk_account_session:) ⇒ Hash
Upsert a single saved page entry in a users account
155 156 157 |
# File 'lib/gds_api/account_api.rb', line 155 def save_page(page_path:, govuk_account_session:) put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session)) end |
#set_attributes(attributes:, govuk_account_session:) ⇒ Hash
Create or update attributes for a user
97 98 99 |
# File 'lib/gds_api/account_api.rb', line 97 def set_attributes(attributes:, govuk_account_session:) patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session)) end |
#update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil) ⇒ Hash
Update the user record with privileged information from the auth service. Only the auth service will call this.
70 71 72 73 74 75 76 77 78 |
# File 'lib/gds_api/account_api.rb', line 70 def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil) params = { email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email, }.compact patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params) end |
#validate_auth_response(code:, state:) ⇒ Hash
Validate an OAuth authentication response
33 34 35 |
# File 'lib/gds_api/account_api.rb', line 33 def validate_auth_response(code:, state:) post_json("#{endpoint}/api/oauth2/callback", code: code, state: state) end |