Class: EcwidApi::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ecwid_api/client.rb

Overview

Public: Client objects manage the connection and interface to a single Ecwid store.

Examples

client = EcwidApi::Client.new(store_id: '12345', token: 'the access_token')
client.get "/products"

Constant Summary collapse

DEFAULT_URL =

The default base URL for the Ecwid API

"https://app.ecwid.com/api/v3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store_id, token, adapter = Faraday.default_adapter) ⇒ Client

Public: Initializes a new Client to interact with the API

store_id - the Ecwid store_id to interact with token - the authorization token provided by oAuth. See the

Authentication class


27
28
29
# File 'lib/ecwid_api/client.rb', line 27

def initialize(store_id, token, adapter = Faraday.default_adapter)
  @store_id, @token, @adapter = store_id, token, adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



19
20
21
# File 'lib/ecwid_api/client.rb', line 19

def adapter
  @adapter
end

#store_idObject (readonly)

Public: Returns the Ecwid Store ID



17
18
19
# File 'lib/ecwid_api/client.rb', line 17

def store_id
  @store_id
end

#tokenObject (readonly)

Returns the value of attribute token.



18
19
20
# File 'lib/ecwid_api/client.rb', line 18

def token
  @token
end

Instance Method Details

#categoriesObject

Public: Returns the Category API



39
40
41
# File 'lib/ecwid_api/client.rb', line 39

def categories
  @categories ||= Api::Categories.new(self)
end

#connectionObject

Private: Returns a Faraday connection to interface with the Ecwid API



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ecwid_api/client.rb', line 54

def connection
  @connection ||= Faraday.new store_url do |conn|
    conn.request  :oauth2, token, param_name: :token
    conn.request  :json

    conn.response :json, content_type: /\bjson$/
    conn.response :logger

    conn.adapter  adapter
  end
end

#ordersObject

Public: Returns the Order API



44
45
46
# File 'lib/ecwid_api/client.rb', line 44

def orders
  @orders ||= Api::Orders.new(self)
end

#productsObject

Public: Returns the Products API



49
50
51
# File 'lib/ecwid_api/client.rb', line 49

def products
  @products ||= Api::Products.new(self)
end

#store_urlObject

Public: The URL of the API for the Ecwid Store



32
33
34
# File 'lib/ecwid_api/client.rb', line 32

def store_url
  "#{DEFAULT_URL}/#{store_id}"
end