ey_api_hmac 0.4.2 → 0.4.3
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/Gemfile +1 -0
- data/lib/ey_api_hmac/authed_connection.rb +1 -13
- data/lib/ey_api_hmac/base_connection.rb +11 -3
- data/lib/ey_api_hmac/version.rb +1 -1
- data/spec/authed_connection_spec.rb +12 -2
- data/spec/spec_helper.rb +2 -0
- metadata +4 -4
data/Gemfile
CHANGED
@@ -9,19 +9,7 @@ module EY
|
|
9
9
|
@auth_id = auth_id
|
10
10
|
@auth_key = auth_key
|
11
11
|
super(user_agent)
|
12
|
-
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def client
|
17
|
-
bak = self.backend
|
18
|
-
#damn you scope!
|
19
|
-
auth_id_arg = auth_id
|
20
|
-
auth_key_arg = auth_key
|
21
|
-
@client ||= Rack::Client.new do
|
22
|
-
use EY::ApiHMAC::ApiAuth::Client, auth_id_arg, auth_key_arg
|
23
|
-
run bak
|
24
|
-
end
|
12
|
+
self.middlewares.unshift [EY::ApiHMAC::ApiAuth::Client, auth_id, auth_key]
|
25
13
|
end
|
26
14
|
|
27
15
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rack/client'
|
2
|
+
require 'rack-idempotent'
|
2
3
|
require 'json'
|
3
4
|
require 'time'
|
4
5
|
|
@@ -6,12 +7,15 @@ module EY
|
|
6
7
|
module ApiHMAC
|
7
8
|
class BaseConnection
|
8
9
|
|
10
|
+
attr_accessor :middlewares
|
11
|
+
|
9
12
|
def initialize(user_agent = nil)
|
10
13
|
@standard_headers = {
|
11
14
|
'Accept' => 'application/json',
|
12
15
|
'HTTP_DATE' => Time.now.httpdate,
|
13
16
|
'USER_AGENT' => user_agent || default_user_agent
|
14
17
|
}
|
18
|
+
self.middlewares = [Rack::Idempotent]
|
15
19
|
end
|
16
20
|
|
17
21
|
def default_user_agent
|
@@ -74,10 +78,14 @@ module EY
|
|
74
78
|
protected
|
75
79
|
|
76
80
|
def client
|
77
|
-
|
81
|
+
#damn you scope!
|
82
|
+
backend = self.backend
|
83
|
+
middlewares = self.middlewares
|
78
84
|
@client ||= Rack::Client.new do
|
79
|
-
|
80
|
-
|
85
|
+
middlewares.each do |middleware|
|
86
|
+
use *Array(middleware)
|
87
|
+
end
|
88
|
+
run backend
|
81
89
|
end
|
82
90
|
end
|
83
91
|
|
data/lib/ey_api_hmac/version.rb
CHANGED
@@ -9,7 +9,7 @@ describe EY::ApiHMAC::AuthedConnection do
|
|
9
9
|
describe "on 500" do
|
10
10
|
before do
|
11
11
|
@connection.backend = lambda do |env|
|
12
|
-
[
|
12
|
+
[500, {}, [""]]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
it "raises an error" do
|
@@ -24,7 +24,7 @@ describe EY::ApiHMAC::AuthedConnection do
|
|
24
24
|
describe "on bad body" do
|
25
25
|
it "calls the error handler" do
|
26
26
|
@connection.backend = lambda do |env|
|
27
|
-
[
|
27
|
+
[200, {"Content-Type" => "application/json"}, ["200 OK"]]
|
28
28
|
end
|
29
29
|
errors = []
|
30
30
|
@connection.handle_errors_with{|*args| errors << args; false}
|
@@ -41,4 +41,14 @@ describe EY::ApiHMAC::AuthedConnection do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
describe "uses Rack Idempotent" do
|
45
|
+
before do
|
46
|
+
@connection.backend = lambda do |env|
|
47
|
+
[408, {}, [""]]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
it "raises an error" do
|
51
|
+
lambda { @connection.get("/") }.should raise_exception(Rack::Idempotent::RetryLimitExceeded)
|
52
|
+
end
|
53
|
+
end
|
44
54
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ey_api_hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 3
|
10
|
+
version: 0.4.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Jacob Burkhart & Thorben Schr\xC3\xB6der & David Calavera & others"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rack-client
|