Class: GustoEmbedded::Introspection

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/gusto_embedded/introspection.rb

Instance Method Summary collapse

Constructor Details

#initialize(sdk_config) ⇒ Introspection

Returns a new instance of Introspection.



17
18
19
# File 'lib/gusto_embedded/introspection.rb', line 17

def initialize(sdk_config)
  @sdk_configuration = sdk_config
end

Instance Method Details

#get_info(x_gusto_api_version = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gusto_embedded/introspection.rb', line 23

def get_info(x_gusto_api_version = nil)
  # get_info - Get info about the current access token
  # Returns scope and resource information associated with the current access token.
  request = ::GustoEmbedded::Operations::GetV1TokenInfoRequest.new(
    
    x_gusto_api_version: x_gusto_api_version
  )
  url, params = @sdk_configuration.get_server_details
  base_url = Utils.template_url(url, params)
  url = "#{base_url}/v1/token_info"
  headers = Utils.get_headers(request)
  headers['Accept'] = 'application/json'
  headers['user-agent'] = @sdk_configuration.user_agent

  r = @sdk_configuration.client.get(url) do |req|
    req.headers = headers
    security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
    Utils.configure_request_security(req, security) if !security.nil?
  end

  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')

  res = ::GustoEmbedded::Operations::GetV1TokenInfoResponse.new(
    status_code: r.status, content_type: content_type, raw_response: r
  )
  if r.status == 200
    if Utils.match_content_type(content_type, 'application/json')
      out = Crystalline.unmarshal_json(JSON.parse(r.env.response_body), ::GustoEmbedded::Operations::GetV1TokenInfoResponseBody)
      res.object = out
    end
  end

  res
end

#refresh_token(request_body, x_gusto_api_version = nil) ⇒ Object

Raises:

  • (StandardError)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/gusto_embedded/introspection.rb', line 60

def refresh_token(request_body, x_gusto_api_version = nil)
  # refresh_token - Refresh access token
  # Exchange a refresh token for a new access token.
  # 
  # The previous `refresh_token` will be revoked on the first usage of the new `access_token`.
  # 
  # The `expires_in` value is provided in seconds from when the `access_token` was generated.
  request = ::GustoEmbedded::Operations::RefreshAccessTokenRequest.new(
    
    request_body: request_body,
    x_gusto_api_version: x_gusto_api_version
  )
  url, params = @sdk_configuration.get_server_details
  base_url = Utils.template_url(url, params)
  url = "#{base_url}/oauth/token"
  headers = Utils.get_headers(request)
  req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :json)
  headers['content-type'] = req_content_type
  raise StandardError, 'request body is required' if data.nil? && form.nil?
  headers['Accept'] = 'application/json'
  headers['user-agent'] = @sdk_configuration.user_agent

  r = @sdk_configuration.client.post(url) do |req|
    req.headers = headers
    security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
    Utils.configure_request_security(req, security) if !security.nil?
    if form
      req.body = Utils.encode_form(form)
    elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded')
      req.body = URI.encode_www_form(data)
    else
      req.body = data
    end
  end

  content_type = r.headers.fetch('Content-Type', 'application/octet-stream')

  res = ::GustoEmbedded::Operations::RefreshAccessTokenResponse.new(
    status_code: r.status, content_type: content_type, raw_response: r
  )
  if r.status == 200
    if Utils.match_content_type(content_type, 'application/json')
      out = Crystalline.unmarshal_json(JSON.parse(r.env.response_body), ::GustoEmbedded::Shared::Authentication)
      res.authentication = out
    end
  end

  res
end