Class: Samsara::Auth::AsyncTokensClient
- Inherits:
-
Object
- Object
- Samsara::Auth::AsyncTokensClient
- Defined in:
- lib/samsara_api/auth/tokens/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#create(code: nil, request_options: nil) ⇒ Object
api.auth.tokens.create.
- #initialize(request_client:) ⇒ Samsara::Auth::AsyncTokensClient constructor
-
#revoke(token:, request_options: nil) ⇒ Object
api.auth.tokens.revoke(token: "token").
Constructor Details
#initialize(request_client:) ⇒ Samsara::Auth::AsyncTokensClient
86 87 88 |
# File 'lib/samsara_api/auth/tokens/client.rb', line 86 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Samsara::AsyncRequestClient (readonly)
81 82 83 |
# File 'lib/samsara_api/auth/tokens/client.rb', line 81 def request_client @request_client end |
Instance Method Details
#create(code: nil, request_options: nil) ⇒ Object
api.auth.tokens.create
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/samsara_api/auth/tokens/client.rb', line 101 def create(code: nil, request_options: nil) Async do response = @request_client.conn.post do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end 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 || {}), "grant_type": "authorization_code", code: code }.compact req.url "#{@request_client.get_url(request_options: request_options)}/oauth2/token" end Samsara::Auth::Tokens::Types::CreateTokensResponse.from_json(json_object: response.body) end end |
#revoke(token:, request_options: nil) ⇒ Object
api.auth.tokens.revoke(token: "token")
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/samsara_api/auth/tokens/client.rb', line 132 def revoke(token:, request_options: nil) Async do response = @request_client.conn.post do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end 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 || {}), token: token }.compact req.url "#{@request_client.get_url(request_options: request_options)}/oauth2/revoke" end Samsara::Auth::Tokens::Types::CreateTokensResponse.from_json(json_object: response.body) end end |