bigcommerce 1.0.0.beta → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +98 -36
- data/bigcommerce.gemspec +11 -13
- data/lib/bigcommerce.rb +4 -33
- data/lib/bigcommerce/config.rb +14 -0
- data/lib/bigcommerce/connection.rb +24 -0
- data/lib/bigcommerce/exception.rb +25 -18
- data/lib/bigcommerce/request.rb +8 -9
- data/lib/bigcommerce/resource_actions.rb +11 -11
- data/lib/bigcommerce/resources/content/blog_post.rb +3 -5
- data/lib/bigcommerce/resources/content/blog_tag.rb +2 -3
- data/lib/bigcommerce/resources/content/redirect.rb +2 -2
- data/lib/bigcommerce/resources/customers/customer.rb +2 -2
- data/lib/bigcommerce/resources/customers/customer_address.rb +5 -5
- data/lib/bigcommerce/resources/customers/customer_group.rb +2 -2
- data/lib/bigcommerce/resources/geography/country.rb +4 -3
- data/lib/bigcommerce/resources/geography/state.rb +6 -5
- data/lib/bigcommerce/resources/marketing/banner.rb +21 -0
- data/lib/bigcommerce/resources/marketing/coupon.rb +2 -2
- data/lib/bigcommerce/resources/marketing/gift_certificates.rb +25 -0
- data/lib/bigcommerce/resources/orders/order.rb +46 -44
- data/lib/bigcommerce/resources/orders/order_coupon.rb +5 -5
- data/lib/bigcommerce/resources/orders/order_message.rb +8 -7
- data/lib/bigcommerce/resources/orders/order_product.rb +37 -36
- data/lib/bigcommerce/resources/orders/order_shipping_address.rb +24 -23
- data/lib/bigcommerce/resources/orders/order_status.rb +2 -1
- data/lib/bigcommerce/resources/orders/order_tax.rb +8 -7
- data/lib/bigcommerce/resources/orders/shipment.rb +11 -10
- data/lib/bigcommerce/resources/products/brand.rb +2 -2
- data/lib/bigcommerce/resources/products/bulk_pricing_rule.rb +6 -5
- data/lib/bigcommerce/resources/products/category.rb +2 -2
- data/lib/bigcommerce/resources/products/configurable_field.rb +6 -5
- data/lib/bigcommerce/resources/products/custom_field.rb +6 -5
- data/lib/bigcommerce/resources/products/google_product_search_mapping.rb +9 -8
- data/lib/bigcommerce/resources/products/option.rb +2 -2
- data/lib/bigcommerce/resources/products/option_set.rb +2 -2
- data/lib/bigcommerce/resources/products/option_set_option.rb +2 -1
- data/lib/bigcommerce/resources/products/option_value.rb +1 -0
- data/lib/bigcommerce/resources/products/product.rb +61 -61
- data/lib/bigcommerce/resources/products/product_image.rb +4 -4
- data/lib/bigcommerce/resources/products/product_option.rb +2 -1
- data/lib/bigcommerce/resources/products/product_review.rb +1 -5
- data/lib/bigcommerce/resources/products/product_rule.rb +4 -4
- data/lib/bigcommerce/resources/products/product_video.rb +4 -4
- data/lib/bigcommerce/resources/products/sku.rb +15 -9
- data/lib/bigcommerce/resources/shipping/shipping_method.rb +2 -1
- data/lib/bigcommerce/resources/store/store_information.rb +18 -14
- data/lib/bigcommerce/resources/system/time.rb +2 -2
- data/lib/bigcommerce/resources/tax/tax_class.rb +2 -1
- data/lib/bigcommerce/resources/webhooks/webhook.rb +2 -1
- data/lib/bigcommerce/subresource_actions.rb +14 -14
- data/lib/bigcommerce/version.rb +1 -1
- metadata +32 -165
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.rubocop.yml +0 -620
- data/.travis.yml +0 -15
- data/CHANGELOG.md +0 -11
- data/CONTRIBUTING.md +0 -119
- data/DEPENDENCIES.md +0 -7
- data/Gemfile +0 -15
- data/Guardfile +0 -22
- data/LICENSE +0 -20
- data/RELEASING.md +0 -64
- data/Rakefile +0 -13
- data/examples/README.md +0 -148
- data/examples/configuration/legacy_auth.rb +0 -12
- data/examples/configuration/oauth.rb +0 -9
- data/examples/content/blog_post.rb +0 -39
- data/examples/content/blog_tag.rb +0 -10
- data/examples/content/redirect.rb +0 -43
- data/examples/customers/customer.rb +0 -36
- data/examples/customers/customer_address.rb +0 -50
- data/examples/customers/customer_group.rb +0 -35
- data/examples/exception_handling.rb +0 -50
- data/examples/geography/country.rb +0 -16
- data/examples/geography/state.rb +0 -19
- data/examples/marketing/coupon.rb +0 -44
- data/examples/orders/order.rb +0 -53
- data/examples/orders/order_coupon.rb +0 -17
- data/examples/orders/order_message.rb +0 -17
- data/examples/orders/order_product.rb +0 -23
- data/examples/orders/order_shipping_address.rb +0 -23
- data/examples/orders/order_status.rb +0 -15
- data/examples/orders/order_tax.rb +0 -17
- data/examples/orders/shipment.rb +0 -57
- data/examples/payments/payment_method.rb +0 -10
- data/examples/products/brand.rb +0 -36
- data/examples/products/bulk_pricing_rule.rb +0 -47
- data/examples/products/category.rb +0 -37
- data/examples/products/configurable_field.rb +0 -29
- data/examples/products/custom_field.rb +0 -44
- data/examples/products/google_product_search_mapping.rb +0 -12
- data/examples/products/option.rb +0 -37
- data/examples/products/option_set.rb +0 -35
- data/examples/products/option_set_option.rb +0 -50
- data/examples/products/option_value.rb +0 -43
- data/examples/products/product.rb +0 -44
- data/examples/products/product_image.rb +0 -42
- data/examples/products/product_option.rb +0 -17
- data/examples/products/product_review.rb +0 -12
- data/examples/products/product_rule.rb +0 -54
- data/examples/products/product_video.rb +0 -45
- data/examples/products/sku.rb +0 -48
- data/examples/shipping/shipping_method.rb +0 -13
- data/examples/store/store_info.rb +0 -10
- data/examples/system/time.rb +0 -10
- data/examples/tax/tax_class.rb +0 -13
- data/examples/webhooks/webhook.rb +0 -29
- data/spec/bigcommerce/bigcommerce_spec.rb +0 -76
- data/spec/bigcommerce/unit/actions_spec.rb +0 -151
- data/spec/bigcommerce/unit/exception_spec.rb +0 -53
- data/spec/bigcommerce/unit/middleware/auth_spec.rb +0 -18
- data/spec/bigcommerce/unit/middleware/http_exception_spec.rb +0 -40
- data/spec/bigcommerce/unit/request_spec.rb +0 -180
- data/spec/bigcommerce/unit/resources/content/blog_post_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/content/blog_tag_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/content/redirect_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/customers/customer_address_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/customers/customer_group_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/customers/customer_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/geography/country_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/geography/state_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/marketing/coupon_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/orders/order_product_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/orders/order_shipping_address_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/orders/order_spec.rb +0 -13
- data/spec/bigcommerce/unit/resources/orders/shipment_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/payments/payment_method_spec.rb +0 -23
- data/spec/bigcommerce/unit/resources/products/brand_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/bulk_pricing_rule_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/category_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/configurable_field_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/custom_field_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/google_product_search_mapping_spec.rb +0 -14
- data/spec/bigcommerce/unit/resources/products/option_set_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/option_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/products/product_image_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/product_review_spec.rb +0 -14
- data/spec/bigcommerce/unit/resources/products/product_rule_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/product_spec.rb +0 -13
- data/spec/bigcommerce/unit/resources/products/product_video_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/products/sku_spec.rb +0 -21
- data/spec/bigcommerce/unit/resources/resource_spec.rb +0 -4
- data/spec/bigcommerce/unit/resources/store_info/store_information_spec.rb +0 -12
- data/spec/bigcommerce/unit/resources/system/time_spec.rb +0 -12
- data/spec/bigcommerce/unit/version_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -11
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce do
|
4
|
-
let(:middleware) do
|
5
|
-
api.instance_variable_get('@builder').instance_variable_get('@handlers')
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should return a faraday object when configured' do
|
9
|
-
Bigcommerce.configure do |config|
|
10
|
-
config.url = 'http://foobar.com'
|
11
|
-
config.auth = 'legacy'
|
12
|
-
config.api_key = '214789175'
|
13
|
-
config.username = 'admin'
|
14
|
-
end
|
15
|
-
expect(Bigcommerce.api).to be_a_kind_of(Faraday::Connection)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.build_connection' do
|
19
|
-
context 'when using legacy' do
|
20
|
-
let(:api) do
|
21
|
-
Bigcommerce.configure do |config|
|
22
|
-
config.url = 'http://foobar.com'
|
23
|
-
config.auth = 'legacy'
|
24
|
-
config.api_key = '214789175'
|
25
|
-
config.username = 'admin'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should have the correct auth middleware' do
|
30
|
-
expect(middleware).to include(Faraday::Request::BasicAuthentication)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when not using legacy' do
|
35
|
-
let(:api) do
|
36
|
-
Bigcommerce.configure do |config|
|
37
|
-
config.access_token = 'jksdgkjbhksjdb'
|
38
|
-
config.client_id = 'negskjgdjkbg'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should have the correct auth middleware' do
|
43
|
-
expect(middleware).to include(Bigcommerce::Middleware::Auth)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'multiple configurations' do
|
49
|
-
it 'should use the configuration for the most recently defined' do
|
50
|
-
Bigcommerce.configure do |config|
|
51
|
-
config.access_token = 'jksdgkjbhksjdb'
|
52
|
-
config.client_id = 'negskjgdjkbg'
|
53
|
-
end
|
54
|
-
|
55
|
-
Bigcommerce.configure do |config|
|
56
|
-
config.url = 'http://foobar.com'
|
57
|
-
config.auth = 'legacy'
|
58
|
-
config.api_key = '214789175'
|
59
|
-
config.username = 'admin'
|
60
|
-
end
|
61
|
-
|
62
|
-
expect(Bigcommerce.api.instance_variable_get('@builder')
|
63
|
-
.instance_variable_get('@handlers'))
|
64
|
-
.to include(Faraday::Request::BasicAuthentication)
|
65
|
-
|
66
|
-
Bigcommerce.configure do |config|
|
67
|
-
config.access_token = 'jksdgkjbhksjdb'
|
68
|
-
config.client_id = 'negskjgdjkbg'
|
69
|
-
end
|
70
|
-
|
71
|
-
expect(Bigcommerce.api.instance_variable_get('@builder')
|
72
|
-
.instance_variable_get('@handlers'))
|
73
|
-
.to include(Bigcommerce::Middleware::Auth)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce::ResourceActions do
|
4
|
-
before do
|
5
|
-
module Bigcommerce
|
6
|
-
class DummyClass
|
7
|
-
include ResourceActions.new(uri: 'http://foo.bar/%d')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
@klass = Bigcommerce::DummyClass
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:params) do
|
14
|
-
{ page: 1 }
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should have options' do
|
18
|
-
mod = Bigcommerce::ResourceActions.new(
|
19
|
-
uri: 'http://foo.bar',
|
20
|
-
disable: [:find,:all]
|
21
|
-
)
|
22
|
-
options = {
|
23
|
-
uri: 'http://foo.bar',
|
24
|
-
disable: [:find,:all]
|
25
|
-
}
|
26
|
-
expect(mod._options).to eq options
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '.all' do
|
30
|
-
it 'should make a get request to the correct route with query params' do
|
31
|
-
expect(@klass).to receive(:get).with('http://foo.bar', page: 1)
|
32
|
-
@klass.all(params)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should make a get request to the correct route' do
|
36
|
-
expect(@klass).to receive(:get).with('http://foo.bar', {})
|
37
|
-
params.delete(:params)
|
38
|
-
@klass.all
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.find' do
|
43
|
-
it 'should make a get request to the correct route' do
|
44
|
-
expect(@klass).to receive(:get).with('http://foo.bar/1')
|
45
|
-
@klass.find(1)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '.create' do
|
50
|
-
it 'should make a post request to the correct route with params' do
|
51
|
-
expect(@klass).to receive(:post).with('http://foo.bar', page: 1)
|
52
|
-
@klass.create(params)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '.update' do
|
57
|
-
it 'should make a put request to the correct route with params' do
|
58
|
-
expect(@klass).to receive(:put).with('http://foo.bar/1', page: 1)
|
59
|
-
@klass.update(1, params)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '.destroy' do
|
64
|
-
it 'should make a delete request to the correct route with params' do
|
65
|
-
expect(@klass).to receive(:delete).with('http://foo.bar/1')
|
66
|
-
@klass.destroy(1)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '.destroy_all' do
|
71
|
-
it 'should make a delete request to the correct route with params' do
|
72
|
-
expect(@klass).to receive(:delete).with('http://foo.bar')
|
73
|
-
@klass.destroy_all
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe Bigcommerce::SubresourceActions do
|
79
|
-
before do
|
80
|
-
module Bigcommerce
|
81
|
-
class DummyClass
|
82
|
-
include SubresourceActions.new(uri: 'http://foo.bar/%d/%d')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
@klass = Bigcommerce::DummyClass
|
86
|
-
end
|
87
|
-
|
88
|
-
let(:params) do
|
89
|
-
{ page: 1 }
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'should have options' do
|
93
|
-
mod = Bigcommerce::SubresourceActions.new(
|
94
|
-
uri: 'http://foo.bar',
|
95
|
-
disable: [:find,:all]
|
96
|
-
)
|
97
|
-
options = {
|
98
|
-
uri: 'http://foo.bar',
|
99
|
-
disable: [:find,:all]
|
100
|
-
}
|
101
|
-
expect(mod._options).to eq options
|
102
|
-
end
|
103
|
-
|
104
|
-
describe '.all' do
|
105
|
-
it 'should make a get request to the correct route with query params' do
|
106
|
-
expect(@klass).to receive(:get).with('http://foo.bar/1', page: 1)
|
107
|
-
@klass.all(1, params)
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should make a get request to the correct route' do
|
111
|
-
expect(@klass).to receive(:get).with('http://foo.bar/1', {})
|
112
|
-
params.delete(:params)
|
113
|
-
@klass.all(1)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '.find' do
|
118
|
-
it 'should make a get request to the correct route' do
|
119
|
-
expect(@klass).to receive(:get).with('http://foo.bar/1/2')
|
120
|
-
@klass.find(1,2)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe '.create' do
|
125
|
-
it 'should make a post request to the correct route with params' do
|
126
|
-
expect(@klass).to receive(:post).with('http://foo.bar/1', page: 1)
|
127
|
-
@klass.create(1, params)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe '.update' do
|
132
|
-
it 'should make a put request to the correct route with params' do
|
133
|
-
expect(@klass).to receive(:put).with('http://foo.bar/1/2', page: 1)
|
134
|
-
@klass.update(1, 2, params)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe '.destroy' do
|
139
|
-
it 'should make a delete request to the correct route with params' do
|
140
|
-
expect(@klass).to receive(:delete).with('http://foo.bar/1/2')
|
141
|
-
@klass.destroy(1, 2)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe '.destroy_all' do
|
146
|
-
it 'should make a delete request to the correct route with params' do
|
147
|
-
expect(@klass).to receive(:delete).with('http://foo.bar/1')
|
148
|
-
@klass.destroy_all(1)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce::HttpErrors do
|
4
|
-
let(:dummy_class) { Class.new { extend Bigcommerce::HttpErrors } }
|
5
|
-
|
6
|
-
it '::ERRORS is not nil' do
|
7
|
-
expect(Bigcommerce::HttpErrors::ERRORS).not_to be_nil
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'invalid response status' do
|
11
|
-
it 'should throw an exception' do
|
12
|
-
code = 404
|
13
|
-
expect { dummy_class.throw_http_exception!(code) }.to raise_exception
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should have a valid error' do
|
17
|
-
codes = Bigcommerce::HttpErrors::ERRORS.keys
|
18
|
-
codes.each do |code|
|
19
|
-
expect { dummy_class.throw_http_exception!(code) }.to raise_exception
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should allow you to pass in an error message when throwing exception' do
|
24
|
-
code = 404
|
25
|
-
env = double
|
26
|
-
allow(env).to receive(:body) { {} }
|
27
|
-
allow(env).to receive(:[]) { {} }
|
28
|
-
expect do
|
29
|
-
dummy_class.throw_http_exception!(code, env)
|
30
|
-
end.to raise_exception(Bigcommerce::HttpErrors::ERRORS[code])
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should parse out a retry-after header if present' do
|
34
|
-
code = 429
|
35
|
-
env = double
|
36
|
-
allow(env).to receive(:body) { "{\"time\":1426184190}" }
|
37
|
-
allow(env).to receive(:[]).with(:response_headers).and_return('X-Retry-After' => 1)
|
38
|
-
begin
|
39
|
-
dummy_class.throw_http_exception!(code, env)
|
40
|
-
rescue Bigcommerce::TooManyRequests => e
|
41
|
-
expect(e.response_headers[:retry_after]).to eq 1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'valid response status' do
|
47
|
-
it 'should not throw an exception' do
|
48
|
-
code = 200
|
49
|
-
env = double
|
50
|
-
expect { dummy_class.throw_http_exception!(code, env) }.to_not raise_exception
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce::Middleware::Auth do
|
4
|
-
it 'should set the correct headers' do
|
5
|
-
app = double
|
6
|
-
options = {
|
7
|
-
client_id: 'client_id',
|
8
|
-
access_token: 'access_token'
|
9
|
-
}
|
10
|
-
@api = Bigcommerce::Middleware::Auth.new(app, options)
|
11
|
-
expect(app).to receive(:call).with(
|
12
|
-
request_headers: {
|
13
|
-
'X-Auth-Client' => 'client_id',
|
14
|
-
'X-Auth-Token' => 'access_token'
|
15
|
-
})
|
16
|
-
@api.call(request_headers: {})
|
17
|
-
end
|
18
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce::Middleware::HttpException do
|
4
|
-
before(:each) { @e = Bigcommerce::Middleware::HttpException.new }
|
5
|
-
|
6
|
-
it 'should check for an error on all responses' do
|
7
|
-
env = {
|
8
|
-
status: '200',
|
9
|
-
body: 'Valid'
|
10
|
-
}
|
11
|
-
expect(@e).to receive(:throw_http_exception!).with(200, env)
|
12
|
-
@e.on_complete env
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when valid response' do
|
16
|
-
let(:env) do
|
17
|
-
{
|
18
|
-
status: '200',
|
19
|
-
body: 'Valid'
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should return its argument if no errors' do
|
24
|
-
expect(@e.on_complete(env)).to eq env
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when invalid response' do
|
29
|
-
let(:env) do
|
30
|
-
{
|
31
|
-
status: '404',
|
32
|
-
body: 'Error'
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should throw an exception' do
|
37
|
-
expect { @e.on_complete(env) }.to raise_exception
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bigcommerce::Request do
|
4
|
-
before do
|
5
|
-
module Bigcommerce
|
6
|
-
class DummyClass
|
7
|
-
include Request.new 'foo/%d'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
@klass = Bigcommerce::DummyClass
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '.path' do
|
14
|
-
it 'should have a path method to expose the path_builder' do
|
15
|
-
expect(@klass.path).to be_kind_of Bigcommerce::PathBuilder
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'ClassMethods' do
|
20
|
-
before do
|
21
|
-
double Bigcommerce.api
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:json) { "{\"body\":[{\"time\":1426184190},{\"time\":1426184190}]}" }
|
25
|
-
|
26
|
-
describe '.get' do
|
27
|
-
it 'should call raw_request and build_response_object' do
|
28
|
-
allow(@klass).to receive(:raw_request) { json }
|
29
|
-
expect(@klass).to receive(:raw_request).with(:get, @klass.path, {})
|
30
|
-
expect(@klass).to receive(:build_response_object).with(json)
|
31
|
-
@klass.get(@klass.path, {})
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '.delete' do
|
36
|
-
it 'should call raw_request' do
|
37
|
-
response = double
|
38
|
-
allow(response).to receive(:body) { '' }
|
39
|
-
allow(@klass).to receive(:raw_request) { response }
|
40
|
-
expect(@klass).to receive(:raw_request).with(:delete, @klass.path)
|
41
|
-
@klass.delete(@klass.path)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '.post' do
|
46
|
-
it 'should call raw_request and build_response_object' do
|
47
|
-
allow(@klass).to receive(:raw_request) { json }
|
48
|
-
expect(@klass).to receive(:raw_request).with(:post, @klass.path, {})
|
49
|
-
expect(@klass).to receive(:build_response_object).with(json)
|
50
|
-
@klass.post(@klass.path, {})
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '.put' do
|
55
|
-
it 'should call raw_request and build_response_object' do
|
56
|
-
allow(@klass).to receive(:raw_request) { json }
|
57
|
-
expect(@klass).to receive(:raw_request).with(:put, @klass.path, {})
|
58
|
-
expect(@klass).to receive(:build_response_object).with(json)
|
59
|
-
@klass.put(@klass.path, {})
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '.raw_request' do
|
64
|
-
before do
|
65
|
-
Bigcommerce.configure do |config|
|
66
|
-
config.client_id = 'sdbgksjbg4'
|
67
|
-
config.access_token = 'jkdgbdsgbg'
|
68
|
-
config.store_hash = 'sdgjnsdjg'
|
69
|
-
end
|
70
|
-
@api = Bigcommerce.api
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'send its method to Bigcommerce.api' do
|
74
|
-
response = double
|
75
|
-
allow(@api).to receive(:get) { response }
|
76
|
-
allow(response).to receive(:headers) { '' }
|
77
|
-
expect(@api).to receive(:get).with('path/1', nil)
|
78
|
-
expect(response).to receive(:headers)
|
79
|
-
@klass.raw_request(:get, 'path/1')
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe 'private methods' do
|
84
|
-
describe '.build_response_object' do
|
85
|
-
before do
|
86
|
-
module Bigcommerce
|
87
|
-
class DummyClass
|
88
|
-
include Request.new 'foo/%d'
|
89
|
-
def initialize(params)
|
90
|
-
@params = params
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
@klass_with_init = Bigcommerce::DummyClass
|
95
|
-
end
|
96
|
-
|
97
|
-
describe 'json array' do
|
98
|
-
let(:json) { "[{\"time\":1426184190},{\"time\":1426184190}]" }
|
99
|
-
|
100
|
-
it 'should build an array of objects' do
|
101
|
-
response = double
|
102
|
-
allow(response).to receive(:body) { json }
|
103
|
-
objs = @klass_with_init.send(:build_response_object, response)
|
104
|
-
expect(objs).to be_kind_of Array
|
105
|
-
objs.each do |obj|
|
106
|
-
expect(obj).to be_kind_of Bigcommerce::DummyClass
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
describe 'json object' do
|
111
|
-
let(:json) { "{\"time\":1426184190}" }
|
112
|
-
it 'should build an object' do
|
113
|
-
response = double
|
114
|
-
allow(response).to receive(:body) { json }
|
115
|
-
objs = @klass_with_init.send(:build_response_object, response)
|
116
|
-
expect(objs).to be_kind_of Bigcommerce::DummyClass
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '.parse' do
|
122
|
-
describe 'empty string' do
|
123
|
-
let(:json) { "" }
|
124
|
-
|
125
|
-
it 'should return an array' do
|
126
|
-
expect(@klass.send(:parse, json)).to be_kind_of Array
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe 'valid json' do
|
131
|
-
let(:json) { "{\"time\":1426184190}" }
|
132
|
-
|
133
|
-
it 'should symbolize keys' do
|
134
|
-
expect(@klass.send(:parse, json)).to eq({time:1426184190})
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'should return a hash' do
|
138
|
-
expect(@klass.send(:parse, json)).to be_kind_of Hash
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe Bigcommerce::PathBuilder do
|
147
|
-
let(:uri) { 'bar/%d' }
|
148
|
-
before do
|
149
|
-
@path_builder = Bigcommerce::PathBuilder.new uri
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '.to_s' do
|
153
|
-
it 'should return uri' do
|
154
|
-
expect(@path_builder.to_s).to eq uri
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe '.build' do
|
159
|
-
context 'hash of keys' do
|
160
|
-
let(:keys) { 1 }
|
161
|
-
it 'should build a formed path' do
|
162
|
-
expect(@path_builder.build keys).to eq 'bar/1'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context 'integer keys' do
|
167
|
-
let(:keys) { 1 }
|
168
|
-
it 'should build a formed path' do
|
169
|
-
expect(@path_builder.build keys).to eq 'bar/1'
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'integer keys' do
|
174
|
-
let(:keys) { nil }
|
175
|
-
it 'should build a formed path' do
|
176
|
-
expect(@path_builder.build keys).to eq 'bar'
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|