Class: Gusto::TokenClient
- Inherits:
-
Object
- Object
- Gusto::TokenClient
- 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::TokenClient constructor
-
#refresh(client_id:, client_secret:, redirect_uri: nil, refresh_token:, grant_type:, request_options: nil) ⇒ Object
).
Constructor Details
#initialize(request_client:) ⇒ Gusto::TokenClient
19 20 21 |
# File 'lib/fern_gusto/token/client.rb', line 19 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Gusto::RequestClient (readonly)
14 15 16 |
# File 'lib/fern_gusto/token/client.rb', line 14 def request_client @request_client end |
Instance Method Details
#get_info(request_options: nil) ⇒ Object
api.token.get_info
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fern_gusto/token/client.rb', line 33 def get_info(request_options: nil) 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 |
#get_system_access_token(client_id:, client_secret:, request_options: nil) ⇒ Object
api.token.get_system_access_token(client_id: “abc123”, client_secret: “xyz789”)
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/fern_gusto/token/client.rb', line 117 def get_system_access_token(client_id:, client_secret:, request_options: nil) 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 |
#refresh(client_id:, client_secret:, redirect_uri: nil, refresh_token:, grant_type:, request_options: nil) ⇒ Object
)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fern_gusto/token/client.rb', line 80 def refresh(client_id:, client_secret:, redirect_uri: nil, refresh_token:, grant_type:, request_options: nil) 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 |