Sha256: d50c65826a08b31153fc78cbe576b3ecd0abae55cbc4f2627082913043260a3b

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

require 'digest'

module Smartsheet
  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

2 entries across 2 versions & 1 rubygems

Version Path
smartsheet-1.0.0.beta.2 lib/smartsheet/endpoints/token/token.rb
smartsheet-1.0.0.beta.0 lib/smartsheet/endpoints/token/token.rb