bigcommerce-test 0.8.42

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) Bigcommerce, 2011.
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
@@ -0,0 +1,130 @@
1
+ Bigcommerce API V2 - Ruby Client
2
+ ================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/bigcommerce.png)](https://rubygems.org/gems/bigcommerce)
5
+ [![Build Status](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby.png?branch=master)](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby)
6
+ [![Dependency Status](https://gemnasium.com/bigcommerce/bigcommerce-api-ruby.png?travis)](https://gemnasium.com/bigcommerce/bigcommerce-api-ruby)
7
+ [![Code Climate](https://codeclimate.com/github/bigcommerce/bigcommerce-api-ruby.png)](https://codeclimate.com/github/bigcommerce/bigcommerce-api-ruby)
8
+ [![Coverage Status](https://coveralls.io/repos/bigcommerce/bigcommerce-api-ruby/badge.png?branch=master)](https://coveralls.io/r/bigcommerce/bigcommerce-api-ruby?branch=master)
9
+
10
+ This library provides a wrapper around the Bigcommerce REST API for use within
11
+ Ruby apps or via the console.
12
+
13
+ Note
14
+ ----
15
+ If you find anything that is missing or needs clean up, please feel free to fork
16
+ it and submit a changes with your pull request.
17
+
18
+ Requirements
19
+ ------------
20
+
21
+ - Ruby 1.9+
22
+
23
+ To connect to the API, you need the following credentials:
24
+
25
+ - Secure URL pointing to a Bigcommerce store
26
+ - Username of an authorized admin user of the store
27
+ - API key for the user
28
+
29
+ A valid API key is required to authenticate requests. To grant API access for a
30
+ user, go to Control Panel > Users > Edit User and make sure that the
31
+ 'Enable API access?' checkbox is ticked.
32
+
33
+ Installation
34
+ ------------
35
+
36
+ Download the lib folder and copy it to a path accessible within your app, or
37
+ install the package directly from Rubygems:
38
+
39
+ ```
40
+ gem install bigcommerce
41
+ ```
42
+
43
+ Note that the RubyGems version of this gem might be outdated. You can install the
44
+ gem directly from this repo. If you are using Rails, you can point your Gemfile
45
+ to this git repo directly or do a local install of the gem by -
46
+
47
+ ```
48
+ rake build
49
+ gem install pkg/bigcommerce-*.gem
50
+ ```
51
+
52
+ Configuration
53
+ -------------
54
+
55
+ To use the API client in your Ruby code, provide the required credentials as
56
+ follows:
57
+
58
+ ```
59
+ require 'bigcommerce'
60
+
61
+ api = Bigcommerce::Api.new({
62
+ :store_url => "https://store.mybigcommerce.com",
63
+ :username => "admin",
64
+ :api_key => "d81aada4c19c34d913e18f07fd7f36ca"
65
+ })
66
+ ```
67
+
68
+ If you want to enable SSL certificates -
69
+
70
+ ```
71
+ require 'bigcommerce'
72
+ api = Bigcommerce::Api.new({
73
+ :store_url => "https://store.mybigcommerce.com",
74
+ :username => "admin",
75
+ :api_key => "d81aada4c19c34d913e18f07fd7f36ca"
76
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
77
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
78
+ :ssl_ca_file => "ca_certificate.pem",
79
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
80
+ })
81
+ ```
82
+ Remember that the fields `:ssl_client_cert`, `:ssl_client_key`, `:ssl_ca_file`
83
+ and `:verify_ssl` are all required when enabling SSL certificates.
84
+
85
+ Connecting to the store
86
+ -----------------------
87
+
88
+ Ping the get_time method to check that your configuration is working and you
89
+ can connect successfully to the store:
90
+
91
+ ```
92
+ ping = api.get_time
93
+ ```
94
+
95
+ Usage
96
+ -----
97
+
98
+ The API object acts as a gateway to all top level resources in the V2 API.
99
+
100
+ Fetch Data
101
+ ```
102
+ orders = api.get_orders
103
+ orders = api.get_orders({:min_id=>100,:max_id=>101})
104
+ orders = api.get_orders(:is_deleted => true)
105
+
106
+ products = api.get_products
107
+ products = api.get_products(:description=>"iphone", :condition=>"New")
108
+
109
+ options = api.get_options
110
+ options = api.get_options(:type=>"MT")
111
+ ...
112
+
113
+ ```
114
+ Create Data
115
+ ```
116
+ api.create_products({:name => "Spiderman - The best return",:price => 9.99,:categories => [17],:type =>"physical",:availability => "available", :weight => 1})
117
+
118
+ api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
119
+
120
+ api.update_orders(101,{:status_id => 12, :is_deleted => true})
121
+
122
+ ```
123
+ Update Data
124
+
125
+ ```
126
+ api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
127
+
128
+ api.update_optionsets(13,{:name => "Marvel toys"})
129
+
130
+ ```
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'ci/reporter/rake/rspec'
3
+ require 'rspec/core/rake_task'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = 'spec/**/*_spec.rb'
9
+ end
10
+
11
+ task :default => ['ci:setup:rspec', :spec]
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bigcommerce_test/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ if RUBY_VERSION < '1.9'
6
+ s.add_dependency('activesupport', '< 4.0')
7
+ else
8
+ s.add_dependency('activesupport')
9
+ end
10
+ s.add_dependency('json')
11
+ s.add_dependency('rest-client')
12
+ if RUBY_VERSION >= '1.9'
13
+ s.add_development_dependency("coveralls")
14
+ end
15
+ s.add_development_dependency("ci_reporter")
16
+ s.add_development_dependency("mocha")
17
+ s.add_development_dependency("rake")
18
+ s.add_development_dependency("rspec", '~> 2.11')
19
+ s.add_development_dependency("vcr")
20
+ s.add_development_dependency("webmock", '1.9')
21
+ s.authors = ["Mark Rickerby", "Rob Howard", "Saranyan Vigraham", "Sasha Gerrand"]
22
+ s.date = Time.now.strftime("%Y-%m-%d")
23
+ s.description = "Test Version of the Bigcommerce API lib - Please use the official version for your purposes"
24
+ s.email = ["mark.rickerby@bigcommerce.com",
25
+ "rob.howard@bigcommerce.com",
26
+ "saranyan.vigraham@bigcommerce.com",
27
+ "sasha.gerrand@bigcommerce.com"]
28
+ s.files = ["LICENSE", "Rakefile", "README.md", "bigcommerce.gemspec"] + Dir['./**/*.rb'] + Dir['./**/*.crt']
29
+ s.has_rdoc = false
30
+ s.homepage = "http://github.com/saranyan/bigcommerce-api-ruby"
31
+ s.name = "bigcommerce-test"
32
+ s.summary = "Enables Ruby applications to communicate with the Bigcommerce API"
33
+ s.test_files = Dir.glob('spec/**/*_spec.rb')
34
+ s.version = BigcommerceTest::VERSION
35
+ end
@@ -0,0 +1 @@
1
+ raise "'big_commerce' (BigCommerce::Api) is no longer supported. Please require 'bigcommerce' (Bigcommerce::Api)"
@@ -0,0 +1,7 @@
1
+ require "cgi"
2
+ require "json"
3
+ require 'rest-client'
4
+ require "uri"
5
+ require 'bigcommerce_test/api'
6
+ require 'bigcommerce_test/connection'
7
+ require 'bigcommerce_test/version'
@@ -0,0 +1,458 @@
1
+ module BigcommerceTest
2
+ class Api
3
+
4
+ def initialize(configuration={})
5
+ @connection = Connection.new(configuration)
6
+ end
7
+
8
+ def connection
9
+ @connection
10
+ end
11
+
12
+ def store_url=(store_url)
13
+ @connection.store_url = store_url
14
+ end
15
+
16
+ def username=(username)
17
+ @connection.username = username
18
+ end
19
+
20
+ def api_key=(api_key)
21
+ @connection.api_key = api_key
22
+ end
23
+
24
+ def verify_ssl=(verify)
25
+ @connection.verify_ssl = verify
26
+ end
27
+
28
+ def ca_file=(path)
29
+ @connection.ca_file = path
30
+ end
31
+
32
+ def to_rfc2822(datetime)
33
+ datetime.strftime("%a, %d %b %Y %H:%M:%S %z")
34
+ end
35
+
36
+ def get_time
37
+ @connection.get '/time'
38
+ end
39
+
40
+ def get_brands(options={})
41
+ @connection.get("/brands", options)
42
+ end
43
+
44
+ def get_brands_count
45
+ @connection.get '/brands/count'
46
+ end
47
+
48
+ def get_brand(id)
49
+ @connection.get("/brands/#{id}", {})
50
+ end
51
+
52
+ def create_brands(options={})
53
+ @connection.post("/brands", options)
54
+ end
55
+
56
+ def update_brand(id, options={})
57
+ @connection.put("/brands/#{id}", options)
58
+ end
59
+
60
+ def delete_brand(id)
61
+ @connection.delete("/brands/#{id}")
62
+ end
63
+
64
+ def delete_brands()
65
+ @connection.delete("/brands")
66
+ end
67
+
68
+ def get_coupons(options={})
69
+ @connection.get("/coupons", options)
70
+ end
71
+
72
+ def create_coupons(options={})
73
+ @connection.post("/coupons", options)
74
+ end
75
+
76
+ def update_coupon(id, options={})
77
+ @connection.put("/coupons/#{id}", options)
78
+ end
79
+
80
+ def get_categories(options={})
81
+ @connection.get("/categories", options)
82
+ end
83
+
84
+ def get_categories_count
85
+ @connection.get '/categories/count'
86
+ end
87
+
88
+ def get_category(id)
89
+ @connection.get("/categories/#{id}", {})
90
+ end
91
+
92
+ def create_categories(options={})
93
+ @connection.post("/categories", options)
94
+ end
95
+
96
+ def update_category(id, options={})
97
+ @connection.put("/categories/#{id}", options)
98
+ end
99
+
100
+ def delete_category(id)
101
+ @connection.delete("/categories/#{id}")
102
+ end
103
+
104
+ def delete_categories()
105
+ @connection.delete("/categories")
106
+ end
107
+
108
+ def get_countries(options={})
109
+ @connection.get("/countries", options)
110
+ end
111
+
112
+ def get_country(id)
113
+ @connection.get("/countries/#{id}", {})
114
+ end
115
+
116
+ def get_countries_states(options={})
117
+ @connection.get("/countries/states", options)
118
+ end
119
+
120
+ def get_countries_state(id, options={})
121
+ @connection.get("/countries/#{id}/states", {})
122
+ end
123
+
124
+ def get_customers(options = {})
125
+ @connection.get("/customers", options)
126
+ end
127
+
128
+ def get_customer(id)
129
+ @connection.get('/customers/' + id.to_s, {})
130
+ end
131
+
132
+ def get_customer_addresses(id, options = {})
133
+ @connection.get("/customers/#{id}/addresses", options)
134
+ end
135
+
136
+ def get_customer_address(customer_id, address_id)
137
+ @connection.get("/customers/#{customer_id}/addresses/#{address_id}",{})
138
+ end
139
+
140
+ def get_options(options={})
141
+ @connection.get("/options", options)
142
+ end
143
+
144
+ def get_options_count
145
+ @connection.get '/options/count'
146
+ end
147
+
148
+ def get_option(id)
149
+ @connection.get("/options/#{id}",{})
150
+ end
151
+
152
+ def create_option(options={})
153
+ @connection.post("/options", options)
154
+ end
155
+
156
+ def update_option(id, options={})
157
+ @connection.put("/options/#{id}", options)
158
+ end
159
+
160
+ def delete_option(id)
161
+ @connection.delete("/options/#{id}")
162
+ end
163
+
164
+ def get_options_values(options={})
165
+ @connection.get("/options/values", options)
166
+ end
167
+
168
+ def get_options_value(id)
169
+ @connection.get("/options/#{id}/values",{})
170
+ end
171
+
172
+ def create_options_values(options_id, options={})
173
+ @connection.post("/options/#{options_id}/values", options)
174
+ end
175
+
176
+ def update_options_value(options_id, values_id, options={})
177
+ @connection.put("/options/#{options_id}/values/#{values_id}", options)
178
+ end
179
+
180
+ def get_optionsets(options={})
181
+ @connection.get("/optionsets", options)
182
+ end
183
+
184
+ def get_optionsets_count
185
+ @connection.get '/optionsets/count'
186
+ end
187
+
188
+ def get_optionset(id)
189
+ @connection.get("/optionsets/#{id}", {})
190
+ end
191
+
192
+ def create_optionset(options={})
193
+ @connection.post("/optionsets", options)
194
+ end
195
+
196
+ def update_optionset(id, options={})
197
+ @connection.put("/optionsets/#{id}", options)
198
+ end
199
+
200
+ def delete_optionset(id)
201
+ @connection.delete("/optionsets/#{id}")
202
+ end
203
+
204
+ def get_optionsets_options(options={})
205
+ @connection.get("/optionsets/options", options)
206
+ end
207
+
208
+ def get_optionset_options(id)
209
+ @connection.get("/optionsets/#{id}/options", {})
210
+ end
211
+
212
+ def get_optionsets_option(id)
213
+ @connection.get("/optionsets/options/#{id}", {})
214
+ end
215
+
216
+ def create_optionset_option(id, options={})
217
+ @connection.post("/optionsets/#{id}/options", options)
218
+ end
219
+
220
+ def update_optionset_option(optionset_id, option_id, options={})
221
+ @connection.put("/optionsets/#{optionset_id}/options/#{option_id}", options)
222
+ end
223
+
224
+ def get_orders(options={})
225
+ @connection.get("/orders", options)
226
+ end
227
+
228
+ def get_orders_by_date(date, options={})
229
+ if date.is_a?(String)
230
+ date = DateTime.parse(date)
231
+ end
232
+ @connection.get('/orders', options.merge!(:min_date_created => to_rfc2822(date)))
233
+ end
234
+
235
+ def get_orders_modified_since(date)
236
+ @connection.get('/orders', {}, {'If-Modified-Since' => to_rfc2822(date)})
237
+ end
238
+
239
+ def get_order(id)
240
+ @connection.get("/orders/#{id}", {})
241
+ end
242
+
243
+ def update_order(id,options={})
244
+ @connection.put("/orders/#{id}", options)
245
+ end
246
+
247
+ def get_orders_coupons(id)
248
+ @connection.get("/orders/#{id}/coupons", {})
249
+ end
250
+
251
+ def get_orders_coupon(order_id,coupon_id)
252
+ @connection.get("/orders/#{order_id}/coupons/#{coupon_id}", {})
253
+ end
254
+
255
+ def get_orders_products(id)
256
+ @connection.get("/orders/#{id}/products", {})
257
+ end
258
+
259
+ def get_orders_product(order_id,product_id)
260
+ @connection.get("/orders/#{order_id}/products/#{product_id}", {})
261
+ end
262
+
263
+ def get_orders_shipments(id)
264
+ @connection.get("/orders/#{id}/shipments", {})
265
+ end
266
+
267
+ def create_orders_shipments(id)
268
+ @connection.post("/orders/#{id}/shipments", {})
269
+ end
270
+
271
+ def get_orders_shipment(order_id,shipment_id)
272
+ @connection.get("/orders/#{order_id}/shipments/#{shipment_id}", {})
273
+ end
274
+
275
+ def update_orders_shipment(order_id,shipment_id,options={})
276
+ @connection.put("/orders/#{order_id}/shipments/#{shipment_id}", options)
277
+ end
278
+
279
+ def get_orders_shippingaddresses(id)
280
+ @connection.get("/orders/#{id}/shippingaddresses", {})
281
+ end
282
+
283
+ def get_orders_shippingaddress(order_id,shippingaddress_id)
284
+ @connection.get("/orders/#{order_id}/shippingaddresses/#{shippingaddress_id}", {})
285
+ end
286
+
287
+ def get_orderstatuses(options={})
288
+ @connection.get("/orderstatuses", options)
289
+ end
290
+
291
+ def get_orderstatus(id)
292
+ @connection.get("/orderstatuses/#{id}", {})
293
+ end
294
+
295
+ def get_products(options={})
296
+ @connection.get("/products", options)
297
+ end
298
+
299
+ def get_products_count
300
+ @connection.get '/products/count'
301
+ end
302
+
303
+ def get_product(id)
304
+ @connection.get("/products/#{id}", {})
305
+ end
306
+
307
+ def create_products(options={})
308
+ @connection.post('/products', options)
309
+ end
310
+
311
+ def update_products(id, options={})
312
+ @connection.put("/products/#{id}", options)
313
+ end
314
+
315
+ def delete_products()
316
+ @connection.delete("/products")
317
+ end
318
+
319
+ def get_products_discountrules(options={})
320
+ @connection.get("/products/discountrules", options)
321
+ end
322
+
323
+ def get_product_discountrules(product_id, options={})
324
+ @connection.get("/products/#{product_id}/discountrules", options)
325
+ end
326
+
327
+ def get_products_discountrule(product_id, discountrule_id)
328
+ @connection.get("/products/#{product_id}/discountrules/#{discountrule_id}", {})
329
+ end
330
+
331
+ def get_products_configurablefields(options={})
332
+ @connection.get("/products/configurablefields", options)
333
+ end
334
+
335
+ def get_product_configurablefields(product_id, options={})
336
+ @connection.get("/products/#{product_id}/configurablefields", options)
337
+ end
338
+
339
+ def get_products_configurablefield(product_id, configurable_field_id)
340
+ @connection.get("/products/#{product_id}/configurablefields/#{configurable_field_id}", {})
341
+ end
342
+
343
+ def get_products_customfields(options={})
344
+ @connection.get("/products/customfields", options)
345
+ end
346
+
347
+ def get_product_customfields(product_id, options={})
348
+ @connection.get("/products/#{product_id}/customfields", options)
349
+ end
350
+
351
+ def get_products_customfield(product_id, custom_field_id)
352
+ @connection.get("/products/#{product_id}/customfields/#{custom_field_id}", {})
353
+ end
354
+
355
+ def get_product_images(product_id, options={})
356
+ @connection.get("/products/#{product_id}/images", options)
357
+ end
358
+
359
+ def create_product_images(product_id, options={})
360
+ @connection.post("/products/#{product_id}/images", options)
361
+ end
362
+
363
+ def get_products_images(options={})
364
+ @connection.get("/products/images", options)
365
+ end
366
+
367
+ def create_products_images(options={})
368
+ @connection.post("/products/images", options)
369
+ end
370
+
371
+ def get_products_image(product_id, image_id)
372
+ @connection.get("/products/#{product_id}/images/#{image_id}", {})
373
+ end
374
+
375
+ def update_products_image(product_id,image_id,options={})
376
+ @connection.put("/products/#{product_id}/images/#{image_id}", options)
377
+ end
378
+
379
+ def get_products_customfields(options={})
380
+ @connection.get("/products/options", options)
381
+ end
382
+
383
+ def get_product_options(product_id, options={})
384
+ @connection.get("/products/#{product_id}/options", options)
385
+ end
386
+
387
+ def get_products_option(product_id,option_id)
388
+ @connection.get("/products/#{product_id}/options/#{option_id}", {})
389
+ end
390
+
391
+ def get_products_rules(options={})
392
+ @connection.get("/products/rules", options)
393
+ end
394
+
395
+ def get_product_rules(product_id, options={})
396
+ @connection.get("/products/#{product_id}/rules", options)
397
+ end
398
+
399
+ def create_products_rules(options={})
400
+ @connection.post("/products/rules", options)
401
+ end
402
+
403
+ def get_products_rule(product_id,rule_id)
404
+ @connection.get("/products/#{product_id}/rules/#{rule_id}", {})
405
+ end
406
+
407
+ def update_products_rule(product_id, rule_id, options={})
408
+ @connection.put("/products/#{product_id}/rules/#{rule_id}", options)
409
+ end
410
+
411
+ def get_products_skus(options={})
412
+ @connection.get("/products/skus", options)
413
+ end
414
+
415
+ def get_product_skus(product_id, options={})
416
+ @connection.get("/products/#{product_id}/skus", options)
417
+ end
418
+
419
+ def create_products_skus(options={})
420
+ @connection.post("/products/skus", options)
421
+ end
422
+
423
+ def get_products_sku(product_id, sku_id)
424
+ @connection.get("/products/#{product_id}/skus/#{sku_id}", {})
425
+ end
426
+
427
+ def update_products_sku(product_id, sku_id, options={})
428
+ @connection.put("/products/#{product_id}/skus/#{sku_id}", options)
429
+ end
430
+
431
+ def get_products_videos(options={})
432
+ @connection.get("/products/videos", options)
433
+ end
434
+
435
+ def get_product_videos(product_id, options={})
436
+ @connection.get("/products/#{product_id}/videos", options)
437
+ end
438
+
439
+ def get_products_video(product_id, video_id)
440
+ @connection.get("/products/#{product_id}/videos/#{video_id}", {})
441
+ end
442
+
443
+ private
444
+
445
+ def get_count(result)
446
+ result["count"]
447
+ end
448
+
449
+ def get_resource(result)
450
+ result
451
+ end
452
+
453
+ def get_collection(result)
454
+ result
455
+ end
456
+
457
+ end
458
+ end
@@ -0,0 +1,99 @@
1
+ module BigcommerceTest
2
+ class Connection
3
+
4
+ def initialize(configuration)
5
+ @configuration = {}
6
+ configuration.each do |key, val|
7
+ send(key.to_s + "=", val)
8
+ end
9
+ end
10
+
11
+ def configuration
12
+ @configuration
13
+ end
14
+
15
+ def store_url=(store_url)
16
+ url = URI.parse(store_url)
17
+ @configuration[:store_url] = url.scheme + "://" + url.host
18
+ end
19
+
20
+ def username=(username)
21
+ @configuration[:username] = username
22
+ end
23
+
24
+ def api_key=(api_key)
25
+ @configuration[:api_key] = api_key
26
+ end
27
+
28
+ def verify_peer=(verify)
29
+ @configuration[:verify_ssl] = verify
30
+ end
31
+
32
+ def ssl_ca_file=(path)
33
+ @configuration.ssl_ca_file = path
34
+ end
35
+
36
+ def ssl_client_key=(path,passphrase=nil)
37
+ if passphrase.nil?
38
+ @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path))
39
+ else
40
+ @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path), passphrase)
41
+ end
42
+ end
43
+
44
+ def ssl_client_cert=(path)
45
+ @configuration.client_cert = OpenSSL::X509::Certificate.new(File.read(path))
46
+ end
47
+
48
+ def get(path, options = {}, headers = {})
49
+ request(:get, path, options, headers)
50
+ end
51
+
52
+ def post(path, options = {}, headers = {})
53
+ request(:post, path, options, headers)
54
+ end
55
+
56
+ def put(path, options = {}, headers = {})
57
+ request(:put, path, options, headers)
58
+ end
59
+
60
+ def delete(path, options = {}, headers = {})
61
+ request(:delete, path, options, headers)
62
+ end
63
+
64
+ def request(method, path, options,headers={})
65
+ restclient = RestClient::Resource.new "#{@configuration[:store_url]}/api/v2#{path}.json", @configuration[:username], @configuration[:api_key]
66
+ if @configuration[:ssl_client_key] && @configuration[:ssl_client_cert] && @configuration[:ssl_ca_file]
67
+ restclient = RestClient::Resource.new(
68
+ "#{@configuration[:store_url]}/api/v2#{path}.json",
69
+ :username => @configuration[:username],
70
+ :password => @configuration[:api_key],
71
+ :ssl_client_cert => @configuration[:ssl_client_cert],
72
+ :ssl_client_key => @configuration[:ssl_client_key],
73
+ :ssl_ca_file => @configuration[:ssl_ca_file],
74
+ :verify_ssl => @configuration[:verify_ssl]
75
+ )
76
+ end
77
+ begin
78
+ response = case method
79
+ when :get then
80
+ restclient.get :params => options, :accept => :json, :content_type => :json
81
+ when :post then
82
+ restclient.post(options.to_json, :content_type => :json, :accept => :json)
83
+ when :put then
84
+ restclient.put(options.to_json, :content_type => :json, :accept => :json)
85
+ when :delete then
86
+ restclient.delete
87
+ end
88
+ if((200..201) === response.code)
89
+ JSON.parse response
90
+ elsif response.code == 204
91
+ nil
92
+ end
93
+ rescue => e
94
+ raise "Failed to parse Bigcommerce response: #{e}"
95
+ end
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,6 @@
1
+ module BigcommerceTest
2
+ major = 0
3
+ minor = 8
4
+ patch = 42
5
+ VERSION = [major, minor, patch].join('.') unless defined? BigcommerceTest::VERSION
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "BigCommerce" do
4
+ describe "require 'big_commerce'" do
5
+ it "should raise exception when required" do
6
+ lambda { (require 'big_commerce').should raise(RuntimeError) }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "/api/v2/orders" do
4
+ include_context "integration"
5
+
6
+ it "gets the orders collection", :vcr do
7
+ orders = api.get_orders
8
+ orders.should be_a_kind_of(Enumerable)
9
+ orders.size.should be > 0
10
+ end
11
+
12
+ it "filters orders by date", :vcr do
13
+ orders = api.get_orders_by_date('2013-03-01')
14
+ orders.should be_a_kind_of(Enumerable)
15
+ orders.size.should be > 0
16
+ end
17
+
18
+ end
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ rescue LoadError => e
5
+ raise e unless RUBY_VERSION < '1.9'
6
+ end
7
+
8
+ require 'bigcommerce'
9
+ require 'date'
10
+ require 'vcr'
11
+ require 'webmock/rspec'
12
+
13
+ # Requires supporting ruby files with custom matchers and macros, etc,
14
+ # in spec/support/ and its subdirectories.
15
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }
16
+
17
+ VCR.configure do |c|
18
+ c.cassette_library_dir = 'spec/fixtures'
19
+ c.hook_into :webmock
20
+ c.configure_rspec_metadata!
21
+ c.filter_sensitive_data('<API_USER>') { ENV['API_USER'] }
22
+ c.filter_sensitive_data('<API_PASS>') { ENV['API_PASS'] }
23
+ end
24
+
25
+ RSpec.configure do |c|
26
+ c.treat_symbols_as_metadata_keys_with_true_values = true
27
+ end
@@ -0,0 +1,13 @@
1
+ shared_context "integration" do
2
+ let :api do
3
+ ENV['API_URL'] = ENV['API_URL'] || 'https://store-vnh06c71.mybigcommerce.com'
4
+ ENV['API_USER'] = ENV['API_USER'] || 'apiuser'
5
+ ENV['API_PASS'] = ENV['API_PASS'] || '123456'
6
+
7
+ Bigcommerce::Api.new({
8
+ :store_url => ENV['API_URL'],
9
+ :username => ENV['API_USER'],
10
+ :api_key => ENV['API_PASS']
11
+ })
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ shared_context "mock api" do
2
+ let :api do
3
+ connection = double(Bigcommerce::Connection)
4
+ api = Bigcommerce::Api.new
5
+ api.instance_eval do
6
+ @connection = connection
7
+ end
8
+ api
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ describe "API request delegation" do
2
+ include_context "mock api"
3
+
4
+ it "requests a resource" do
5
+ api.connection.should_receive(:get).once.with("/time")
6
+ api.get_time
7
+ end
8
+
9
+ it "requests a resource by id" do
10
+ api.connection.should_receive(:get).once.with("/products/333", {})
11
+ api.get_product(333)
12
+ end
13
+
14
+ it "requests a compound resource by ids" do
15
+ api.connection.should_receive(:get).once.with("/orders/999/products/333", {})
16
+ api.get_orders_product(999, 333)
17
+ end
18
+
19
+ it "requests a resource with pagination" do
20
+ api.connection.should_receive(:get).once.with("/orders", {:page => 2})
21
+ api.get_orders(:page => 2)
22
+ end
23
+
24
+ it "requests a resource with limit" do
25
+ api.connection.should_receive(:get).once.with("/categories", {:limit => 10})
26
+ api.get_categories(:limit => 10)
27
+ end
28
+
29
+ it "request a resource with pagination and limit" do
30
+ api.connection.should_receive(:get).once.with("/customers", {:limit => 10, :page => 2})
31
+ api.get_customers(:limit => 10, :page => 2)
32
+ end
33
+
34
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "request method accepting optional params and headers" do
4
+ it "sends request with no params" do
5
+ connection.should_receive(:request).once.with(http_method, path, {}, {})
6
+ connection.send(http_method, path)
7
+ end
8
+
9
+ it "sends request with params" do
10
+ connection.should_receive(:request).once.with(http_method, path, {:page => 3}, {})
11
+ connection.send(http_method, path, {:page => 3})
12
+ end
13
+
14
+ it "sends request with headers" do
15
+ connection.should_receive(:request).once.with(http_method, "/orders", {}, {'Some-Header' => 'abc'})
16
+ connection.send(http_method, path, {}, {'Some-Header' => 'abc'})
17
+ 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'})
22
+ end
23
+ end
24
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bigcommerce::Api do
4
+
5
+ let(:api) do
6
+ Bigcommerce::Api.new({
7
+ :store_url => "https://store-12345.mybigcommerce.com",
8
+ :username => "test", :api_key => "12345"
9
+ })
10
+ end
11
+
12
+ let(:rfc2822_datetime) { "Tue, 13 Mar 2012 12:45:26 +0000" }
13
+ let(:rfc2822_date) { "Mon, 12 Mar 2012 00:00:00 +0000" }
14
+
15
+ describe "RFC 2822 DateTime format" do
16
+
17
+ it "converts raw date times to RFC 2822 format" do
18
+ api.to_rfc2822(DateTime.parse('2012-03-13 12:45:26 +0000')).should eql rfc2822_datetime
19
+ end
20
+
21
+ it "converts textual date times to RFC 2822 format" do
22
+ api.to_rfc2822(DateTime.parse('12th March 2012')).should eql rfc2822_date
23
+ end
24
+
25
+ it "converts ISO 8601 dates to RFC 2822 format" do
26
+ api.to_rfc2822(DateTime.parse('2012-03-12')).should eql rfc2822_date
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bigcommerce do
4
+ describe 'VERSION' do
5
+ it "should have a version number set" do
6
+ expect(Bigcommerce::VERSION).to_not be_nil
7
+ end
8
+
9
+ it "should use a semantic version format" do
10
+ expect(Bigcommerce::VERSION).to match(/\d+\.\d+\.\d+(rc\d?)?/)
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigcommerce-test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.42
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Rickerby
9
+ - Rob Howard
10
+ - Saranyan Vigraham
11
+ - Sasha Gerrand
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2013-09-02 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: activesupport
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rest-client
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ - !ruby/object:Gem::Dependency
66
+ name: coveralls
67
+ requirement: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: ci_reporter
83
+ requirement: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake
115
+ requirement: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: rspec
131
+ requirement: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ~>
135
+ - !ruby/object:Gem::Version
136
+ version: '2.11'
137
+ type: :development
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ~>
143
+ - !ruby/object:Gem::Version
144
+ version: '2.11'
145
+ - !ruby/object:Gem::Dependency
146
+ name: vcr
147
+ requirement: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ - !ruby/object:Gem::Dependency
162
+ name: webmock
163
+ requirement: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - '='
167
+ - !ruby/object:Gem::Version
168
+ version: '1.9'
169
+ type: :development
170
+ prerelease: false
171
+ version_requirements: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - '='
175
+ - !ruby/object:Gem::Version
176
+ version: '1.9'
177
+ description: Test Version of the Bigcommerce API lib - Please use the official version
178
+ for your purposes
179
+ email:
180
+ - mark.rickerby@bigcommerce.com
181
+ - rob.howard@bigcommerce.com
182
+ - saranyan.vigraham@bigcommerce.com
183
+ - sasha.gerrand@bigcommerce.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - LICENSE
189
+ - Rakefile
190
+ - README.md
191
+ - bigcommerce.gemspec
192
+ - ./lib/big_commerce.rb
193
+ - ./lib/bigcommerce_test/api.rb
194
+ - ./lib/bigcommerce_test/connection.rb
195
+ - ./lib/bigcommerce_test/version.rb
196
+ - ./lib/bigcommerce_test.rb
197
+ - ./spec/big_commerce_spec.rb
198
+ - ./spec/integration/orders_spec.rb
199
+ - ./spec/spec_helper.rb
200
+ - ./spec/support/integration_context.rb
201
+ - ./spec/support/mock_api_context.rb
202
+ - ./spec/unit/api_request_spec.rb
203
+ - ./spec/unit/connection_spec.rb
204
+ - ./spec/unit/date_time_spec.rb
205
+ - ./spec/unit/version_spec.rb
206
+ - spec/big_commerce_spec.rb
207
+ - spec/integration/orders_spec.rb
208
+ - spec/unit/api_request_spec.rb
209
+ - spec/unit/connection_spec.rb
210
+ - spec/unit/date_time_spec.rb
211
+ - spec/unit/version_spec.rb
212
+ homepage: http://github.com/saranyan/bigcommerce-api-ruby
213
+ licenses: []
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ requirements: []
231
+ rubyforge_project:
232
+ rubygems_version: 1.8.24
233
+ signing_key:
234
+ specification_version: 3
235
+ summary: Enables Ruby applications to communicate with the Bigcommerce API
236
+ test_files:
237
+ - spec/big_commerce_spec.rb
238
+ - spec/integration/orders_spec.rb
239
+ - spec/unit/api_request_spec.rb
240
+ - spec/unit/connection_spec.rb
241
+ - spec/unit/date_time_spec.rb
242
+ - spec/unit/version_spec.rb