mad_cart 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +2 -1
- data/lib/mad_cart/store/base.rb +38 -0
- data/lib/mad_cart/store/big_commerce.rb +2 -33
- data/lib/mad_cart/store/spree.rb +1 -31
- data/lib/mad_cart/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/big_commerce_server_error.yml +43 -0
- data/spec/lib/store/big_commerce_spec.rb +18 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ecdd2f48e981f110c690f70ab25a4beeb069391
|
4
|
+
data.tar.gz: 36ce1a0fa9c93679bf16a4622ca2ddf7b2e8c99e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1b7a5593c7080e3b411292a8b19bdc6764ba239ec92d9e280b972df679b521ac85648c2350caa8a19fd534c97e8742faf04f2122a021eb73018279d521d2d94
|
7
|
+
data.tar.gz: f02165a862e4312a9f3b3b48d4bd66d6e0d659a6f7656b135ce7e94e8b5f6767af75f83b02ed8d0cbfab34ebf1ad85c2ec7eee954812955515b7cd346cbb7d2b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## 0.1.2 (7 June 2016)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- New `MadCart::Store::UnavailableStore` error raised when there is a (possibly) temporary problem with the connection to the Store's API.
|
6
|
+
|
7
|
+
Refactor:
|
8
|
+
|
9
|
+
- Removed duplication between the different stores in terms of how responses and connections are handled.
|
10
|
+
|
11
|
+
## 0.1.1
|
12
|
+
|
13
|
+
Initial release
|
data/README.md
CHANGED
@@ -114,7 +114,8 @@ MadCart throws several types of exceptions:
|
|
114
114
|
```ruby
|
115
115
|
MadCart::Store::ServerError #=> when Store's API returns server error response (status code: 500).
|
116
116
|
MadCart::Store::InvalidCredentials #=> when Store's API returns unauthorized response (status code: 401).
|
117
|
-
MadCart::Store::InvalidStore #=> when there is a problem
|
117
|
+
MadCart::Store::InvalidStore #=> when there is a problem reaching the Store's API.
|
118
|
+
MadCart::Store::UnavailableStore #=> when there is a possibly temporary problem with the connection to the Store's API.
|
118
119
|
```
|
119
120
|
|
120
121
|
## Contributing
|
data/lib/mad_cart/store/base.rb
CHANGED
@@ -13,6 +13,7 @@ module MadCart
|
|
13
13
|
InvalidStore = Class.new(StandardError)
|
14
14
|
ServerError = Class.new(StandardError)
|
15
15
|
InvalidCredentials = Class.new(StandardError)
|
16
|
+
UnavailableStore = Class.new(StandardError)
|
16
17
|
|
17
18
|
module Base
|
18
19
|
DEFAULT_CONNECTION_OPTIONS = {
|
@@ -42,6 +43,43 @@ module MadCart
|
|
42
43
|
@connection ||= execute_delegate(klass.connection_delegate, @init_args)
|
43
44
|
end
|
44
45
|
|
46
|
+
def valid_by_path?(path)
|
47
|
+
check_for_errors do
|
48
|
+
connection.get(path)
|
49
|
+
end
|
50
|
+
true
|
51
|
+
rescue InvalidCredentials, InvalidStore, ServerError, UnavailableStore
|
52
|
+
false
|
53
|
+
end
|
54
|
+
private :valid_by_path?
|
55
|
+
|
56
|
+
def parse_response(&block)
|
57
|
+
response = check_for_errors &block
|
58
|
+
empty_body?(response) ? [] : response.body
|
59
|
+
end
|
60
|
+
private :parse_response
|
61
|
+
|
62
|
+
def check_for_errors(&block)
|
63
|
+
response = yield
|
64
|
+
|
65
|
+
case response.status
|
66
|
+
when 401
|
67
|
+
raise InvalidCredentials
|
68
|
+
when 500
|
69
|
+
raise ServerError
|
70
|
+
end
|
71
|
+
|
72
|
+
response
|
73
|
+
rescue Faraday::Error::ConnectionFailed, Faraday::ParsingError, Faraday::SSLError
|
74
|
+
raise UnavailableStore
|
75
|
+
end
|
76
|
+
private :check_for_errors
|
77
|
+
|
78
|
+
def empty_body?(response)
|
79
|
+
response.status == 204 || response.body.nil?
|
80
|
+
end
|
81
|
+
private :empty_body?
|
82
|
+
|
45
83
|
def klass
|
46
84
|
self.class
|
47
85
|
end
|
@@ -9,13 +9,7 @@ module MadCart
|
|
9
9
|
fetch :store, :with => :get_store
|
10
10
|
|
11
11
|
def valid?
|
12
|
-
|
13
|
-
connection.get('time.json')
|
14
|
-
end
|
15
|
-
return true
|
16
|
-
|
17
|
-
rescue InvalidCredentials => e
|
18
|
-
return false
|
12
|
+
valid_by_path?('time.json')
|
19
13
|
end
|
20
14
|
|
21
15
|
def products_count
|
@@ -59,7 +53,7 @@ module MadCart
|
|
59
53
|
def get_customer_hashes
|
60
54
|
result = []
|
61
55
|
loop(:make_customer_request) {|c| result << c }
|
62
|
-
|
56
|
+
result
|
63
57
|
end
|
64
58
|
|
65
59
|
def loop(source, &block)
|
@@ -78,35 +72,10 @@ module MadCart
|
|
78
72
|
parse_response { connection.get('store.json') }
|
79
73
|
end
|
80
74
|
|
81
|
-
def parse_response(&block)
|
82
|
-
response = check_for_errors &block
|
83
|
-
return [] if empty_body?(response)
|
84
|
-
return response.body
|
85
|
-
end
|
86
|
-
|
87
|
-
def check_for_errors(&block)
|
88
|
-
response = yield
|
89
|
-
|
90
|
-
case response.status
|
91
|
-
when 401
|
92
|
-
raise InvalidCredentials
|
93
|
-
when 500
|
94
|
-
raise ServerError
|
95
|
-
end
|
96
|
-
|
97
|
-
response
|
98
|
-
rescue Faraday::Error::ConnectionFailed => e
|
99
|
-
raise InvalidStore
|
100
|
-
end
|
101
|
-
|
102
75
|
def api_url_for(store_domain)
|
103
76
|
"https://#{store_domain}/api/v2/"
|
104
77
|
end
|
105
78
|
|
106
|
-
def empty_body?(response)
|
107
|
-
true if response.status == 204 || response.body.nil?
|
108
|
-
end
|
109
|
-
|
110
79
|
def create_connection(args={})
|
111
80
|
Faraday.new(DEFAULT_CONNECTION_OPTIONS.merge(:url => api_url_for(args[:store_url]))) do |connection|
|
112
81
|
connection.basic_auth(args[:username], args[:api_key])
|
data/lib/mad_cart/store/spree.rb
CHANGED
@@ -11,12 +11,7 @@ module MadCart
|
|
11
11
|
fetch :products, :with => :get_products
|
12
12
|
|
13
13
|
def valid?
|
14
|
-
|
15
|
-
connection.get('orders.json')
|
16
|
-
end
|
17
|
-
return true
|
18
|
-
rescue InvalidCredentials => e
|
19
|
-
return false
|
14
|
+
valid_by_path?('orders.json')
|
20
15
|
end
|
21
16
|
|
22
17
|
def products_count
|
@@ -101,35 +96,10 @@ module MadCart
|
|
101
96
|
items.each(&block)
|
102
97
|
end
|
103
98
|
|
104
|
-
def parse_response(&block)
|
105
|
-
response = check_for_errors &block
|
106
|
-
return [] if empty_body?(response)
|
107
|
-
return response.body
|
108
|
-
end
|
109
|
-
|
110
|
-
def check_for_errors(&block)
|
111
|
-
response = yield
|
112
|
-
|
113
|
-
case response.status
|
114
|
-
when 401
|
115
|
-
raise InvalidCredentials
|
116
|
-
when 500
|
117
|
-
raise ServerError
|
118
|
-
end
|
119
|
-
|
120
|
-
response
|
121
|
-
rescue Faraday::Error::ConnectionFailed => e
|
122
|
-
raise InvalidStore
|
123
|
-
end
|
124
|
-
|
125
99
|
def api_url_for(store_domain)
|
126
100
|
"http://#{store_domain}/api/"
|
127
101
|
end
|
128
102
|
|
129
|
-
def empty_body?(response)
|
130
|
-
true if response.status == 204 || response.body.nil?
|
131
|
-
end
|
132
|
-
|
133
103
|
def create_connection(args={})
|
134
104
|
Faraday.new(DEFAULT_CONNECTION_OPTIONS.merge(:url => api_url_for(args[:store_url]))) do |connection|
|
135
105
|
connection.response :json
|
data/lib/mad_cart/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://support%40madmimi.com:an-invalid-key@store-cr4wsh4.mybigcommerce.com/api/v2/time.json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.2
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 500
|
19
|
+
message: Internal Server Error
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx
|
23
|
+
Date:
|
24
|
+
- Tue, 31 May 2016 10:09:21 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Set-Cookie:
|
32
|
+
- fornax_anonymousId=1bc2ddc4-69b4-43ec-a7e7-6fca029c0eea; expires=Sun, 27-Nov-2016
|
33
|
+
10:09:21 GMT; path=/; domain=.store-cr4wsh4.mybigcommerce.com
|
34
|
+
Www-Authenticate:
|
35
|
+
- Basic
|
36
|
+
X-Bc-Store-Version:
|
37
|
+
- 7.6.0
|
38
|
+
body:
|
39
|
+
encoding: UTF-8
|
40
|
+
string: '[{"status":401,"message":"The specified credentials were invalid."}]'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Tue, 31 May 2016 10:09:23 GMT
|
43
|
+
recorded_with: VCR 2.5.0
|
@@ -123,6 +123,24 @@ describe MadCart::Store::BigCommerce do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
it "fails if it cannot connect to the big commerce server" do
|
127
|
+
VCR.use_cassette('big_commerce_server_error') do
|
128
|
+
api = MadCart::Store::BigCommerce.new(
|
129
|
+
:api_key => 'an-invalid-key',
|
130
|
+
:store_url => 'store-cr4wsh4.mybigcommerce.com',
|
131
|
+
:username => 'support@madmimi.com'
|
132
|
+
)
|
133
|
+
|
134
|
+
api.should_not be_valid
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "fails if it cannot parse the response from the big commerce server" do
|
139
|
+
VCR.use_cassette('big_commerce_time') do
|
140
|
+
subject.connection.stub(:get) { raise Faraday::ParsingError, "" }
|
141
|
+
subject.should_not be_valid
|
142
|
+
end
|
143
|
+
end
|
126
144
|
end
|
127
145
|
|
128
146
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mad_cart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Heiligers
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -203,6 +203,7 @@ extra_rdoc_files: []
|
|
203
203
|
files:
|
204
204
|
- ".gitignore"
|
205
205
|
- ".rspec"
|
206
|
+
- CHANGELOG.md
|
206
207
|
- Gemfile
|
207
208
|
- LICENSE.txt
|
208
209
|
- README.md
|
@@ -228,6 +229,7 @@ files:
|
|
228
229
|
- spec/fixtures/vcr_cassettes/big_commerce_products.yml
|
229
230
|
- spec/fixtures/vcr_cassettes/big_commerce_products_count.yml
|
230
231
|
- spec/fixtures/vcr_cassettes/big_commerce_products_no_images.yml
|
232
|
+
- spec/fixtures/vcr_cassettes/big_commerce_server_error.yml
|
231
233
|
- spec/fixtures/vcr_cassettes/big_commerce_store.yml
|
232
234
|
- spec/fixtures/vcr_cassettes/big_commerce_time.yml
|
233
235
|
- spec/fixtures/vcr_cassettes/etsy_store_does_not_exist.yml
|
@@ -268,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
270
|
version: '0'
|
269
271
|
requirements: []
|
270
272
|
rubyforge_project:
|
271
|
-
rubygems_version: 2.
|
273
|
+
rubygems_version: 2.4.3
|
272
274
|
signing_key:
|
273
275
|
specification_version: 4
|
274
276
|
summary: Allows communication with various e-commerce merchants such as BigCommerce
|
@@ -281,6 +283,7 @@ test_files:
|
|
281
283
|
- spec/fixtures/vcr_cassettes/big_commerce_products.yml
|
282
284
|
- spec/fixtures/vcr_cassettes/big_commerce_products_count.yml
|
283
285
|
- spec/fixtures/vcr_cassettes/big_commerce_products_no_images.yml
|
286
|
+
- spec/fixtures/vcr_cassettes/big_commerce_server_error.yml
|
284
287
|
- spec/fixtures/vcr_cassettes/big_commerce_store.yml
|
285
288
|
- spec/fixtures/vcr_cassettes/big_commerce_time.yml
|
286
289
|
- spec/fixtures/vcr_cassettes/etsy_store_does_not_exist.yml
|