lib/smartsheet/endpoints/token/token.rb in smartsheet-1.0.0 vs lib/smartsheet/endpoints/token/token.rb in smartsheet-1.1.0

- old
+ new

@@ -1,61 +1,66 @@ -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 +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 build_authorization_url(client_id:, scopes:) + scopes_string = scopes.join('%20') + "https://app.smartsheet.com/b/authorize?response_type=code&client_id=#{client_id}&scope=#{scopes_string}" + 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 \ No newline at end of file