Class: Blupee::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/blupee/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id = nil, client_secret = nil) ⇒ Auth

Creates a new client.

Parameters:

  • client_id (String, Integer) (defaults to: nil)

    a Blupee client ID

  • client_secret (defaults to: nil)

    a Blupee client secret


13
14
15
16
# File 'lib/blupee/auth.rb', line 13

def initialize(client_id = nil, client_secret = nil)
  @client_id = client_id || Blupee.config.client_id
  @client_secret = client_secret || Blupee.config.client_secret
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.


7
8
9
# File 'lib/blupee/auth.rb', line 7

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.


7
8
9
# File 'lib/blupee/auth.rb', line 7

def client_secret
  @client_secret
end

Instance Method Details

#get_access_token(options = {}) ⇒ Object

Fetches the application’s access token (ignoring expiration and other info).

Returns:

  • the application access token

See Also:

  • get_app_access_token_info

43
44
45
46
47
# File 'lib/blupee/auth.rb', line 43

def get_access_token(options = {})
  if info = get_access_token_info(options)
    Blupee.config.access_token = info["access_token"]
  end
end

#get_access_token_info(options = {}) ⇒ Object

Fetches an access token, token expiration, and other info from Blupee. Useful when you’ve received an OAuth code using the server-side authentication process.

Parameters:

  • options (defaults to: {})

    any additional parameters to send to Blupee when redeeming the token

Returns:

  • a hash of the access token info returned by Blupee (token, expiration, etc.)

Raises:

  • Blupee::OAuthTokenRequestError if Blupee returns an error response

See Also:

  • url_for_oauth_code

32
33
34
35
# File 'lib/blupee/auth.rb', line 32

def get_access_token_info(options = {})
  # convenience method to get a the application's sessionless access token
   get_token_from_server({}, true, options)
end