Class: WooCommerce::Client
- Inherits:
-
Object
- Object
- WooCommerce::Client
- Defined in:
- lib/woo_commerce/client.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #connection ⇒ Object
- #coupons ⇒ Object
- #customers ⇒ Object
-
#initialize(url:, api_key:, api_secret:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #order_notes ⇒ Object
- #orders ⇒ Object
- #product_categories ⇒ Object
- #product_variations ⇒ Object
- #products ⇒ Object
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/woo_commerce/client.rb', line 4 def adapter @adapter end |
#api_key ⇒ Object (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_secret ⇒ Object (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 |
#url ⇒ Object (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
#connection ⇒ Object
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 |
#coupons ⇒ Object
16 17 18 |
# File 'lib/woo_commerce/client.rb', line 16 def coupons CouponsResource.new(self) end |
#customers ⇒ Object
20 21 22 |
# File 'lib/woo_commerce/client.rb', line 20 def customers CustomersResource.new(self) end |
#order_notes ⇒ Object
28 29 30 |
# File 'lib/woo_commerce/client.rb', line 28 def order_notes OrderNotesResource.new(self) end |
#orders ⇒ Object
24 25 26 |
# File 'lib/woo_commerce/client.rb', line 24 def orders OrdersResource.new(self) end |
#product_categories ⇒ Object
40 41 42 |
# File 'lib/woo_commerce/client.rb', line 40 def product_categories ProductCategoriesResource.new(self) end |
#product_variations ⇒ Object
36 37 38 |
# File 'lib/woo_commerce/client.rb', line 36 def product_variations ProductVariationsResource.new(self) end |
#products ⇒ Object
32 33 34 |
# File 'lib/woo_commerce/client.rb', line 32 def products ProductsResource.new(self) end |