Class: NewDemoApiClient::UserClient

Inherits:
Object
  • Object
show all
Defined in:
lib/test_sdk/user/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ NewDemoApiClient::UserClient

Parameters:



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_clientNewDemoApiClient::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.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.create_or_replace_api_key

Parameters:

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: 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.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.delete_api_key

Parameters:

Returns:

  • (Hash{String => Object})


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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: 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.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.get_token(api_key: "api_key")

Parameters:

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request_options&.additional_body_parameters || {}), api_key: api_key }.compact
    req.url "#{@request_client.get_url(request_options: 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.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.me

Parameters:

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: 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.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.user.upload_user_avatar(image: my_file.txt)

Parameters:

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      image: NewDemoApiClient::FileUtilities.as_faraday_multipart(file_like: image)
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/user/me/avatar"
  end
  NewDemoApiClient::UserWithGroupsResponse.from_json(json_object: response.body)
end