bigcommerce 0.0.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,16 +6,12 @@ Ruby apps or via the console.
6
6
 
7
7
  Note
8
8
  ----
9
-
10
- **The Ruby Client is still in alpha and core features of the API may be
11
- unsupported and undocumented.**
9
+ If you find anything that is missing or needs clean up, please feel free to fork it and submit a changes with your pull request.
12
10
 
13
11
  Requirements
14
12
  ------------
15
13
 
16
- - Ruby 1.8.7+
17
- - Rubygems
18
- - JSON
14
+ - Ruby 1.9+
19
15
 
20
16
  To connect to the API, you need the following credentials:
21
17
 
@@ -25,7 +21,7 @@ To connect to the API, you need the following credentials:
25
21
 
26
22
  A valid API key is required to authenticate requests. To grant API access for
27
23
  user, go to Control Panel > Users > Edit User and make sure that the
28
- 'Enable the XML API?' checkbox is ticked.
24
+ 'Enable API access?' checkbox is ticked.
29
25
 
30
26
  Installation
31
27
  ------------
@@ -37,6 +33,13 @@ install the package directly from Rubygems:
37
33
  gem install bigcommerce
38
34
  ```
39
35
 
36
+ Note - the current gem version is 1.0. The Rubygems version might be older. You can install the gem directly from this repo. If you are using rails, you can point your gemfile to this git repo directly or do a local install of the gem by -
37
+
38
+ ```
39
+ gem build bigcommerce
40
+ gem install bigcommerce-1.0.gem
41
+ ```
42
+
40
43
  Configuration
41
44
  -------------
42
45
 
@@ -46,12 +49,28 @@ follows:
46
49
  ```
47
50
  require 'bigcommerce'
48
51
 
