Class: NewDemoApiClient::AsyncUserClient
- Inherits:
-
Object
- Object
- NewDemoApiClient::AsyncUserClient
- 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::AsyncUserClient 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::AsyncUserClient
189 190 191 |
# File 'lib/test_sdk/user/client.rb', line 189 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ NewDemoApiClient::AsyncRequestClient (readonly)
185 186 187 |
# File 'lib/test_sdk/user/client.rb', line 185 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.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/test_sdk/user/client.rb', line 307 def create_or_replace_api_key(request_options: nil) Async do 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 end |
#delete_api_key(request_options: nil) ⇒ Hash{String => Object}
Delete an API key for the current user.
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/test_sdk/user/client.rb', line 340 def delete_api_key(request_options: nil) Async do 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 parsed_json = JSON.parse(response.body) parsed_json end 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.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/test_sdk/user/client.rb', line 208 def get_token(api_key:, request_options: nil) Async do 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 end |
#me(request_options: nil) ⇒ NewDemoApiClient::UserWithPermissionsResponse
Get the current user.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/test_sdk/user/client.rb', line 239 def me(request_options: nil) Async do 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 end |
#upload_user_avatar(image:, request_options: nil) ⇒ NewDemoApiClient::UserWithGroupsResponse
Upload an avatar for a user.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/test_sdk/user/client.rb', line 273 def upload_user_avatar(image:, request_options: nil) Async do 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 end |