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
-
#deactivate_account(account_id) ⇒ Object
-
#find_account_by_username(username) ⇒ Object
-
#get_account_by_id(account_id) ⇒ Object
-
#get_account_with_profile(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
-
#patch_payload(path, body) ⇒ 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
-
#update_account(account_id, account_params) ⇒ Object
-
#update_profile(account_id, profile_params) ⇒ 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
|
#deactivate_account(account_id) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/platform_sdk/identity/clients.rb', line 103
def deactivate_account(account_id)
with_rescue do
response = @conn.patch("/api/Accounts/#{account_id}", { isActive: false })
response.body
end
end
|
#find_account_by_username(username) ⇒ Object
56
57
58
|
# File 'lib/platform_sdk/identity/clients.rb', line 56
def find_account_by_username(username)
get_payload("/api/Accounts/?username=#{username}")
end
|
#get_account_by_id(account_id) ⇒ Object
38
39
40
|
# File 'lib/platform_sdk/identity/clients.rb', line 38
def get_account_by_id(account_id)
get_payload("/api/Accounts/#{account_id}")
end
|
#get_account_with_profile(account_id) ⇒ Object
60
61
62
|
# File 'lib/platform_sdk/identity/clients.rb', line 60
def get_account_with_profile(account_id)
get_payload("/api/Accounts/#{account_id}/WithProfile")
end
|
#get_payload(path) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/platform_sdk/identity/clients.rb', line 72
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
42
43
44
45
46
47
48
49
50
|
# File 'lib/platform_sdk/identity/clients.rb', line 42
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
|
#patch_payload(path, body) ⇒ Object
96
97
98
99
100
101
|
# File 'lib/platform_sdk/identity/clients.rb', line 96
def patch_payload(path, body)
with_rescue do
response = @conn.patch(path, body)
response.body
end
end
|
#post_payload(path, body, query_params = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/platform_sdk/identity/clients.rb', line 79
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
89
90
91
92
93
94
|
# File 'lib/platform_sdk/identity/clients.rb', line 89
def put_payload(path, body)
with_rescue do
response = @conn.put(path, body)
response.body
end
end
|
#send_reminder_email(account_id) ⇒ Object
52
53
54
|
# File 'lib/platform_sdk/identity/clients.rb', line 52
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
|
#update_account(account_id, account_params) ⇒ Object
64
65
66
|
# File 'lib/platform_sdk/identity/clients.rb', line 64
def update_account(account_id, account_params)
patch_payload("/api/Accounts/#{account_id}", account_params)
end
|
#update_profile(account_id, profile_params) ⇒ Object
68
69
70
|
# File 'lib/platform_sdk/identity/clients.rb', line 68
def update_profile(account_id, profile_params)
patch_payload("/api/accounts/#{account_id}/profile", profile_params)
end
|