Sha256: 06c9e23c1b618d7d62daa838bb81bba284768c59bd1763114f3dcc2e3d285d44

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require 'digest'

module Smartsheet
  # Token Endpoints
  #
  # {#get} and {#refresh} do not require an existing token to call
  # @see https://smartsheet-platform.github.io/api-docs/?ruby#token API Token Docs
  class Token
    attr_reader :client
    private :client

    def initialize(client)
      @client = client
    end

    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

    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smartsheet-1.0.0 lib/smartsheet/endpoints/token/token.rb