Class: SpreePlatformApiClient::Client

Inherits:
Object
  • Object
show all
Includes:
Actions
Defined in:
lib/spree_platform_api_client/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#create, #delete, #index, #show, #update

Constructor Details

#initialize(client_id:, client_secret:, username:, password:, host:) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spree_platform_api_client/client.rb', line 9

def initialize(client_id:, client_secret:, username:, password:, host:)
  @host = host
  @token = nil

  result = HTTP.post(
    URI.join(host, "spree_oauth/token").to_s,
    json: {
      grant_type:    "password",
      scope:         "admin",
      username:      username,
      password:      password,
      client_id:     client_id,
      client_secret: client_secret,
    }
  ).parse

  raise result["error_description"] if result["error"]
  @token = result["access_token"]
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/spree_platform_api_client/client.rb', line 8

def host
  @host
end

Class Method Details

.config {|@config| ... } ⇒ Object

Yields:



33
34
35
36
37
# File 'lib/spree_platform_api_client/client.rb', line 33

def self.config
  @config ||= SpreePlatformApiClient::Config.new
  yield @config if block_given?
  @config
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/spree_platform_api_client/client.rb', line 29

def authenticated?
  !@token.nil?
end