Class: PlatformSdk::Identity::Client
- Inherits:
-
Object
- Object
- PlatformSdk::Identity::Client
show all
- Includes:
- ErrorHandleable
- Defined in:
- lib/platform_sdk/identity/clients.rb
Overview
Client for making calls to the Identity Server API
Instance Method Summary
collapse
-
#accept_terms_and_conditions(terms_and_conditions_id, account_id) ⇒ Object
-
#get_payload(path) ⇒ Object
-
#initialize(identity_base_url, client_id, client_secret, auth_client = nil) ⇒ Client
constructor
A new instance of Client.
-
#password_reset(account_id, return_url = nil, send_email: true, include_username: true) ⇒ Object
-
#password_status(account_id) ⇒ Object
-
#post_payload(path, body, query_params = {}) ⇒ Object
-
#provision_identity(user_params) ⇒ Object
-
#put_payload(path, body) ⇒ Object
-
#send_reminder_email(account_id) ⇒ Object
-
#terms_and_conditions ⇒ Object
#raise_error_with_payload, #with_rescue
Constructor Details
#initialize(identity_base_url, client_id, client_secret, auth_client = nil) ⇒ Client
Returns a new instance of Client.
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/platform_sdk/identity/clients.rb', line 9
def initialize(identity_base_url, client_id, client_secret, auth_client = nil)
@auth = auth_client.nil? ? AuthClient.new(identity_base_url, client_id, client_secret) : auth_client
@conn = Faraday.new(identity_base_url) do |conn|
conn.request :authorization, 'Bearer', -> { @auth.auth_token }
conn.request :retry
conn.request :json
conn.response :raise_error
conn.response :json
conn.adapter :net_http
end
end
|
Instance Method Details
#accept_terms_and_conditions(terms_and_conditions_id, account_id) ⇒ Object
30
31
32
|
# File 'lib/platform_sdk/identity/clients.rb', line 30
def accept_terms_and_conditions(terms_and_conditions_id, account_id)
put_payload("/api/TermsAndConditions/#{terms_and_conditions_id}/Accounts/#{account_id}", {})
end
|
#get_payload(path) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/platform_sdk/identity/clients.rb', line 52
def get_payload(path)
with_rescue do
response = @conn.get(path)
response.body
end
end
|
#password_reset(account_id, return_url = nil, send_email: true, include_username: true) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/platform_sdk/identity/clients.rb', line 38
def password_reset(account_id, return_url = nil, send_email: true, include_username: true)
query_params = {
sendEmail: send_email,
includeUsername: include_username
}
query_params[:returnUrl] = return_url if return_url
post_payload("/api/Accounts/#{account_id}/PasswordReset", {}, query_params)
end
|
#password_status(account_id) ⇒ Object
34
35
36
|
# File 'lib/platform_sdk/identity/clients.rb', line 34
def password_status(account_id)
get_payload("/api/Accounts/#{account_id}/PasswordStatus")
end
|
#post_payload(path, body, query_params = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/platform_sdk/identity/clients.rb', line 59
def post_payload(path, body, query_params = {})
with_rescue do
response = @conn.post(path) do |req|
req.params = query_params unless query_params.empty?
req.body = body
end
response.body
end
end
|
#provision_identity(user_params) ⇒ Object
22
23
24
|
# File 'lib/platform_sdk/identity/clients.rb', line 22
def provision_identity(user_params)
post_payload('/api/accounts/WithProfile', user_params)
end
|
#put_payload(path, body) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/platform_sdk/identity/clients.rb', line 69
def put_payload(path, body)
with_rescue do
response = @conn.put(path, body)
response.body
end
end
|
#send_reminder_email(account_id) ⇒ Object
48
49
50
|
# File 'lib/platform_sdk/identity/clients.rb', line 48
def send_reminder_email(account_id)
post_payload('/api/Accounts/SendReminderEmail', JSON.dump(account_id))
end
|
#terms_and_conditions ⇒ Object
26
27
28
|
# File 'lib/platform_sdk/identity/clients.rb', line 26
def terms_and_conditions
get_payload('/api/TermsAndConditions')
end
|