Sha256: fd57fd4072245dac439cabf207421653ec155109c2bc6b8f9c1fb0e44163d62b

Contents?: true

Size: 610 Bytes

Versions: 5

Compression:

Stored size: 610 Bytes

Contents

require "oauth2"

module Commercelayer
  class Client

    def initialize(options={})
      @client_id = options[:client_id]
      @client_secret = options[:client_secret]
      @scope = options[:scope]
      @site = options[:site]
    end

    def authorize!
      Resource.site = @site + "/api/"
      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.5.0 lib/commercelayer/client.rb
commercelayer-0.4.0 lib/commercelayer/client.rb
commercelayer-0.3.0 lib/commercelayer/client.rb
commercelayer-0.2.0 lib/commercelayer/client.rb
commercelayer-0.1.0 lib/commercelayer/client.rb