Class: Arctic::Vendor::API

Inherits:
Object
  • Object
show all
Defined in:
lib/arctic/vendor/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ API

Returns a new instance of API.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/arctic/vendor/api.rb', line 10

def initialize(**options)
  api_token = options.fetch(:token, ENV.fetch('ARCTIC_CORE_API_TOKEN'))
  api_url = options.fetch(:url,
    ENV.fetch('ARCTIC_CORE_API_URL',
      'http://localhost:5000/v1/vendors'))

  @token = api_token
  headers = {
    Authorization: "Vendor #{token}",
    'Content-Type': 'application/json',
    Accept: 'application/json',
  }
  @connection = Faraday.new url: api_url.chomp('/'), headers: headers
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/arctic/vendor/api.rb', line 8

def connection
  @connection
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/arctic/vendor/api.rb', line 8

def token
  @token
end

Instance Method Details

#list_accountsObject

List the current accounts available to the vendor



26
27
28
# File 'lib/arctic/vendor/api.rb', line 26

def list_accounts
  make_request :get, 'accounts'
end

#list_shops(account_id) ⇒ Object

List shops for a single account



36
37
38
# File 'lib/arctic/vendor/api.rb', line 36

def list_shops()
  make_request :get, "accounts/#{}/shops"
end

#send_products(account_id, shop_id, products) ⇒ Object

Send products to the Core API



41
42
43
44
45
# File 'lib/arctic/vendor/api.rb', line 41

def send_products(, shop_id, products)
  products.tap do |px|
    make_batch_request :post, "accounts/#{}/shops/#{shop_id}/products", body: px
  end
end

#show_account(account_id) ⇒ Object

Show details about a single account



31
32
33
# File 'lib/arctic/vendor/api.rb', line 31

def ()
  make_request :get, "accounts/#{}"
end