bigcommerce 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bigcommerce.gemspec +2 -1
- data/lib/big_commerce.rb +1 -2
- data/lib/bigcommerce/api.rb +10 -3
- data/lib/bigcommerce/version.rb +1 -1
- data/spec/integration/orders_spec.rb +18 -0
- data/spec/spec_helper.rb +13 -1
- data/spec/support/integration_context.rb +13 -0
- data/spec/support/mock_api_context.rb +10 -0
- data/spec/unit/api_request_spec.rb +34 -0
- data/spec/{models → unit}/connection_spec.rb +0 -0
- data/spec/unit/date_time_spec.rb +31 -0
- metadata +34 -12
- data/spec/models/api_spec.rb +0 -93
- data/spec/support/fixture_helpers.rb +0 -9
data/bigcommerce.gemspec
CHANGED
@@ -6,7 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.add_dependency('json')
|
7
7
|
s.add_dependency('rest-client')
|
8
8
|
s.add_development_dependency("ci_reporter")
|
9
|
-
s.add_development_dependency("
|
9
|
+
s.add_development_dependency("vcr")
|
10
|
+
s.add_development_dependency("webmock", '1.9')
|
10
11
|
s.add_development_dependency("mocha")
|
11
12
|
s.add_development_dependency("rake")
|
12
13
|
s.add_development_dependency("rspec", '~> 2.11')
|
data/lib/big_commerce.rb
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
require 'bigcommerce'
|
1
|
+
raise "'big_commerce' (BigCommerce::Api) is no longer supported. Please require 'bigcommerce' (Bigcommerce::Api)"
|
data/lib/bigcommerce/api.rb
CHANGED
@@ -177,12 +177,11 @@ module Bigcommerce
|
|
177
177
|
if date.is_a?(String)
|
178
178
|
date = DateTime.parse(date)
|
179
179
|
end
|
180
|
-
|
181
|
-
@connection.get('/orders', options.merge!(:min_date_created => CGI::escape(date)))
|
180
|
+
@connection.get('/orders', options.merge!(:min_date_created => to_rfc2822(date)))
|
182
181
|
end
|
183
182
|
|
184
183
|
def get_orders_modified_since(date)
|
185
|
-
@connection.get('/orders', {}, {'If-Modified-Since' =>
|
184
|
+
@connection.get('/orders', {}, {'If-Modified-Since' => to_rfc2822(date)})
|
186
185
|
end
|
187
186
|
|
188
187
|
def get_order(id)
|
@@ -281,6 +280,14 @@ module Bigcommerce
|
|
281
280
|
@connection.get("/products/#{product_id}/customfields/#{custom_field_id}", {})
|
282
281
|
end
|
283
282
|
|
283
|
+
def get_product_images(product_id, options={})
|
284
|
+
@connection.get("/products/#{product_id}/images", options)
|
285
|
+
end
|
286
|
+
|
287
|
+
def create_product_images(product_id, options={})
|
288
|
+
@connection.post("/products/#{product_id}/images", options)
|
289
|
+
end
|
290
|
+
|
284
291
|
def get_products_images(options={})
|
285
292
|
@connection.get("/products/images", options)
|
286
293
|
end
|
data/lib/bigcommerce/version.rb
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
require 'bigcommerce'
|
2
2
|
require 'date'
|
3
|
-
require '
|
3
|
+
require 'vcr'
|
4
|
+
require 'webmock/rspec'
|
4
5
|
|
5
6
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
6
7
|
# in spec/support/ and its subdirectories.
|
7
8
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }
|
8
9
|
|
10
|
+
VCR.configure do |c|
|
11
|
+
c.cassette_library_dir = 'spec/fixtures'
|
12
|
+
c.hook_into :webmock
|
13
|
+
c.configure_rspec_metadata!
|
14
|
+
c.filter_sensitive_data('<API_USER>') { ENV['API_USER'] }
|
15
|
+
c.filter_sensitive_data('<API_PASS>') { ENV['API_PASS'] }
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |c|
|
19
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
20
|
+
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,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
|
File without changes
|
@@ -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
|
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.8.
|
4
|
+
version: 0.8.2
|
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-04-
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: vcr
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - '='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.9'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - '='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.9'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: mocha
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,12 +170,17 @@ files:
|
|
154
170
|
- ./lib/bigcommerce/connection.rb
|
155
171
|
- ./lib/bigcommerce/version.rb
|
156
172
|
- ./lib/bigcommerce.rb
|
157
|
-
- ./spec/
|
158
|
-
- ./spec/models/connection_spec.rb
|
173
|
+
- ./spec/integration/orders_spec.rb
|
159
174
|
- ./spec/spec_helper.rb
|
160
|
-
- ./spec/support/
|
161
|
-
- spec/
|
162
|
-
- spec/
|
175
|
+
- ./spec/support/integration_context.rb
|
176
|
+
- ./spec/support/mock_api_context.rb
|
177
|
+
- ./spec/unit/api_request_spec.rb
|
178
|
+
- ./spec/unit/connection_spec.rb
|
179
|
+
- ./spec/unit/date_time_spec.rb
|
180
|
+
- spec/integration/orders_spec.rb
|
181
|
+
- spec/unit/api_request_spec.rb
|
182
|
+
- spec/unit/connection_spec.rb
|
183
|
+
- spec/unit/date_time_spec.rb
|
163
184
|
homepage: http://github.com/bigcommerce/bigcommerce-api-ruby
|
164
185
|
licenses: []
|
165
186
|
post_install_message:
|
@@ -180,11 +201,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
201
|
version: '0'
|
181
202
|
requirements: []
|
182
203
|
rubyforge_project:
|
183
|
-
rubygems_version: 1.8.
|
204
|
+
rubygems_version: 1.8.23
|
184
205
|
signing_key:
|
185
206
|
specification_version: 3
|
186
207
|
summary: Enables Ruby applications to communicate with the Bigcommerce API
|
187
208
|
test_files:
|
188
|
-
- spec/
|
189
|
-
- spec/
|
190
|
-
|
209
|
+
- spec/integration/orders_spec.rb
|
210
|
+
- spec/unit/api_request_spec.rb
|
211
|
+
- spec/unit/connection_spec.rb
|
212
|
+
- spec/unit/date_time_spec.rb
|
data/spec/models/api_spec.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce::Api do
|
4
|
-
before do
|
5
|
-
FakeWeb.allow_net_connect = false
|
6
|
-
FakeWeb.register_uri(:get, %r|https://test:12345@store-12345.mybigcommerce.com/api/v2/orders|, :body => load_json_fixture('order'), :status => 200, :content_type => "text/json")
|
7
|
-
FakeWeb.register_uri(:get, %r|https://test:12345@store-12345.mybigcommerce.com/api/v2/time|, :body => load_json_fixture('time'), :status => 200, :content_type => "text/json")
|
8
|
-
end
|
9
|
-
after do
|
10
|
-
FakeWeb.clean_registry
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:api) do
|
14
|
-
Bigcommerce::Api.new({
|
15
|
-
:store_url => "https://store-12345.mybigcommerce.com",
|
16
|
-
:username => "test", :api_key => "12345"
|
17
|
-
})
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:rfc2822_datetime) { "Tue, 13 Mar 2012 12:45:26 +0000" }
|
21
|
-
let(:rfc2822_date) { "Mon, 12 Mar 2012 00:00:00 +0000" }
|
22
|
-
|
23
|
-
describe "Time" do
|
24
|
-
it "converts times to RFC 2822 format" do
|
25
|
-
api.to_rfc2822(DateTime.parse('2012-03-13 12:45:26 +0000')).should eql rfc2822_datetime
|
26
|
-
end
|
27
|
-
it "converts dates to RFC 2822 format" do
|
28
|
-
api.to_rfc2822(DateTime.parse('2012-03-12 00:00:00 +0000')).should eql rfc2822_date
|
29
|
-
end
|
30
|
-
it "retrieves the current time from the store" do
|
31
|
-
api.connection.should_receive(:get).once.with("/time")
|
32
|
-
api.get_time
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "Orders" do
|
37
|
-
it "retrieves an order by ID" do
|
38
|
-
api.connection.should_receive(:get).once.with("/orders/100", {})
|
39
|
-
api.get_order(100)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "retrieves orders" do
|
43
|
-
api.connection.should_receive(:get).once.with("/orders", {})
|
44
|
-
api.get_orders
|
45
|
-
end
|
46
|
-
|
47
|
-
it "retrieves orders with pagination" do
|
48
|
-
api.connection.should_receive(:get).once.with("/orders", {:page => 2})
|
49
|
-
api.get_orders(:page => 2)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "retrieves orders with limit" do
|
53
|
-
api.connection.should_receive(:get).once.with("/orders", {:limit => 10})
|
54
|
-
api.get_orders(:limit => 10)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "retrieves orders with pagination and limit" do
|
58
|
-
api.connection.should_receive(:get).once.with("/orders", {:limit => 10, :page => 2})
|
59
|
-
api.get_orders(:limit => 10, :page => 2)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "converts from DateTime when retrieving orders by date" do
|
63
|
-
api.connection.should_receive(:get).once.with("/orders", {:min_date_created => CGI::escape(rfc2822_datetime)})
|
64
|
-
api.get_orders_by_date(DateTime.parse('2012-03-13 12:45:26 GMT'))
|
65
|
-
end
|
66
|
-
|
67
|
-
it "converts from DateTime when retrieving orders by date with pagination" do
|
68
|
-
api.connection.should_receive(:get).once.with("/orders", {:min_date_created => CGI::escape(rfc2822_datetime), :page => 2})
|
69
|
-
api.get_orders_by_date(DateTime.parse('2012-03-13 12:45:26 GMT'), :page => 2)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "converts from Date when retrieving orders by date" do
|
73
|
-
api.connection.should_receive(:get).once.with("/orders", {:min_date_created => CGI::escape(rfc2822_date)})
|
74
|
-
api.get_orders_by_date(Date.parse("2012-03-12"))
|
75
|
-
end
|
76
|
-
|
77
|
-
it "converts from a datetime string when retrieving orders by date" do
|
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
|
-
|
81
|
-
api.get_orders_by_date('2012-03-13 12:45:26 GMT')
|
82
|
-
api.get_orders_by_date('2012-03-12')
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#get_orders_modified_since' do
|
86
|
-
it "retrieves orders modified since date-time" do
|
87
|
-
api.connection.should_receive(:get).with('/orders', {}, {'If-Modified-Since' => CGI::escape(rfc2822_datetime)})
|
88
|
-
api.get_orders_modified_since(DateTime.parse(rfc2822_datetime))
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|