shydra 0.1.0 → 0.1.1
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.
- data/Guardfile +1 -1
- data/lib/shydra.rb +2 -0
- data/lib/shydra/batch.rb +20 -0
- data/lib/shydra/version.rb +1 -1
- data/spec/shydra/batch_spec.rb +65 -0
- data/spec/shydra/hydra_spec.rb +6 -1
- data/spec/shydra/request_spec.rb +3 -26
- data/spec/shydra/response_spec.rb +32 -1
- data/spec/shydra_spec.rb +10 -1
- data/spec/spec_helper.rb +3 -1
- metadata +7 -4
data/Guardfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# More info at https://github.com/guard/guard#readme
|
2
2
|
|
3
|
-
guard :rspec, cli: "--color", bundler: false, all_on_start: true do
|
3
|
+
guard :rspec, cli: "--color --backtrace", bundler: false, all_on_start: true do
|
4
4
|
watch(%r{^spec/.+_spec\.rb$})
|
5
5
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
6
6
|
watch('spec/spec_helper.rb') { "spec" }
|
data/lib/shydra.rb
CHANGED
data/lib/shydra/batch.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Shydra
|
2
|
+
class Batch
|
3
|
+
OVER_LIMIT_RESPONSE_CODE = 429
|
4
|
+
|
5
|
+
attr_accessor :requests
|
6
|
+
def initialize
|
7
|
+
@requests = []
|
8
|
+
end
|
9
|
+
|
10
|
+
delegate :<<, :size, :clear, to: :requests
|
11
|
+
|
12
|
+
def finished?
|
13
|
+
requests.all?{|r| !r.response.nil?}
|
14
|
+
end
|
15
|
+
|
16
|
+
def over_limit?
|
17
|
+
requests.any? { |r| r.response && (r.response.code == OVER_LIMIT_RESPONSE_CODE) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/shydra/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shydra::Batch do
|
4
|
+
it "adds requests" do
|
5
|
+
request = double("Request")
|
6
|
+
subject << request
|
7
|
+
expect(subject.requests).to include(request)
|
8
|
+
end
|
9
|
+
|
10
|
+
def request_and_response_mock(request_name, response_name=nil, response={})
|
11
|
+
req = double(request_name)
|
12
|
+
resp = response_name.nil? ? nil : double(response_name)
|
13
|
+
if response[:code]
|
14
|
+
resp.should_receive(:code).at_least(:once).and_return(response[:code])
|
15
|
+
else
|
16
|
+
resp.stub(:code).and_return(200) unless resp.nil?
|
17
|
+
end
|
18
|
+
if resp
|
19
|
+
req.should_receive(:response).at_least(:once).and_return(resp)
|
20
|
+
else
|
21
|
+
req.stub(:response).and_return(resp)
|
22
|
+
end
|
23
|
+
req
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#finished?" do
|
27
|
+
it "returns true when all the requests have a response" do
|
28
|
+
r1 = request_and_response_mock("request 1", 'response 1')
|
29
|
+
r2 = request_and_response_mock("request 2", 'response 2')
|
30
|
+
subject << r1; subject << r2
|
31
|
+
expect(subject.finished?).to be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns false when not all the requests have a response" do
|
35
|
+
r1 = request_and_response_mock("request 1", 'response 1')
|
36
|
+
r2 = request_and_response_mock("request 2", nil)
|
37
|
+
subject << r1; subject << r2
|
38
|
+
expect(subject.finished?).to be_false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#over_limit?" do
|
43
|
+
before do
|
44
|
+
end
|
45
|
+
it "returns false when all the requests do not have response code 429" do
|
46
|
+
r1 = request_and_response_mock("request 1", 'response 1', code: 200)
|
47
|
+
r2 = request_and_response_mock("request 2", 'response 2', code: 500)
|
48
|
+
subject << r1; subject << r2
|
49
|
+
subject << r1; subject << r2
|
50
|
+
expect(subject.over_limit?).to be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns true when any request has response code 429" do
|
54
|
+
r1 = request_and_response_mock("request 1", 'response 1', code: 200)
|
55
|
+
r2 = request_and_response_mock("request 2", 'response 2', code: 429)
|
56
|
+
r3 = request_and_response_mock("request 3") # over_limit will return true after finding the first 429
|
57
|
+
subject << r1; subject << r2; subject << r3
|
58
|
+
expect(subject.over_limit?).to be_true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
end
|
data/spec/shydra/hydra_spec.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Hydra" do
|
4
|
-
|
4
|
+
context "check api limit with one request" do
|
5
|
+
it "only sends one request if the api-limit is too small for all the requests"
|
6
|
+
it "sends all the requests if the api-limit will allow"
|
7
|
+
|
8
|
+
end
|
9
|
+
|
5
10
|
end
|
data/spec/shydra/request_spec.rb
CHANGED
@@ -55,32 +55,9 @@ describe "Shydra::Request" do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
response = Typhoeus::Response.new(code: 200, body: "{\"count\":14}")
|
62
|
-
Typhoeus.stub(/cronin/).and_return(response)
|
63
|
-
response = Shydra::Request.new(:product, :count).run
|
64
|
-
|
65
|
-
expect(response.data).to eq 14
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns a hash of product attributes for an id request" do
|
69
|
-
response = Typhoeus::Response.new(code: 200, body: "{\"product\":{\"body_html\":\"yo yo yo baby pop\",\"id\":137632345}}")
|
70
|
-
Typhoeus.stub(/cronin/).and_return(response)
|
71
|
-
response = Shydra::Request.new(:product, id: 137632345).run
|
72
|
-
|
73
|
-
expect(response.data).to eq( {"body_html"=>"yo yo yo baby pop", "id"=>137632345})
|
74
|
-
end
|
75
|
-
|
76
|
-
it "returns an array of hashes of product attributes for an collection request" do
|
77
|
-
response = Typhoeus::Response.new(code: 200, body: "{\"products\":[{\"body_html\":\"yo yo yo baby pop\",\"id\":123},{\"body_html\":\"yowza\",\"id\":456}]}")
|
78
|
-
Typhoeus.stub(/cronin/).and_return(response)
|
79
|
-
response = Shydra::Request.new(:product).run
|
80
|
-
|
81
|
-
expect(response.data).to eq( [{"body_html"=>"yo yo yo baby pop", "id"=>123}, {"body_html"=>"yowza", "id"=>456}] )
|
82
|
-
end
|
83
|
-
end
|
58
|
+
|
59
|
+
context "api-limits" do
|
60
|
+
it "adds the api-limit on_complete handler to a request"
|
84
61
|
end
|
85
62
|
|
86
63
|
end
|
@@ -1,5 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Response" do
|
4
|
-
|
4
|
+
before do
|
5
|
+
@shopify_headers = {"X-Shopify-Access-Token"=>"yyyyyyyyy"}
|
6
|
+
ShopifyAPI::Base.stub(:site).and_return(URI("https://xxxx:yyyy@cronin.myshopify.com/admin/"))
|
7
|
+
ShopifyAPI::Base.stub(:headers).and_return(@shopify_headers)
|
8
|
+
end
|
9
|
+
describe '#data' do
|
10
|
+
it "returns the count as an int for a count request" do
|
11
|
+
response = Typhoeus::Response.new(code: 200, body: "{\"count\":14}")
|
12
|
+
Typhoeus.stub(/cronin/).and_return(response)
|
13
|
+
response = Shydra::Request.new(:product, :count).run
|
14
|
+
|
15
|
+
expect(response.data).to eq 14
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a hash of product attributes for an id request" do
|
19
|
+
response = Typhoeus::Response.new(code: 200, body: "{\"product\":{\"body_html\":\"yo yo yo baby pop\",\"id\":137632345}}")
|
20
|
+
Typhoeus.stub(/cronin/).and_return(response)
|
21
|
+
response = Shydra::Request.new(:product, id: 137632345).run
|
22
|
+
|
23
|
+
expect(response.data).to eq( {"body_html"=>"yo yo yo baby pop", "id"=>137632345})
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an array of hashes of product attributes for an collection request" do
|
27
|
+
response = Typhoeus::Response.new(code: 200, body: "{\"products\":[{\"body_html\":\"yo yo yo baby pop\",\"id\":123},{\"body_html\":\"yowza\",\"id\":456}]}")
|
28
|
+
Typhoeus.stub(/cronin/).and_return(response)
|
29
|
+
response = Shydra::Request.new(:product).run
|
30
|
+
|
31
|
+
expect(response.data).to eq( [{"body_html"=>"yo yo yo baby pop", "id"=>123}, {"body_html"=>"yowza", "id"=>456}] )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
5
36
|
end
|
data/spec/shydra_spec.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Shydra" do
|
4
|
-
|
4
|
+
context "api-limits" do
|
5
|
+
describe '#update_api_limit' do
|
6
|
+
it "sets the current requests left from a response"
|
7
|
+
it "sets the first known time the api-limit was set"
|
8
|
+
it "resets the first known time if the requests left increases"
|
9
|
+
it "uses the response time if it is available"
|
10
|
+
it "caches the results with memcache if it is available"
|
11
|
+
it "synchronizes"
|
12
|
+
end
|
13
|
+
end
|
5
14
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shydra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-06-
|
12
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- README.md
|
125
125
|
- Rakefile
|
126
126
|
- lib/shydra.rb
|
127
|
+
- lib/shydra/batch.rb
|
127
128
|
- lib/shydra/hydra.rb
|
128
129
|
- lib/shydra/request.rb
|
129
130
|
- lib/shydra/resource.rb
|
@@ -133,6 +134,7 @@ files:
|
|
133
134
|
- lib/shydra/response.rb
|
134
135
|
- lib/shydra/version.rb
|
135
136
|
- shydra.gemspec
|
137
|
+
- spec/shydra/batch_spec.rb
|
136
138
|
- spec/shydra/hydra_spec.rb
|
137
139
|
- spec/shydra/request_spec.rb
|
138
140
|
- spec/shydra/resource_spec.rb
|
@@ -157,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
159
|
version: '0'
|
158
160
|
segments:
|
159
161
|
- 0
|
160
|
-
hash:
|
162
|
+
hash: 3761638624358977940
|
161
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
164
|
none: false
|
163
165
|
requirements:
|
@@ -166,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
168
|
version: '0'
|
167
169
|
segments:
|
168
170
|
- 0
|
169
|
-
hash:
|
171
|
+
hash: 3761638624358977940
|
170
172
|
requirements: []
|
171
173
|
rubyforge_project:
|
172
174
|
rubygems_version: 1.8.25
|
@@ -174,6 +176,7 @@ signing_key:
|
|
174
176
|
specification_version: 3
|
175
177
|
summary: A fast, parallel shopify api client using typhoeus/hydraa
|
176
178
|
test_files:
|
179
|
+
- spec/shydra/batch_spec.rb
|
177
180
|
- spec/shydra/hydra_spec.rb
|
178
181
|
- spec/shydra/request_spec.rb
|
179
182
|
- spec/shydra/resource_spec.rb
|