Sha256: 85a62b9786d7eb6e4a3c8c658d7a0974bbe1741db346f7f1c712be4c9495023d

Contents?: true

Size: 640 Bytes

Versions: 5

Compression:

Stored size: 640 Bytes

Contents

require "oauth2"

module Commercelayer
  class Client

    MAX_RETRIES = 1

    def initialize(options={})
      @client_id = options[:client_id]
      @client_secret = options[:client_secret]
      @scope = options[:scope]
      @site = options[:site]
      Resource.site = "#{options[:site]}/api/"
    end

    def authorize!
      Resource.authorize_with = get_access_token
    end

    private
    def get_access_token(options={})
      oauth2_client = OAuth2::Client.new(@client_id, @client_secret, site: @site)
      access_token = oauth2_client.client_credentials.get_token(scope: @scope)
      access_token.token
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
commercelayer-0.8.4 lib/commercelayer/client.rb
commercelayer-0.8.3 lib/commercelayer/client.rb
commercelayer-0.8.2 lib/commercelayer/client.rb
commercelayer-0.8.1 lib/commercelayer/client.rb
commercelayer-0.8.0 lib/commercelayer/client.rb