ruwoco 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruwoco.rb +159 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd0b6d47628e2762008c6900884d0c34427f229f
|
4
|
+
data.tar.gz: ff3def0f381eda504e5a52eb7c37811cc67afd7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c901e75781624e341494a7bd36700c680b9b2a71e3ff478f21620e0b591a1ec71ad316f440c22bea9032a254cd479b869cfeb6794ec05f9d50aaaf7167cf6fef
|
7
|
+
data.tar.gz: 2b8029323e26a794292d17d4f8c77175df3c3682d0e52402ce9f3a5683bb5a2a2fea597227c3183637cfef157b19b1cbf4c8ce16e35f2c154809b6929e2d5fbb
|
data/lib/ruwoco.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
class RuWoCo
|
2
|
+
require "digest/sha1"
|
3
|
+
require "cgi"
|
4
|
+
require "json"
|
5
|
+
require "base64"
|
6
|
+
require "openssl"
|
7
|
+
require "net/http"
|
8
|
+
require "net/https"
|
9
|
+
|
10
|
+
attr_accessor :consumer_key, :consumer_secret, :api_url, :is_ssl
|
11
|
+
|
12
|
+
API_ENDPOINT = "wc-api/v1/"
|
13
|
+
HTTP_GET = "GET"
|
14
|
+
HTTP_POST = "POST"
|
15
|
+
|
16
|
+
def initialize(consumer_key, consumer_secret, store_url, is_ssl = true)
|
17
|
+
if consumer_key && consumer_secret && store_url
|
18
|
+
@consumer_key = consumer_key
|
19
|
+
@consumer_secret = consumer_secret
|
20
|
+
@api_url = store_url + API_ENDPOINT
|
21
|
+
@is_ssl = is_ssl
|
22
|
+
elsif !consumer_key
|
23
|
+
raise "Consumer key missing"
|
24
|
+
elsif !consumer_secret
|
25
|
+
raise "Consumer secret missing"
|
26
|
+
else
|
27
|
+
raise "Store URL missing"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_index()
|
32
|
+
return make_api_call()
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_orders(params = {})
|
36
|
+
return make_api_call("orders", params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_order(order_id)
|
40
|
+
return make_api_call("orders/#{order_id}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_orders_count()
|
44
|
+
return make_api_call("orders/count")
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_order_notes(order_id)
|
48
|
+
return make_api_call("orders/#{order_id}/notes")
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_order(order_id, params = {})
|
52
|
+
return make_api_call("orders/#{order_id}", params, 'POST')
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_coupons(params = {})
|
56
|
+
return make_api_call("coupons", params)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_coupon(coupon_id)
|
60
|
+
return make_api_call("coupons/#{coupon_id}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_coupons_count()
|
64
|
+
return make_api_call("coupons/count")
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_coupon_by_code(coupon_code)
|
68
|
+
return make_api_call("coupons/code/#{coupon_code}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_customers(params = {})
|
72
|
+
return make_api_call("customers", params)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_customer(customer_id)
|
76
|
+
return make_api_call("customers/#{customer_id}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_customer_by_email(email)
|
80
|
+
return make_api_call("customers/email/#{email}")
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_customers_count()
|
84
|
+
return make_api_call("customers/count")
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_customer_orders(customer_id)
|
88
|
+
return make_api_call("customers/#{customer_id}/orders")
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_products()
|
92
|
+
return make_api_call("products")
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_product(product_id)
|
96
|
+
return make_api_call("products/#{product_id}")
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_products_count()
|
100
|
+
return make_api_call("products/count")
|
101
|
+
end
|
102
|
+
|
103
|
+
def get_reports(params = {})
|
104
|
+
return make_api_call("reports")
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_sales_report(params = {})
|
108
|
+
return make_api_call("reports/sales", params)
|
109
|
+
end
|
110
|
+
|
111
|
+
def get_top_sellers_report(params = {})
|
112
|
+
return make_api_call("reports/sales/top_sellers", params)
|
113
|
+
end
|
114
|
+
|
115
|
+
def make_api_call(endpoint, params = {}, method='GET')
|
116
|
+
if (!@is_ssl)
|
117
|
+
params[:oauth_consumer_key] = @consumer_key
|
118
|
+
params[:oauth_nonce] = Digest::SHA1.hexdigest(Time.new.to_i)
|
119
|
+
params[:oauth_signature_method] = 'HMAC-256'
|
120
|
+
params[:oauth_timestamp] = Time.new.to_i
|
121
|
+
params[:oauth_signature] = generate_oauth_signature(endpoint, params, method)
|
122
|
+
end
|
123
|
+
|
124
|
+
if (method == HTTP_GET)
|
125
|
+
query = URI.encode_www_form(params)
|
126
|
+
uri = URI(@api_url + endpoint + '?' + query)
|
127
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
128
|
+
http.use_ssl = true
|
129
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
130
|
+
req.basic_auth(@consumer_key, @consumer_secret)
|
131
|
+
res = http.start { |test| test.request(req) }
|
132
|
+
elsif (method == HTTP_POST)
|
133
|
+
url = URI.parse(@api_url + endpoint)
|
134
|
+
req = Net::HTTP::Post.new(url.path)
|
135
|
+
req.basic_auth(@consumer_key, @consumer_secret)
|
136
|
+
req.body = params.to_json
|
137
|
+
sock = Net::HTTP.new(url.host, url.port)
|
138
|
+
sock.use_ssl = true
|
139
|
+
res = sock.start { |test| test.request(req) }
|
140
|
+
else
|
141
|
+
raise "Unsupported HTTP operation requested"
|
142
|
+
end
|
143
|
+
|
144
|
+
return res.body.to_json()
|
145
|
+
end
|
146
|
+
|
147
|
+
def generate_oauth_signature(endpoint, params, method)
|
148
|
+
base_request_uri = CGI::escape(@api_url + endpoint)
|
149
|
+
|
150
|
+
query_params = []
|
151
|
+
params.each { |key, value| query_params.push(CGI::escape(key) + "%3D" + CGI::escape(value)) }
|
152
|
+
|
153
|
+
query_string = "%26".join(query_params)
|
154
|
+
|
155
|
+
string_to_sign = method + "&" + base_request_uri + '&' + query_string
|
156
|
+
|
157
|
+
return Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @consumer_secret, string_to_sign))
|
158
|
+
end
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruwoco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Cooper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby WooCommerce RESTful API client library
|
14
|
+
email: dave@davecooper.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ruwoco.rb
|
20
|
+
homepage: http://github.com/gurgus/RuWoCo
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ruby WooCommerce client library
|
44
|
+
test_files: []
|