Class: NewDemoApiClient::UserClient
- Inherits:
-
Object
- Object
- NewDemoApiClient::UserClient
- Defined in:
- lib/test_sdk/user/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#create_or_replace_api_key(request_options: nil) ⇒ NewDemoApiClient::CreateAPIKeyResponse
Create or replace an API key for the current user.
-
#delete_api_key(request_options: nil) ⇒ Hash{String => Object}
Delete an API key for the current user.
-
#get_token(api_key:, request_options: nil) ⇒ NewDemoApiClient::AuthenticateAPIKeyResponse
Authenticate an API key and return an access token Returns a client JWT for the provided API key, where the JWT contains claims for permissions and access and can be refreshed as part of an OAuth flow.
- #initialize(request_client:) ⇒ NewDemoApiClient::UserClient constructor
-
#me(request_options: nil) ⇒ NewDemoApiClient::UserWithPermissionsResponse
Get the current user.
-
#upload_user_avatar(image:, request_options: nil) ⇒ NewDemoApiClient::UserWithGroupsResponse
Upload an avatar for a user.
Constructor Details
#initialize(request_client:) ⇒ NewDemoApiClient::UserClient
19 20 21 |
# File 'lib/test_sdk/user/client.rb', line 19 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ NewDemoApiClient::RequestClient (readonly)
15 16 17 |
# File 'lib/test_sdk/user/client.rb', line 15 def request_client @request_client end |
Instance Method Details
#create_or_replace_api_key(request_options: nil) ⇒ NewDemoApiClient::CreateAPIKeyResponse
Create or replace an API key for the current user.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/test_sdk/user/client.rb', line 131 def create_or_replace_api_key(request_options: nil) response = @request_client.conn.put do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/api/v1/user/api-key" end NewDemoApiClient::CreateAPIKeyResponse.from_json(json_object: response.body) end |
#delete_api_key(request_options: nil) ⇒ Hash{String => Object}
Delete an API key for the current user.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/test_sdk/user/client.rb', line 162 def delete_api_key(request_options: nil) response = @request_client.conn.delete do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/api/v1/user/api-key" end JSON.parse(response.body) end |
#get_token(api_key:, request_options: nil) ⇒ NewDemoApiClient::AuthenticateAPIKeyResponse
Authenticate an API key and return an access token
Returns a client JWT for the provided API key, where the JWT contains claims for
permissions and access and can be
refreshed as part of an OAuth flow.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/test_sdk/user/client.rb', line 38 def get_token(api_key:, request_options: nil) response = @request_client.conn.post do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), api_key: api_key }.compact req.url "#{@request_client.get_url(request_options: )}/api/v1/auth/get-token" end NewDemoApiClient::AuthenticateAPIKeyResponse.from_json(json_object: response.body) end |
#me(request_options: nil) ⇒ NewDemoApiClient::UserWithPermissionsResponse
Get the current user.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/test_sdk/user/client.rb', line 67 def me(request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/api/v1/user/me" end NewDemoApiClient::UserWithPermissionsResponse.from_json(json_object: response.body) end |
#upload_user_avatar(image:, request_options: nil) ⇒ NewDemoApiClient::UserWithGroupsResponse
Upload an avatar for a user.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/test_sdk/user/client.rb', line 99 def upload_user_avatar(image:, request_options: nil) response = @request_client.conn.post do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), image: NewDemoApiClient::FileUtilities.as_faraday_multipart(file_like: image) }.compact req.url "#{@request_client.get_url(request_options: )}/api/v1/user/me/avatar" end NewDemoApiClient::UserWithGroupsResponse.from_json(json_object: response.body) end |