Class: Courier::Users::TokensClient
- Inherits:
-
Object
- Object
- Courier::Users::TokensClient
- 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::TokensClient 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::TokensClient
17 18 19 20 |
# File 'lib/trycourier/users/tokens/client.rb', line 17 def initialize(request_client:) # @type [RequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
13 14 15 |
# File 'lib/trycourier/users/tokens/client.rb', line 13 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.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/trycourier/users/tokens/client.rb', line 61 def add(user_id:, token:, request:, request_options: nil) @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 |
#add_multiple(user_id:, request_options: nil) ⇒ Void
Adds multiple tokens to a user and overwrites matching existing tokens.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/trycourier/users/tokens/client.rb', line 27 def add_multiple(user_id:, request_options: nil) @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 |
#get(user_id:, token:, request_options: nil) ⇒ Users::Tokens::GetUserTokenResponse
Get single token available for a ‘:token`
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/trycourier/users/tokens/client.rb', line 99 def get(user_id:, token:, request_options: nil) 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 |
#list(user_id:, request_options: nil) ⇒ Users::Tokens::GET_ALL_TOKENS_RESPONSE
Gets all tokens available for a :user_id
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/trycourier/users/tokens/client.rb', line 116 def list(user_id:, request_options: nil) 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 return if response.body.nil? response.body.map do |v| v = v.to_json Users::Tokens::UserToken.from_json(json_object: v) end end |
#update(user_id:, token:, request:, request_options: nil) ⇒ Void
Apply a JSON Patch (RFC 6902) to the specified token.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/trycourier/users/tokens/client.rb', line 81 def update(user_id:, token:, request:, request_options: nil) @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 |