Class: PlatformSdk::Identity::Client

Inherits:
Object
  • Object
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

Methods included from ErrorHandleable

#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, )
  put_payload("/api/TermsAndConditions/#{terms_and_conditions_id}/Accounts/#{}", {})
end

#deactivate_account(account_id) ⇒ Object



103
104
105
106
107
108
# File 'lib/platform_sdk/identity/clients.rb', line 103

def ()
  with_rescue do
    response = @conn.patch("/api/Accounts/#{}", { 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 (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_payload("/api/Accounts/#{}")
end

#get_account_with_profile(account_id) ⇒ Object



60
61
62
# File 'lib/platform_sdk/identity/clients.rb', line 60

def ()
  get_payload("/api/Accounts/#{}/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(, 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/#{}/PasswordReset", {}, query_params)
end

#password_status(account_id) ⇒ Object



34
35
36
# File 'lib/platform_sdk/identity/clients.rb', line 34

def password_status()
  get_payload("/api/Accounts/#{}/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()
  post_payload('/api/Accounts/SendReminderEmail', JSON.dump())
end

#terms_and_conditionsObject



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 (, )
  patch_payload("/api/Accounts/#{}", )
end

#update_profile(account_id, profile_params) ⇒ Object



68
69
70
# File 'lib/platform_sdk/identity/clients.rb', line 68

def update_profile(, profile_params)
  patch_payload("/api/accounts/#{}/profile", profile_params)
end