woocommerce_api 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d5fe62b56cded73f61f26308f6bba3ba15898b8
4
- data.tar.gz: d29f7f4ce9027449ac4b2a54110f973e00d2600e
3
+ metadata.gz: 9c5c6ddc266dfa306c0c2eb7cf2e26e691a0e863
4
+ data.tar.gz: 00b4d32c73163f6b2995c8900e24e71b2bc45b12
5
5
  SHA512:
6
- metadata.gz: dc90d44760b4b1c2c2eb801f315c814dbd30b460960cbba17230dac8c0d64375dfafe1f945193af8e230a35df409125cfc027ee4f0557c75c93fafa3e4c2136e
7
- data.tar.gz: bde96c899c1d8f5f172c3e8dc4cfcb499fd91084782243491502b4e2815dcac3241820e1c2f216b7e4d40ca064cabb0890033b86179fa6d8bed0c23a0f670245
6
+ metadata.gz: a68107081a25c7e8ff8bc00682034d2d381f1fe8751224c795c25d2e4db657f0ebf14da6755b2e9f2bcdc8dc0016ef4df447d53b63fc67f57da275689a0bee77
7
+ data.tar.gz: 7c06cfa2fe2c8af611fa75327ded5c307a60305590a3e5bcd098293afcd943ac85a907ed755a199b696c4cd10797c89b27d74ab88131913de3f5d170018613f8
data/README.md CHANGED
@@ -20,6 +20,8 @@ Check out the WooCommerce API endpoints and data that can be manipulated in <htt
20
20
 
21
21
  ## Setup
22
22
 
23
+ Setup for the old WooCommerce API v3:
24
+
23
25
  ```ruby
24
26
  require "woocommerce_api"
25
27
 
@@ -30,6 +32,22 @@ woocommerce = WooCommerce::API.new(
30
32
  )
31
33
  ```
32
34
 
35
+ Setup for the new WP REST API integration:
36
+
37
+ ```ruby
38
+ require "woocommerce_api"
39
+
40
+ woocommerce = WooCommerce::API.new(
41
+ "http://example.com",
42
+ "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
43
+ "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
44
+ {
45
+ wp_api: true,
46
+ version: "wc/v1"
47
+ }
48
+ )
49
+ ```
50
+
33
51
  ### Options
34
52
 
35
53
  | Option | Type | Required | Description |
@@ -42,7 +60,8 @@ woocommerce = WooCommerce::API.new(
42
60
  #### Args options
43
61
 
44
62
  | Option | Type | Required | Description |
45
- | ------------------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------ |
63
+ |--------------------|----------|----------|--------------------------------------------------------------------------------------------------------------|
64
+ | `wp_api` | `Bool` | no | Allow requests to the WP REST API |
46
65
  | `version` | `String` | no | API version, default is `v3` |
47
66
  | `verify_ssl` | `Bool` | no | Verify SSL when connect, use this option as `false` when need to test with self-signed certificates |
48
67
  | `signature_method` | `String` | no | Signature method used for oAuth requests, works with `HMAC-SHA1` and `HMAC-SHA256`, default is `HMAC-SHA256` |
@@ -71,9 +90,13 @@ woocommerce = WooCommerce::API.new(
71
90
 
72
91
  - `.delete(endpoint, query)`
73
92
 
93
+ ### OPTIONS
94
+
95
+ - `.options(endpoint)`
96
+
74
97
  #### Response
75
98
 
76
- All methods will return [HTTPary::Response](https://github.com/jnunemaker/httparty) object.
99
+ All methods will return [HTTParty::Response](https://github.com/jnunemaker/httparty) object.
77
100
 
78
101
  ```ruby
79
102
  response = api.get "customers"
@@ -93,6 +116,7 @@ puts response.headers["x-wc-totalpages"] # Total of pages
93
116
 
94
117
  ## Release History
95
118
 
119
+ - 2016-05-09 - 1.2.0 - Added support for WP REST API and added method to do HTTP OPTIONS requests..
96
120
  - 2015-12-07 - 1.1.2 - Stop send `body` in GET and DELETE requests.
97
121
  - 2015-12-07 - 1.1.1 - Fixed the encode when have spaces in the URL parameters.
98
122
  - 2015-08-27 - 1.1.0 - Added `query` argument for GET and DELETE methods, reduced chance of nonce collisions and added support for urls including ports
@@ -15,12 +15,14 @@ module WooCommerce
15
15
 
16
16
  # Optional args
17
17
  defaults = {
18
+ wp_api: false,
18
19
  version: "v3",
19
20
  verify_ssl: true,
20
21
  signature_method: "HMAC-SHA256"
21
22
  }
22
23
  args = defaults.merge(args)
23
24
 
25
+ @wp_api = args[:wp_api]
24
26
  @version = args[:version]
25
27
  @verify_ssl = args[:verify_ssl] == true
26
28
  @signature_method = args[:signature_method]
@@ -69,6 +71,15 @@ module WooCommerce
69
71
  do_request :delete, add_query_params(endpoint, query)
70
72
  end
71
73
 
74
+ # Public: OPTIONS requests.
75
+ #
76
+ # endpoint - A String naming the request endpoint.
77
+ #
78
+ # Returns the request Hash.
79
+ def options endpoint
80
+ do_request :options, add_query_params(endpoint, nil)
81
+ end
82
+
72
83
  protected
73
84
 
74
85
  # Internal: Appends data as query params onto an endpoint
@@ -80,9 +91,9 @@ module WooCommerce
80
91
  def add_query_params endpoint, data
81
92
  return endpoint if data.nil? || data.empty?
82
93
 
83
- endpoint += '?' unless endpoint.include? '?'
84
- endpoint += '&' unless endpoint.end_with? '?'
85
- endpoint + URI.encode(flatten_hash(data).join('&'))
94
+ endpoint += "?" unless endpoint.include? "?"
95
+ endpoint += "&" unless endpoint.end_with? "?"
96
+ endpoint + URI.encode(flatten_hash(data).join("&"))
86
97
  end
87
98
 
88
99
  # Internal: Get URL for requests
@@ -92,9 +103,10 @@ module WooCommerce
92
103
  #
93
104
  # Returns the endpoint String.
94
105
  def get_url endpoint, method
106
+ api = @wp_api ? 'wp-json' : 'wc-api'
95
107
  url = @url
96
108
  url = "#{url}/" unless url.end_with? "/"
97
- url = "#{url}wc-api/#{@version}/#{endpoint}"
109
+ url = "#{url}#{api}/#{@version}/#{endpoint}"
98
110
 
99
111
  @is_ssl ? url : oauth_url(url, method)
100
112
  end
@@ -1,3 +1,3 @@
1
1
  module WooCommerce
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woocommerce_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Sanches
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.2.2
67
+ rubygems_version: 2.5.1
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: A Ruby wrapper for the WooCommerce API