Class: Lucid::Shopify::Authorise

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid/shopify/authorise.rb

Constant Summary collapse

Error =
Class.new(Error)

Instance Method Summary collapse

Constructor Details

#initialize(client: Container[:client]) ⇒ Authorise

Returns a new instance of Authorise.

Parameters:

  • client (#post_json) (defaults to: Container[:client])


11
12
13
# File 'lib/lucid/shopify/authorise.rb', line 11

def initialize(client: Container[:client])
  @client = client
end

Instance Method Details

#call(myshopify_domain, authorisation_code) ⇒ String

Exchange an authorisation code for a new Shopify access token.

Parameters:

  • myshopify_domain (String)
  • authorisation_code (String)

Returns:

  • (String)

    the access token

Raises:

  • (Error)

    if the response is invalid



23
24
25
26
27
28
29
30
31
32
# File 'lib/lucid/shopify/authorise.rb', line 23

def call(myshopify_domain, authorisation_code)
  credentials = Credentials.new(myshopify_domain)

  data = @client.post_json(credentials, 'oauth/access_token', post_data(authorisation_code))

  raise Error if data['access_token'].nil?
  raise Error if data['scope'] != Shopify.config.scope

  data['access_token']
end