Class: EcwidApi::Client

Inherits:
Object
  • Object
show all
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 do |config|
  config.store_id = '12345'
  config.url = 'http://app.ecwid.com/api/v1'
  config.order_secret_key = 'ORDER_SECRET_KEY'
  config.product_secret_key = 'PRODUCT_SECRET_KEY'
end

Constant Summary collapse

DEFAULT_URL =

The default base URL for the Ecwid API

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:

Raises:



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

def initialize
  yield(self) if block_given?
  raise Error.new("The store_id is required") unless store_id
end

Instance Attribute Details

#order_secret_keyObject

Public: Gets or sets the Order API Secret Key for the Ecwid Store



24
25
26
# File 'lib/ecwid_api/client.rb', line 24

def order_secret_key
  @order_secret_key
end

#product_secret_keyObject

Public: Gets or sets the default Product API Secret Key for the Ecwid Store



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

def product_secret_key
  @product_secret_key
end

#store_idObject

Public: Returns the Ecwid Store ID



21
22
23
# File 'lib/ecwid_api/client.rb', line 21

def store_id
  @store_id
end

Instance Method Details

#get(path, params = {}) ⇒ Object

Public: Sends a GET request to the Ecwid API

path - The String path for the URL of the request without the base URL params - A Hash of query string parameters

Examples

# Gets the Categories where the parent Category is 1
client.get("categories", parent: 1)
# => #<Faraday::Response>

Returns a Faraday::Response



68
69
70
# File 'lib/ecwid_api/client.rb', line 68

def get(path, params={})
  connection.get(path, params)
end

#store_urlObject

Public: The URL of the API for the Ecwid Store



52
53
54
# File 'lib/ecwid_api/client.rb', line 52

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

#urlObject

Public: Returns the base URL of the Ecwid API



35
36
37
# File 'lib/ecwid_api/client.rb', line 35

def url
  @url || DEFAULT_URL
end

#url=(url) ⇒ Object

Public: Sets the base URL for the Ecwid API



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

def url=(url)
  reset_connection
  @url = url
end