Class: Smartsheet::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/smartsheet/endpoints/token/token.rb

Overview

Token Endpoints

#get and #refresh do not require an existing token to call

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Token

Returns a new instance of Token.



12
13
14
# File 'lib/smartsheet/endpoints/token/token.rb', line 12

def initialize(client)
  @client = client
end

Instance Method Details

#build_authorization_url(client_id:, scopes:, state: nil) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/smartsheet/endpoints/token/token.rb', line 16

def build_authorization_url(client_id:, scopes:, state: nil)
  scopes_string = scopes.join('%20')
  url = "https://app.smartsheet.com/b/authorize?response_type=code&client_id=#{client_id}&scope=#{scopes_string}"
  if state.present?
    return "#{url}&state=#{state}"
  end
  return url
end

#get(client_id:, hash:, code:, params: {}, header_overrides: {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/smartsheet/endpoints/token/token.rb', line 25

def get(client_id:, hash:, code:, params: {}, header_overrides: {})
  endpoint_spec = Smartsheet::API::EndpointSpec.new(
      :post,
      ['token'],
      no_auth: true
  )
  request_spec = Smartsheet::API::RequestSpec.new(
      header_overrides: header_overrides,
      params: params.merge({
                               client_id: client_id,
                               code: code,
                               hash: hash,
                               grant_type: 'authorization_code'
                           })
  )
  client.make_request(endpoint_spec, request_spec)
end

#refresh(client_id:, hash:, refresh_token:, params: {}, header_overrides: {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/smartsheet/endpoints/token/token.rb', line 43

def refresh(client_id:, hash:, refresh_token:, params: {}, header_overrides: {})
  endpoint_spec = Smartsheet::API::EndpointSpec.new(
      :post,
      ['token'],
      no_auth: true
  )
  request_spec = Smartsheet::API::RequestSpec.new(
      header_overrides: header_overrides,
      params: params.merge({
                               client_id: client_id,
                               refresh_token: refresh_token,
                               hash: hash,
                               grant_type: 'refresh_token'
                           })
  )
  client.make_request(endpoint_spec, request_spec)
end

#revoke(params: {}, header_overrides: {}) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/smartsheet/endpoints/token/token.rb', line 61

def revoke(params: {}, header_overrides: {})
  endpoint_spec = Smartsheet::API::EndpointSpec.new(:delete, ['token'])
  request_spec = Smartsheet::API::RequestSpec.new(
      header_overrides: header_overrides,
      params: params
  )
  client.make_request(endpoint_spec, request_spec)
end