Class: WooCommerce::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/woo_commerce/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, api_key:, api_secret:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
# File 'lib/woo_commerce/client.rb', line 6

def initialize(url:, api_key:, api_secret:, adapter: Faraday.default_adapter, stubs: nil)
  @url = url
  @api_key = api_key
  @api_secret = api_secret
  @adapter = adapter

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



4
5
6
# File 'lib/woo_commerce/client.rb', line 4

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



4
5
6
# File 'lib/woo_commerce/client.rb', line 4

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



4
5
6
# File 'lib/woo_commerce/client.rb', line 4

def api_secret
  @api_secret
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/woo_commerce/client.rb', line 4

def url
  @url
end

Instance Method Details

#connectionObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/woo_commerce/client.rb', line 44

def connection
  @connection ||= Faraday.new("#{url}/wp-json/wc/v3") do |conn|
    conn.request :authorization, :basic, api_key, api_secret
    conn.request :json

    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#couponsObject



16
17
18
# File 'lib/woo_commerce/client.rb', line 16

def coupons
  CouponsResource.new(self)
end

#customersObject



20
21
22
# File 'lib/woo_commerce/client.rb', line 20

def customers
  CustomersResource.new(self)
end

#order_notesObject



28
29
30
# File 'lib/woo_commerce/client.rb', line 28

def order_notes
  OrderNotesResource.new(self)
end

#ordersObject



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

def orders
  OrdersResource.new(self)
end

#product_categoriesObject



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

def product_categories
  ProductCategoriesResource.new(self)
end

#product_variationsObject



36
37
38
# File 'lib/woo_commerce/client.rb', line 36

def product_variations
  ProductVariationsResource.new(self)
end

#productsObject



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

def products
  ProductsResource.new(self)
end