Class: Courier::Users::AsyncTokensClient
- Inherits:
-
Object
- Object
- Courier::Users::AsyncTokensClient
- Defined in:
- lib/trycourier/users/tokens/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
-
#add(user_id:, token:, request:, request_options: nil) ⇒ Void
Adds a single token to a user and overwrites a matching existing token.
-
#add_multiple(user_id:, request_options: nil) ⇒ Void
Adds multiple tokens to a user and overwrites matching existing tokens.
-
#get(user_id:, token:, request_options: nil) ⇒ Users::Tokens::GetUserTokenResponse
Get single token available for a ‘:token`.
- #initialize(request_client:) ⇒ Users::AsyncTokensClient constructor
-
#list(user_id:, request_options: nil) ⇒ Users::Tokens::GET_ALL_TOKENS_RESPONSE
Gets all tokens available for a :user_id.
-
#update(user_id:, token:, request:, request_options: nil) ⇒ Void
Apply a JSON Patch (RFC 6902) to the specified token.
Constructor Details
#initialize(request_client:) ⇒ Users::AsyncTokensClient
139 140 141 142 |
# File 'lib/trycourier/users/tokens/client.rb', line 139 def initialize(request_client:) # @type [AsyncRequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
135 136 137 |
# File 'lib/trycourier/users/tokens/client.rb', line 135 def request_client @request_client end |
Instance Method Details
#add(user_id:, token:, request:, request_options: nil) ⇒ Void
Adds a single token to a user and overwrites a matching existing token.
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/trycourier/users/tokens/client.rb', line 185 def add(user_id:, token:, request:, request_options: nil) Async do @request_client.conn.put("/users/#{user_id}/tokens/#{token}") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact end end end |
#add_multiple(user_id:, request_options: nil) ⇒ Void
Adds multiple tokens to a user and overwrites matching existing tokens.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/trycourier/users/tokens/client.rb', line 149 def add_multiple(user_id:, request_options: nil) Async do @request_client.conn.put("/users/#{user_id}/tokens") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end end end |
#get(user_id:, token:, request_options: nil) ⇒ Users::Tokens::GetUserTokenResponse
Get single token available for a ‘:token`
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/trycourier/users/tokens/client.rb', line 227 def get(user_id:, token:, request_options: nil) Async do response = @request_client.conn.get("/users/#{user_id}/tokens/#{token}") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end Users::Tokens::GetUserTokenResponse.from_json(json_object: response.body) end end |
#list(user_id:, request_options: nil) ⇒ Users::Tokens::GET_ALL_TOKENS_RESPONSE
Gets all tokens available for a :user_id
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/trycourier/users/tokens/client.rb', line 246 def list(user_id:, request_options: nil) Async do response = @request_client.conn.get("/users/#{user_id}/tokens") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end response.body&.map do |v| v = v.to_json Users::Tokens::UserToken.from_json(json_object: v) end end end |
#update(user_id:, token:, request:, request_options: nil) ⇒ Void
Apply a JSON Patch (RFC 6902) to the specified token.
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/trycourier/users/tokens/client.rb', line 207 def update(user_id:, token:, request:, request_options: nil) Async do @request_client.conn.patch("/users/#{user_id}/tokens/#{token}") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact end end end |