Class: Gusto::AsyncTokenClient
- Inherits:
-
Object
- Object
- Gusto::AsyncTokenClient
- Defined in:
- lib/fern_gusto/token/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#get_info(request_options: nil) ⇒ Object
api.token.get_info.
-
#get_system_access_token(client_id:, client_secret:, request_options: nil) ⇒ Object
api.token.get_system_access_token(client_id: “abc123”, client_secret: “xyz789”).
- #initialize(request_client:) ⇒ Gusto::AsyncTokenClient constructor
-
#refresh(client_id:, client_secret:, redirect_uri: nil, refresh_token:, grant_type:, request_options: nil) ⇒ Object
).
Constructor Details
#initialize(request_client:) ⇒ Gusto::AsyncTokenClient
145 146 147 |
# File 'lib/fern_gusto/token/client.rb', line 145 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Gusto::AsyncRequestClient (readonly)
140 141 142 |
# File 'lib/fern_gusto/token/client.rb', line 140 def request_client @request_client end |
Instance Method Details
#get_info(request_options: nil) ⇒ Object
api.token.get_info
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/fern_gusto/token/client.rb', line 159 def get_info(request_options: nil) Async do response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end unless &.gusto_api_version.nil? req.headers["X-Gusto-API-Version"] = .gusto_api_version 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 unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/v1/token_info" end Gusto::Token::TokenGetInfoResponse.from_json(json_object: response.body) end end |
#get_system_access_token(client_id:, client_secret:, request_options: nil) ⇒ Object
api.token.get_system_access_token(client_id: “abc123”, client_secret: “xyz789”)
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/fern_gusto/token/client.rb', line 247 def get_system_access_token(client_id:, client_secret:, 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 unless &.gusto_api_version.nil? req.headers["X-Gusto-API-Version"] = .gusto_api_version 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": "system_access", client_id: client_id, client_secret: client_secret }.compact req.url "#{@request_client.get_url(request_options: )}/oauth/token" end Gusto::Token::TokenGetSystemAccessTokenResponse.from_json(json_object: response.body) end end |
#refresh(client_id:, client_secret:, redirect_uri: nil, refresh_token:, grant_type:, request_options: nil) ⇒ Object
)
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/fern_gusto/token/client.rb', line 208 def refresh(client_id:, client_secret:, redirect_uri: nil, refresh_token:, grant_type:, 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 unless &.gusto_api_version.nil? req.headers["X-Gusto-API-Version"] = .gusto_api_version 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 || {}), client_id: client_id, client_secret: client_secret, redirect_uri: redirect_uri, refresh_token: refresh_token, grant_type: grant_type }.compact req.url "#{@request_client.get_url(request_options: )}/oauth/token" end Gusto::Authentication.from_json(json_object: response.body) end end |