49
- api = Bigcommerce::Api.new({
52
+ api = BigCommerce::Api.new({
53
+ :store_url => "https://store.mybigcommerce.com",
54
+ :username => "admin",
55
+ :api_key => "d81aada4c19c34d913e18f07fd7f36ca"
56
+ })
57
+ ```
58
+
59
+ If you want to enable SSL certificates -
60
+
61
+ ```
62
+ require 'bigcommerce'
63
+ api = BigCommerce::Api.new({
50
64
  :store_url => "https://store.mybigcommerce.com",
51
65
  :username => "admin",
52
66
  :api_key => "d81aada4c19c34d913e18f07fd7f36ca"
67
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
68
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
69
+ :ssl_ca_file => "ca_certificate.pem",
70
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
53
71
  })
54
72
  ```
73
+ Remember that the fields :ssl_client_cert, :ssl_client_key, :ssl_ca_file and :verify_ssl are all requrired when enabling SSL certs.
55
74
 
56
75
  Connecting to the store
57
76
  -----------------------
@@ -68,27 +87,35 @@ Usage
68
87
 
69
88
  The API object acts as a gateway to all top level resources in the V2 API.
70
89
 
90
+ Fetch Data
71
91
  ```
72
- $ irb
73
- >
74
- > api = Bigcommerce::Api.new(...)
75
- >
76
- > api.get_products.each { |product| puts product.name }
77
- >
78
- > api.get_customers.each { |customer| puts customer.email }
79
- >
80
- > puts api.get_orders_count
81
- >
82
- > category = api.get_category(11)
83
- > category.name = "Laptops"
84
- > category.update
85
- >
86
- > brand = Bigcommerce::Api::Brand.new
87
- > brand.name = "Samsung"
88
- > brand.create
89
- >
90
- > option = api.get_option(22)
91
- > option.delete
92
- >
92
+ orders = api.get_orders
93
+ orders = api.get_orders({:min_id=>100,:max_id=>101})
94
+ orders = api.get_orders(:is_deleted => true)
95
+
96
+ products = api.get_products
97
+ products = api.get_products(:description=>"iphone", :condition=>"New")
98
+
99
+ options = api.get_options
100
+ options = api.get_options(:type=>"MT")
101
+ ...
102
+
103
+ ```
104
+ Create Data
105
+ ```
106
+ api.create_products({:name => "Spiderman - The best return",:price => 9.99,:categories => [17],:type =>"physical",:availability => "available", :weight => 1})
107
+
108
+ api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
109
+
110
+ api.update_orders(101,{:status_id => 12, :is_deleted => true})
111
+
112
+ ```
113
+ Update Data
114
+
115
+ ```
116
+ api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
117
+
118
+ api.update_optionsets(13,{:name => "Marvel toys"})
119
+
93
120
  ```
94
121
 
data/bigcommerce.gemspec CHANGED
@@ -4,6 +4,7 @@ require File.expand_path('../lib/bigcommerce/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.add_dependency('activesupport')
6
6
  s.add_dependency('json')
7
+ s.add_dependency('rest-client')
7
8
  s.add_development_dependency("ci_reporter")
8
9
  s.add_development_dependency("fakeweb")
9
10
  s.add_development_dependency("mocha")
data/lib/bigcommerce.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "cgi"
2
2
  require "json"
3
- require "net/https"
3
+ require 'rest-client'
4
4
  require "uri"
5
5
  require 'bigcommerce/api'
6
6
  require 'bigcommerce/connection'
@@ -5,7 +5,6 @@ module Bigcommerce
5
5
  @connection = Connection.new(configuration)
6
6
  end
7
7
 
8
- # Added getter to ensure configuration is correct
9
8
  def connection
10
9
  @connection
11
10
  end
@@ -22,16 +21,14 @@ module Bigcommerce
22
21
  @connection.api_key = api_key
23
22
  end
24
23
 
25
- def verify_peer=(verify)
26
- @connection.verify_peer = verify
24
+ def verify_ssl=(verify)
25
+ @connection.verify_ssl = verify
27
26
  end
28
27
 
29
28
  def ca_file=(path)
30
29
  @connection.ca_file = path
31
30
  end
32
31
 
33
- # Returns the date formatted as
34
- # RFC 2822 string
35
32
  def to_rfc2822(datetime)
36
33
  datetime.strftime("%a, %d %b %Y %H:%M:%S %z")
37
34
  end
@@ -40,24 +37,24 @@ module Bigcommerce
40
37
  @connection.get '/time'
41
38
  end
42
39
 
43
- def get_products(params={})
44
- @connection.get '/products'
40
+ def get_brands(options={})
41
+ @connection.get("/brands", options)
45
42
  end
46
43
 
47
- def get_products_count
48
- @connection.get '/products/count/'
44
+ def get_brand(id)
45
+ @connection.get("/brands/#{id}", {})
49
46
  end
50
47
 
51
- def get_brands
52
- @connection.get '/brands'
48
+ def create_brands(options={})
49
+ @connection.post("/brands", options)
53
50
  end
54
51
 
55
- def get_product(id)
56
- @connection.get '/products/' + id.to_s
52
+ def update_brand(id, options={})
53
+ @connection.put("/brands/#{id}", options)
57
54
  end
58
55
 
59
- def get_categories
60
- @connection.get '/categories'
56
+ def get_categories(options={})
57
+ @connection.get("/categories", options)
61
58
  end
62
59
 
63
60
  def get_categories_count
@@ -65,56 +62,288 @@ module Bigcommerce
65
62
  end
66
63
 
67
64
  def get_category(id)
68
- @connection.get '/categories/' + id.to_s
65
+ @connection.get("/categories/#{id}", {})
66
+ end
67
+
68
+ def create_categories(options={})
69
+ @connection.post("/categories", options)
70
+ end
71
+
72
+ def update_category(id, options={})
73
+ @connection.put("/categories/#{id}", options)
74
+ end
75
+
76
+ def get_countries(options={})
77
+ @connection.get("/countries", options)
78
+ end
79
+
80
+ def get_country(id)
81
+ @connection.get("/countries/#{id}", {})
82
+ end
83
+
84
+ def get_countries_states(options={})
85
+ @connection.get("/countries/states", options)
86
+ end
87
+
88
+ def get_countries_state(id, options={})
89
+ @connection.get("/countries/#{id}/states", {})
90
+ end
91
+
92
+ def get_customers(options = {})
93
+ @connection.get("/customers", options)
94
+ end
95
+
96
+ def get_customer(id)
97
+ @connection.get('/customers/' + id.to_s, {})
98
+ end
99
+
100
+ def get_customer_addresses(id, options = {})
101
+ @connection.get("/customers/#{id}/addresses", options)
102
+ end
103
+
104
+ def get_customer_address(customer_id, address_id)
105
+ @connection.get("/customers/#{customer_id}/addresses/#{address_id}",{})
106
+ end
107
+
108
+ def get_options(options={})
109
+ @connection.get("/options", options)
110
+ end
111
+
112
+ def get_option(id)
113
+ @connection.get("/options/#{id}",{})
114
+ end
115
+
116
+ def create_options(options={})
117
+ @connection.post("/options", options)
118
+ end
119
+
120
+ def update_option(id, options={})
121
+ @connection.put("/options/#{id}", options)
69
122
  end
70
123
 
71
- def get_orders(params={})
72
- @connection.get('/orders', :params => params)
124
+ def get_options_values(options={})
125
+ @connection.get("/options/values", options)
73
126
  end
74
127
 
75
- def get_orders_by_date(date, params={})
128
+ def get_options_value(id)
129
+ @connection.get("/options/#{id}/values",{})
130
+ end
131
+
132
+ def create_options_values(options_id, options={})
133
+ @connection.post("/options/#{options_id}/values", options)
134
+ end
135
+
136
+ def update_options_value(options_id, values_id, options={})
137
+ @connection.put("/options/#{options_id}/values/#{values_id}", options)
138
+ end
139
+
140
+ def get_optionsets(options={})
141
+ @connection.get("/optionsets", options)
142
+ end
143
+
144
+ def get_optionset(id)
145
+ @connection.get("/optionsets/#{id}", {})
146
+ end
147
+
148
+ def create_optionsets(options={})
149
+ @connection.post("/optionsets", options)
150
+ end
151
+
152
+ def update_optionset(id,options={})
153
+ @connection.put("/optionsets/#{id}", options)
154
+ end
155
+
156
+ def get_optionsets_options(options={})
157
+ @connection.get("/optionsets/options", options)
158
+ end
159
+
160
+ def get_optionsets_option(id)
161
+ @connection.get("/optionsets/options/#{id}", {})
162
+ end
163
+
164
+ def create_optionsets_options(options={})
165
+ @connection.post("/optionsets/options", options)
166
+ end
167
+
168
+ def update_optionsets_option(id,options={})
169
+ @connection.put("/optionsets/options/#{id}", options)
170
+ end
171
+
172
+ def get_orders(options={})
173
+ @connection.get("/orders", options)
174
+ end
175
+
176
+ def get_orders_by_date(date, options={})
76
177
  if date.is_a?(String)
77
178
  date = DateTime.parse(date)
78
179
  end
79
180
  date = to_rfc2822(date)
80
- @connection.get('/orders', :params => params.merge!(:min_date_created => CGI::escape(date)))
181
+ @connection.get('/orders', options.merge!(:min_date_created => CGI::escape(date)))
81
182
  end
82
183
 
83
- def get_orders_count
84
- get_count @connection.get '/orders/count'
184
+ def get_orders_modified_since(date)
185
+ @connection.get('/orders', {}, {'If-Modified-Since' => CGI::escape(to_rfc2822(date))})
85
186
  end
86
187
 
87
188
  def get_order(id)
88
- @connection.get '/orders/' + id.to_s
189
+ @connection.get("/orders/#{id}", {})
89
190
  end
90
191
 
91
- def get_order_products(id)
92
- @connection.get '/orders/' + id.to_s + '/products'
192
+ def update_order(id,options={})
193
+ @connection.put("/orders/#{id}", options)
93
194
  end
94
195
 
95
- def get_orders_modified_since(datetime)
96
- @connection.get('/orders', :headers => {'If-Modified-Since' => CGI::escape(to_rfc2822(datetime))})
196
+ def get_orders_coupons(id)
197
+ @connection.get("/orders/#{id}/coupons", {})
97
198
  end
98
199
 
99
- def get_customers(_filters = {})
100
- url_filters = _filters.map{|k,v| "#{k}=#{v}"}.join("&")
101
- @connection.get "/customers#{url_filters.present? ? ("?" + url_filters) : ""}"
200
+ def get_orders_product(order_id,coupon_id)
201
+ @connection.get("/orders/#{order_id}/coupons/#{coupon_id}", {})
102
202
  end
103
203
 
104
- def get_customer(id)
105
- @connection.get '/customers/' + id.to_s
204
+ def get_orders_products(id)
205
+ @connection.get("/orders/#{id}/products", {})
206
+ end
207
+
208
+ def get_orders_product(order_id,product_id)
209
+ @connection.get("/orders/#{order_id}/products/#{product_id}", {})
210
+ end
211
+
212
+ def get_orders_shipments(id)
213
+ @connection.get("/orders/#{id}/shipments", {})
214
+ end
215
+
216
+ def create_orders_shipments(id)
217
+ @connection.post("/orders/#{id}/shipments", {})
106
218
  end
107
219
 
108
- def get_customer_count
109
- @connection.get '/customers/count'
220
+ def get_orders_shipment(order_id,shipment_id)
221
+ @connection.get("/orders/#{order_id}/shipments/#{shipment_id}", {})
110
222
  end
111
223
 
112
- def create_product(attributes)
113
- @connection.post('/products', :body => attributes.to_xml(:root => 'product'))
224
+ def update_orders_shipment(order_id,shipment_id,options={})
225
+ @connection.put("/orders/#{order_id}/shipments/#{shipment_id}", options)
114
226
  end
115
227
 
116
- def update_product(id, attributes)
117
- @connection.put("/products/#{id}", :body => attributes.to_xml(:root => 'product'))
228
+ def get_orders_shippingaddresses(id)
229
+ @connection.get("/orders/#{id}/shippingaddresses", {})
230
+ end
231
+
232
+ def get_orders_shippingaddress(order_id,shippingaddress_id)
233
+ @connection.get("/orders/#{order_id}/shippingaddresses/#{shippingaddress_id}", {})
234
+ end
235
+
236
+ def get_orderstatuses(options={})
237
+ @connection.get("/orderstatuses", options)
238
+ end
239
+
240
+ def get_orderstatuses(id)
241
+ @connection.get("/orderstatuses/#{id}", {})
242
+ end
243
+
244
+ def get_products(options={})
245
+ @connection.get("/products", options)
246
+ end
247
+
248
+ def get_product(id)
249
+ @connection.get("/products/#{id}", {})
250
+ end
251
+
252
+ def create_products(options={})
253
+ @connection.post('/products', options)
254
+ end
255
+
256
+ def update_products(id, options={})
257
+ @connection.put("/products/#{id}", options)
258
+ end
259
+
260
+ def get_products_discountrules(options={})
261
+ @connection.get("/products/discountrules", options)
262
+ end
263
+
264
+ def get_products_discountrule(product_id, discountrule_id)
265
+ @connection.get("/products/#{product_id}/discountrules/#{discountrule_id}", {})
266
+ end
267
+
268
+ def get_products_configurablefields(options={})
269
+ @connection.get("/products/configurablefields", options)
270
+ end
271
+
272
+ def get_products_configurablefield(product_id, configurable_field_id)
273
+ @connection.get("/products/#{product_id}/configurablefields/#{configurable_field_id}", {})
274
+ end
275
+
276
+ def get_products_customfields(options={})
277
+ @connection.get("/products/customfields", options)
278
+ end
279
+
280
+ def get_products_customfield(product_id, custom_field_id)
281
+ @connection.get("/products/#{product_id}/customfields/#{custom_field_id}", {})
282
+ end
283
+
284
+ def get_products_images(options={})
285
+ @connection.get("/products/images", options)
286
+ end
287
+
288
+ def create_products_images(options={})
289
+ @connection.post("/products/images", options)
290
+ end
291
+
292
+ def get_products_image(product_id, image_id)
293
+ @connection.get("/products/#{product_id}/images/#{image_id}", {})
294
+ end
295
+
296
+ def update_products_image(product_id,image_id,options={})
297
+ @connection.put("/products/#{product_id}/images/#{image_id}", options)
298
+ end
299
+
300
+ def get_products_customfields(options={})
301
+ @connection.get("/products/options", options)
302
+ end
303
+
304
+ def get_products_option(product_id,option_id)
305
+ @connection.get("/products/#{product_id}/options/#{option_id}", {})
306
+ end
307
+
308
+ def get_products_rules(options={})
309
+ @connection.get("/products/rules", options)
310
+ end
311
+
312
+ def create_products_rules(options={})
313
+ @connection.post("/products/rules", options)
314
+ end
315
+
316
+ def get_products_rule(product_id,rule_id)
317
+ @connection.get("/products/#{product_id}/rules/#{rule_id}", {})
318
+ end
319
+
320
+ def update_products_rule(product_id, rule_id, options={})
321
+ @connection.put("/products/#{product_id}/rules/#{rule_id}", options)
322
+ end
323
+
324
+ #products/skus
325
+ def get_products_skus(options={})
326
+ @connection.get("/products/skus", options)
327
+ end
328
+
329
+ def create_products_skus(options={})
330
+ @connection.post("/products/skus", options)
331
+ end
332
+
333
+ def get_products_sku(product_id, sku_id)
334
+ @connection.get("/products/#{product_id}/skus/#{sku_id}", {})
335
+ end
336
+
337
+ def update_products_sku(product_id, sku_id, options={})
338
+ @connection.put("/products/#{product_id}/skus/#{sku_id}", options)
339
+ end
340
+
341
+ def get_products_videos(options={})
342
+ @connection.get("/products/videos", options)
343
+ end
344
+
345
+ def get_products_video(product_id, video_id)
346
+ @connection.get("/products/#{product_id}/videos/#{video_id}", {})
118
347
  end
119
348
 
120
349
  private
@@ -124,11 +353,11 @@ module Bigcommerce
124
353
  end
125
354
 
126
355
  def get_resource(result)
127
-
356
+ result
128
357
  end
129
358
 
130
359
  def get_collection(result)
131
-
360
+ result
132
361
  end
133
362
 
134
363
  end
@@ -18,90 +18,70 @@ module Bigcommerce
18
18
  end
19
19
 
20
20
  def verify_peer=(verify)
21
- @configuration[:verify_peer] = verify
21
+ @configuration[:verify_ssl] = verify
22
22
  end
23
23
 
24
- def ca_file=(path)
25
- @configuration.ca_file = path
24
+ def ssl_ca_file=(path)
25
+ @configuration.ssl_ca_file = path
26
26
  end
27
27
 
28
- def get(path, options = {})
29
- request(:get, path, options)
28
+ def ssl_client_key=(path,passphrase=nil)
29
+ if passphrase.nil?
30
+ @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path))
31
+ else
32
+ @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path), passphrase)
33
+ end
30
34
  end
31
35
 
32
- def post(path, options = {})
33
- request(:post, path, options)
36
+ def ssl_client_cert=(path)
37
+ @configuration.client_cert = OpenSSL::X509::Certificate.new(File.read(path))
34
38
  end
35
39
 
36
- def put(path, options = {})
37
- request(:put, path, options)
40
+ def get(path, options = {}, headers = {})
41
+ request(:get, path, options, headers)
38
42
  end
39
43
 
40
- def delete(path, options = {})
41
- request(:delete, path, options)
44
+ def post(path, options = {}, headers = {})
45
+ request(:post, path, options, headers)
42
46
  end
43
47
 
44
- def request(method, path, options = {})
45
- body, params = options.values_at(:body, :params)
46
- headers = options[:headers] || {}
47
- url = @configuration[:store_url] + '/api/v2' + path
48
- param_string = hash_to_params(params) unless params.nil? || params.empty?
49
-
50
- unless (param_string.nil? || param_string.empty?)
51
- uri = URI.parse("#{url}?#{param_string}")
52
- else
53
- uri = URI.parse(url)
54
- end
55
-
56
- http = Net::HTTP.new(uri.host, uri.port)
57
- http.use_ssl = true
58
-
59
- if @configuration.has_key?(:verify_peer) && @configuration[:verify_peer]
60
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
61
- else
62
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
63
- end
64
-
65
- http.ca_file = @configuration[:ca_path] if @configuration.has_key?(:ca_path)
66
-
67
- request = case method
68
- when :get then
69
- Net::HTTP::Get.new(uri.request_uri)
70
- when :post then
71
- Net::HTTP::Post.new(uri.request_uri)
72
- when :put then
73
- Net::HTTP::Put.new(uri.request_uri)
74
- when :delete then
75
- Net::HTTP::Delete.new(uri.request_uri)
76
- end
77
-
78
- request.basic_auth(@configuration[:username], @configuration[:api_key])
79
- request.add_field 'Accept', 'application/json'
80
- request.add_field 'Content-Type', 'application/json'
81
- headers.each { |k,v| request.add_field(k, v) }
82
-
83
- response = http.request(request)
84
-
85
- return case response
86
- when Net::HTTPSuccess, Net::HTTPRedirection
87
- JSON.parse(response.body || "{}")
88
- else
89
- false
90
- end
48
+ def put(path, options = {}, headers = {})
49
+ request(:put, path, options, headers)
91
50
  end
92
51
 
93
- def hash_to_params(hash)
94
- return nil if hash.nil? || hash.empty?
95
-
96
- # convert the hash to URL params
97
- return hash.map {|pair| pair.join("=")}.join("&")
98
-
99
-
52
+ def delete(path, options = {}, headers = {})
53
+ request(:delete, path, options, headers)
100
54
  end
101
- end
102
-
103
-
104
- class HttpError < Exception
105
55
 
56
+ def request(method, path, options,headers={})
57
+ restclient = RestClient::Resource.new "#{@configuration[:store_url]}/api/v2#{path}.json", @configuration[:username], @configuration[:api_key]
58
+ if @configuration[:ssl_client_key] && @configuration[:ssl_client_cert] && @configuration[:ssl_ca_file]
59
+ restclient = RestClient::Resource.new(
60
+ "#{@configuration[:store_url]}/api/v2#{path}.json",
61
+ :username => @configuration[:username],
62
+ :password => @configuration[:api_key],
63
+ :ssl_client_cert => @configuration[:ssl_client_cert],
64
+ :ssl_client_key => @configuration[:ssl_client_key],
65
+ :ssl_ca_file => @configuration[:ssl_ca_file],
66
+ :verify_ssl => @configuration[:verify_ssl]
67
+ )
68
+ end
69
+ begin
70
+ response = case method
71
+ when :get then
72
+ restclient.get :params => options, :accept => :json, :content_type => :json
73
+ when :post then
74
+ restclient.post(options.to_json, :content_type => :json, :accept => :json)
75
+ when :put then
76
+ restclient.put(options.to_json, :content_type => :json, :accept => :json)
77
+ when :delete then
78
+ restclient.delete
79
+ end
80
+ JSON.parse response
81
+ rescue => e
82
+ {"error"=>"Nothing to parse. Possibly no data?"}.to_json
83
+ end
84
+ end
85
+
106
86
  end
107
87
  end
@@ -1,6 +1,6 @@
1
1
  module Bigcommerce
2
2
  major = 0
3
- minor = 0
4
- patch = 6
3
+ minor = 8
4
+ patch = 0
5
5
  VERSION = [major, minor, patch].join('.') unless defined? Bigcommerce::VERSION
6
6
  end
@@ -35,48 +35,48 @@ describe Bigcommerce::Api do
35
35
 
36
36
  describe "Orders" do
37
37
  it "retrieves an order by ID" do
38
- api.connection.should_receive(:get).once.with("/orders/100")
38
+ api.connection.should_receive(:get).once.with("/orders/100", {})
39
39
  api.get_order(100)
40
40
  end
41
41
 
42
42
  it "retrieves orders" do
43
- api.connection.should_receive(:get).once.with("/orders", :params => {})
43
+ api.connection.should_receive(:get).once.with("/orders", {})
44
44
  api.get_orders
45
45
  end
46
46
 
47
47
  it "retrieves orders with pagination" do
48
- api.connection.should_receive(:get).once.with("/orders", :params => {:page => 2})
48
+ api.connection.should_receive(:get).once.with("/orders", {:page => 2})
49
49
  api.get_orders(:page => 2)
50
50
  end
51
51
 
52
52
  it "retrieves orders with limit" do
53
- api.connection.should_receive(:get).once.with("/orders", :params => {:limit => 10})
53
+ api.connection.should_receive(:get).once.with("/orders", {:limit => 10})
54
54
  api.get_orders(:limit => 10)
55
55
  end
56
56
 
57
57
  it "retrieves orders with pagination and limit" do
58
- api.connection.should_receive(:get).once.with("/orders", :params => {:limit => 10, :page => 2})
58
+ api.connection.should_receive(:get).once.with("/orders", {:limit => 10, :page => 2})
59
59
  api.get_orders(:limit => 10, :page => 2)
60
60
  end
61
61
 
62
62
  it "converts from DateTime when retrieving orders by date" do
63
- api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created => CGI::escape(rfc2822_datetime)})
63
+ api.connection.should_receive(:get).once.with("/orders", {:min_date_created => CGI::escape(rfc2822_datetime)})
64
64
  api.get_orders_by_date(DateTime.parse('2012-03-13 12:45:26 GMT'))
65
65
  end
66
66
 
67
67
  it "converts from DateTime when retrieving orders by date with pagination" do
68
- api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created => CGI::escape(rfc2822_datetime), :page => 2})
68
+ api.connection.should_receive(:get).once.with("/orders", {:min_date_created => CGI::escape(rfc2822_datetime), :page => 2})
69
69
  api.get_orders_by_date(DateTime.parse('2012-03-13 12:45:26 GMT'), :page => 2)
70
70
  end
71
71
 
72
72
  it "converts from Date when retrieving orders by date" do
73
- api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created => CGI::escape(rfc2822_date)})
73
+ api.connection.should_receive(:get).once.with("/orders", {:min_date_created => CGI::escape(rfc2822_date)})
74
74
  api.get_orders_by_date(Date.parse("2012-03-12"))
75
75
  end
76
76
 
77
77
  it "converts from a datetime string when retrieving orders by date" do
78
- api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created=> CGI::escape(rfc2822_datetime)})
79
- api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created=> CGI::escape(rfc2822_date)})
78
+ api.connection.should_receive(:get).once.with("/orders", {:min_date_created=> CGI::escape(rfc2822_datetime)})
79
+ api.connection.should_receive(:get).once.with("/orders", {:min_date_created=> CGI::escape(rfc2822_date)})
80
80
 
81
81
  api.get_orders_by_date('2012-03-13 12:45:26 GMT')
82
82
  api.get_orders_by_date('2012-03-12')
@@ -84,29 +84,10 @@ describe Bigcommerce::Api do
84
84
 
85
85
  describe '#get_orders_modified_since' do
86
86
  it "retrieves orders modified since date-time" do
87
- api.connection.should_receive(:get).with('/orders', :headers => {'If-Modified-Since' => CGI::escape(rfc2822_datetime)})
87
+ api.connection.should_receive(:get).with('/orders', {}, {'If-Modified-Since' => CGI::escape(rfc2822_datetime)})
88
88
  api.get_orders_modified_since(DateTime.parse(rfc2822_datetime))
89
89
  end
90
90
  end
91
-
92
- describe "Products" do
93
- describe '#create_product' do
94
- before { attributes.stub(:to_xml).with(:root => 'product') { 'product_xml' } }
95
- let(:attributes) { stub(:attributes) }
96
- it "creates product with passed attributes" do
97
- api.connection.should_receive(:post).with('/products', :body => 'product_xml')
98
- api.create_product(attributes)
99
- end
100
- end
101
-
102
- describe '#update_product' do
103
- before { attributes.stub(:to_xml).with(:root => 'product') { 'product_xml' } }
104
- let(:attributes) { stub(:attributes) }
105
- it "updates product with passed attributes" do
106
- api.connection.should_receive(:put).with('/products/123', :body => 'product_xml')
107
- api.update_product(123, attributes)
108
- end
109
- end
110
- end
91
+
111
92
  end
112
93
  end
@@ -2,90 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples_for "request method accepting optional params and headers" do
4
4
  it "sends request with no params" do
5
- connection.should_receive(:request).once.with(http_method, path, {})
5
+ connection.should_receive(:request).once.with(http_method, path, {}, {})
6
6
  connection.send(http_method, path)
7
7
  end
8
8
 
9
9
  it "sends request with params" do
10
- connection.should_receive(:request).once.with(http_method, path, :params => {:page => 3})
11
- connection.send(http_method, path, :params => {:page => 3})
10
+ connection.should_receive(:request).once.with(http_method, path, {:page => 3}, {})
11
+ connection.send(http_method, path, {:page => 3})
12
12
  end
13
13
 
14
14
  it "sends request with headers" do
15
- connection.should_receive(:request).once.with(http_method, "/orders", :headers => {'Some-Header' => 'abc'})
16
- connection.send(http_method, path, :headers => {'Some-Header' => 'abc'})
15
+ connection.should_receive(:request).once.with(http_method, "/orders", {}, {'Some-Header' => 'abc'})
16
+ connection.send(http_method, path, {}, {'Some-Header' => 'abc'})
17
17
  end
18
- end
19
-
20
- describe Bigcommerce::Connection do
21
- before { FakeWeb.allow_net_connect = false }
22
- after { FakeWeb.clean_registry }
23
- subject(:connection) do
24
- Bigcommerce::Connection.new(
25
- :store_url => "https://store-12345.mybigcommerce.com",
26
- :username => "test",
27
- :api_key => "12345"
28
- )
29
- end
30
-
31
- [:get, :post, :put, :delete].each do |http_method|
32
- let(:path) { '/orders' }
33
- describe "##{http_method}" do
34
- eval "let(:http_method) { :#{http_method} }"
35
- it_behaves_like "request method accepting optional params and headers"
36
- end
37
-
38
- describe '#request' do
39
- context "when #{http_method.to_s.upcase} request" do
40
- before do
41
- http_class.stub(:new) { request }
42
- Net::HTTP.stub(:new) { stub.as_null_object }
43
- end
44
- let(:http_class) { eval "Net::HTTP::#{http_method.to_s.gsub(/^(.)/) { $1.upcase }}" }
45
- let(:args) { [http_method, path, options] }
46
- let(:body) { nil }
47
- let(:params) { {} }
48
- let(:headers) { {} }
49
- let(:options) { {:body => body, :params => params, :headers => headers}.reject { |k,v| v.nil? } }
50
- let(:request) { stub.as_null_object }
51
-
52
- it "requests path with API prefix" do
53
- http_class.should_receive(:new).with("/api/v2#{path}")
54
- connection.request(*args)
55
- end
56
-
57
- context "with querystring" do
58
- let(:params) { {:foo => 'bar'} }
59
-
60
- it "includes querystring" do
61
- http_class.should_receive(:new).with("/api/v2#{path}?foo=bar")
62
- connection.request(*args)
63
- end
64
- end
65
-
66
- context "with custom header" do
67
- let(:headers) { {'Some-Header' => 'abc'} }
68
-
69
- it "includes custom header" do
70
- request.should_receive(:add_field).with('Some-Header', 'abc')
71
- request.stub(:add_field) # ignoring other headers
72
- connection.request(*args)
73
- end
74
- end
75
- end
76
- end
77
- end
78
-
79
- describe "#hash_to_params" do
80
- # TODO: Consider using addressable gem; see <http://stackoverflow.com/a/803067/3528> for examples.
81
- it "converts flat hashes to query strings" do
82
- connection.hash_to_params({:a => 1, :b => 2}).should eql "a=1&b=2"
83
- end
84
- it "converts empty hashes to nil" do
85
- connection.hash_to_params({}).should be_nil
86
- end
87
- it "leaves nil as nil" do
88
- connection.hash_to_params(nil).should be_nil
89
- end
18
+
19
+ it "sends request with params and headers" do
20
+ connection.should_receive(:request).once.with(http_method, "/orders", {:page => 6}, {'Some-Header' => 'abc'})
21
+ connection.send(http_method, path, {:page => 6}, {'Some-Header' => 'abc'})
90
22
  end
91
23
  end
24
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigcommerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: ci_reporter
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -164,11 +180,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
180
  version: '0'
165
181
  requirements: []
166
182
  rubyforge_project:
167
- rubygems_version: 1.8.24
183
+ rubygems_version: 1.8.23
168
184
  signing_key:
169
185
  specification_version: 3
170
186
  summary: Enables Ruby applications to communicate with the Bigcommerce API
171
187
  test_files:
172
188
  - spec/models/api_spec.rb
173
189
  - spec/models/connection_spec.rb
174
- has_rdoc: false