leadlight 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +7 -7
- data/Rakefile +7 -1
- data/leadlight.gemspec +4 -2
- data/lib/leadlight.rb +1 -1
- data/lib/leadlight/request.rb +9 -2
- data/spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/enables_custom_error_matching.yml +67 -0
- data/spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/should_raise_ResourceNotFound.yml +139 -0
- data/spec/leadlight/request_spec.rb +62 -5
- data/spec/leadlight_spec.rb +19 -0
- metadata +32 -30
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
leadlight (0.0.
|
4
|
+
leadlight (0.0.4)
|
5
5
|
addressable
|
6
6
|
faraday
|
7
7
|
fattr
|
@@ -18,11 +18,11 @@ GEM
|
|
18
18
|
columnize (0.3.6)
|
19
19
|
diff-lcs (1.1.3)
|
20
20
|
fail-fast (1.0.0)
|
21
|
-
faraday (0.7.
|
22
|
-
addressable (~> 2.2
|
23
|
-
multipart-post (~> 1.1
|
24
|
-
rack (
|
25
|
-
fattr (2.2.
|
21
|
+
faraday (0.7.6)
|
22
|
+
addressable (~> 2.2)
|
23
|
+
multipart-post (~> 1.1)
|
24
|
+
rack (~> 1.1)
|
25
|
+
fattr (2.2.1)
|
26
26
|
ffi (1.0.11)
|
27
27
|
guard (0.10.0)
|
28
28
|
ffi (>= 0.5.0)
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
mime-types (1.17.2)
|
41
41
|
multi_json (1.0.4)
|
42
42
|
multipart-post (1.1.4)
|
43
|
-
rack (1.4.
|
43
|
+
rack (1.4.1)
|
44
44
|
rake (0.9.2.2)
|
45
45
|
rspec (2.7.0)
|
46
46
|
rspec-core (~> 2.7.0)
|
data/Rakefile
CHANGED
@@ -84,7 +84,7 @@ task :release => :build do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
desc "Build #{gem_file} into the pkg directory"
|
87
|
-
task :build => :gemspec do
|
87
|
+
task :build => [:gemspec, :update_bundle] do
|
88
88
|
sh "mkdir -p pkg"
|
89
89
|
sh "gem build #{gemspec_file}"
|
90
90
|
sh "mv #{gem_file} pkg"
|
@@ -119,6 +119,12 @@ task :gemspec => :validate do
|
|
119
119
|
puts "Updated #{gemspec_file}"
|
120
120
|
end
|
121
121
|
|
122
|
+
desc "Update #{name} in bundle"
|
123
|
+
task :update_bundle => :validate do
|
124
|
+
`bundle update #{name}`
|
125
|
+
puts "Bundled #{name} version #{version}"
|
126
|
+
end
|
127
|
+
|
122
128
|
desc "Validate #{gemspec_file}"
|
123
129
|
task :validate do
|
124
130
|
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
data/leadlight.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'leadlight'
|
16
|
-
s.version = '0.0.
|
17
|
-
s.date = '2012-02-
|
16
|
+
s.version = '0.0.4'
|
17
|
+
s.date = '2012-02-10'
|
18
18
|
s.rubyforge_project = 'leadlight'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -103,6 +103,8 @@ Gem::Specification.new do |s|
|
|
103
103
|
spec/cassettes/Leadlight/tinted_GitHub_example/_root/__location__/.yml
|
104
104
|
spec/cassettes/Leadlight/tinted_GitHub_example/_root/should_be_a_204_no_content.yml
|
105
105
|
spec/cassettes/Leadlight/tinted_GitHub_example/_user/has_the_expected_content.yml
|
106
|
+
spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/enables_custom_error_matching.yml
|
107
|
+
spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/should_raise_ResourceNotFound.yml
|
106
108
|
spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/.yml
|
107
109
|
spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_able_to_follow_next_link.yml
|
108
110
|
spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable.yml
|
data/lib/leadlight.rb
CHANGED
data/lib/leadlight/request.rb
CHANGED
@@ -55,6 +55,7 @@ module Leadlight
|
|
55
55
|
entity_body = entity.body
|
56
56
|
content_type = entity.content_type
|
57
57
|
connection.run_request(http_method, url, entity_body, {}) do |request|
|
58
|
+
request.params.update(params) unless params.empty?
|
58
59
|
request.headers['Content-Type'] = content_type if content_type
|
59
60
|
request.options[:leadlight_request] = self
|
60
61
|
execute_hook(:on_prepare_request, request)
|
@@ -83,15 +84,21 @@ module Leadlight
|
|
83
84
|
end
|
84
85
|
alias_method :then, :submit_and_wait
|
85
86
|
|
86
|
-
def
|
87
|
+
def on_error
|
87
88
|
on_or_after_complete do |response|
|
88
89
|
unless response.success?
|
89
|
-
|
90
|
+
yield(response.env.fetch(:leadlight_representation))
|
90
91
|
end
|
91
92
|
end
|
92
93
|
self
|
93
94
|
end
|
94
95
|
|
96
|
+
def raise_on_error
|
97
|
+
on_error do |representation|
|
98
|
+
raise representation
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
95
102
|
def on_or_after_complete(&block)
|
96
103
|
synchronize do
|
97
104
|
if completed?
|
data/spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/enables_custom_error_matching.yml
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.github.com/
|
6
|
+
body: ''
|
7
|
+
headers:
|
8
|
+
Accept:
|
9
|
+
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
|
10
|
+
text/plain
|
11
|
+
response:
|
12
|
+
status:
|
13
|
+
code: 204
|
14
|
+
message:
|
15
|
+
headers:
|
16
|
+
server:
|
17
|
+
- nginx/1.0.4
|
18
|
+
date:
|
19
|
+
- Mon, 06 Feb 2012 21:16:34 GMT
|
20
|
+
connection:
|
21
|
+
- close
|
22
|
+
status:
|
23
|
+
- 204 No Content
|
24
|
+
x-ratelimit-limit:
|
25
|
+
- '5000'
|
26
|
+
etag:
|
27
|
+
- ! '"d41d8cd98f00b204e9800998ecf8427e"'
|
28
|
+
x-ratelimit-remaining:
|
29
|
+
- '4995'
|
30
|
+
body: ''
|
31
|
+
http_version:
|
32
|
+
recorded_at: Mon, 06 Feb 2012 21:17:11 GMT
|
33
|
+
- request:
|
34
|
+
method: get
|
35
|
+
uri: https://api.github.com/not_exist
|
36
|
+
body: ''
|
37
|
+
headers:
|
38
|
+
Accept:
|
39
|
+
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
|
40
|
+
text/plain
|
41
|
+
response:
|
42
|
+
status:
|
43
|
+
code: 404
|
44
|
+
message:
|
45
|
+
headers:
|
46
|
+
server:
|
47
|
+
- nginx/1.0.4
|
48
|
+
date:
|
49
|
+
- Mon, 06 Feb 2012 21:36:01 GMT
|
50
|
+
content-type:
|
51
|
+
- application/json; charset=utf-8
|
52
|
+
transfer-encoding:
|
53
|
+
- chunked
|
54
|
+
connection:
|
55
|
+
- close
|
56
|
+
status:
|
57
|
+
- 404 Not Found
|
58
|
+
x-ratelimit-limit:
|
59
|
+
- '5000'
|
60
|
+
etag:
|
61
|
+
- ! '"e66a7a6c91e2c26803f3f49feb7a883f"'
|
62
|
+
x-ratelimit-remaining:
|
63
|
+
- '4994'
|
64
|
+
body: ! '{"message":"Not Found"}'
|
65
|
+
http_version:
|
66
|
+
recorded_at: Mon, 06 Feb 2012 21:36:38 GMT
|
67
|
+
recorded_with: VCR 2.0.0.rc1
|
data/spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/should_raise_ResourceNotFound.yml
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.github.com/
|
6
|
+
body: ''
|
7
|
+
headers:
|
8
|
+
Accept:
|
9
|
+
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
|
10
|
+
text/plain
|
11
|
+
response:
|
12
|
+
status:
|
13
|
+
code: 204
|
14
|
+
message:
|
15
|
+
headers:
|
16
|
+
server:
|
17
|
+
- nginx/1.0.4
|
18
|
+
date:
|
19
|
+
- Mon, 06 Feb 2012 21:10:45 GMT
|
20
|
+
connection:
|
21
|
+
- close
|
22
|
+
status:
|
23
|
+
- 204 No Content
|
24
|
+
x-ratelimit-limit:
|
25
|
+
- '5000'
|
26
|
+
etag:
|
27
|
+
- ! '"d41d8cd98f00b204e9800998ecf8427e"'
|
28
|
+
x-ratelimit-remaining:
|
29
|
+
- '4999'
|
30
|
+
body: ''
|
31
|
+
http_version:
|
32
|
+
recorded_at: Mon, 06 Feb 2012 21:11:23 GMT
|
33
|
+
- request:
|
34
|
+
method: get
|
35
|
+
uri: https://api.github.com/not_exist
|
36
|
+
body: ''
|
37
|
+
headers:
|
38
|
+
Accept:
|
39
|
+
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
|
40
|
+
text/plain
|
41
|
+
response:
|
42
|
+
status:
|
43
|
+
code: 404
|
44
|
+
message:
|
45
|
+
headers:
|
46
|
+
server:
|
47
|
+
- nginx/1.0.4
|
48
|
+
date:
|
49
|
+
- Mon, 06 Feb 2012 21:10:45 GMT
|
50
|
+
content-type:
|
51
|
+
- application/json; charset=utf-8
|
52
|
+
transfer-encoding:
|
53
|
+
- chunked
|
54
|
+
connection:
|
55
|
+
- close
|
56
|
+
status:
|
57
|
+
- 404 Not Found
|
58
|
+
x-ratelimit-limit:
|
59
|
+
- '5000'
|
60
|
+
etag:
|
61
|
+
- ! '"e66a7a6c91e2c26803f3f49feb7a883f"'
|
62
|
+
x-ratelimit-remaining:
|
63
|
+
- '4998'
|
64
|
+
body: ! '{"message":"Not Found"}'
|
65
|
+
http_version:
|
66
|
+
recorded_at: Mon, 06 Feb 2012 21:11:23 GMT
|
67
|
+
- request:
|
68
|
+
method: get
|
69
|
+
uri: https://api.github.com/users/avdi
|
70
|
+
body: ''
|
71
|
+
headers:
|
72
|
+
Accept:
|
73
|
+
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
|
74
|
+
text/plain
|
75
|
+
response:
|
76
|
+
status:
|
77
|
+
code: 200
|
78
|
+
message:
|
79
|
+
headers:
|
80
|
+
server:
|
81
|
+
- nginx/1.0.4
|
82
|
+
date:
|
83
|
+
- Mon, 06 Feb 2012 21:12:36 GMT
|
84
|
+
content-type:
|
85
|
+
- application/json; charset=utf-8
|
86
|
+
transfer-encoding:
|
87
|
+
- chunked
|
88
|
+
connection:
|
89
|
+
- close
|
90
|
+
status:
|
91
|
+
- 200 OK
|
92
|
+
x-ratelimit-limit:
|
93
|
+
- '5000'
|
94
|
+
etag:
|
95
|
+
- ! '"c5c28456b021cca2a722c58983a4e081"'
|
96
|
+
x-ratelimit-remaining:
|
97
|
+
- '4997'
|
98
|
+
body: ! '{"type":"User","blog":"http://avdi.org/devblog/","url":"https://api.github.com/users/avdi","public_repos":61,"hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/4dea430d31b993abaf41cd9b54f8128d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","html_url":"https://github.com/avdi","public_gists":73,"following":33,"bio":null,"gravatar_id":"4dea430d31b993abaf41cd9b54f8128d","login":"avdi","followers":200,"location":"Pennsylvania,
|
99
|
+
USA","name":"Avdi Grimm","company":"ShipRise","id":982,"created_at":"2008-02-26T19:54:34Z","email":"avdi@avdi.org"}'
|
100
|
+
http_version:
|
101
|
+
recorded_at: Mon, 06 Feb 2012 21:13:13 GMT
|
102
|
+
- request:
|
103
|
+
method: get
|
104
|
+
uri: https://api.github.com/users/avdi/followers
|
105
|
+
body: ''
|
106
|
+
headers:
|
107
|
+
Accept:
|
108
|
+
- application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html,
|
109
|
+
text/plain
|
110
|
+
response:
|
111
|
+
status:
|
112
|
+
code: 200
|
113
|
+
message:
|
114
|
+
headers:
|
115
|
+
server:
|
116
|
+
- nginx/1.0.4
|
117
|
+
date:
|
118
|
+
- Mon, 06 Feb 2012 21:12:36 GMT
|
119
|
+
content-type:
|
120
|
+
- application/json; charset=utf-8
|
121
|
+
transfer-encoding:
|
122
|
+
- chunked
|
123
|
+
connection:
|
124
|
+
- close
|
125
|
+
status:
|
126
|
+
- 200 OK
|
127
|
+
x-ratelimit-limit:
|
128
|
+
- '5000'
|
129
|
+
etag:
|
130
|
+
- ! '"e83323661b46ebf08cc1d5f6f8fa2c5e"'
|
131
|
+
link:
|
132
|
+
- <https://api.github.com/users/avdi/followers?page=2>; rel="next", <https://api.github.com/users/avdi/followers?page=7>;
|
133
|
+
rel="last"
|
134
|
+
x-ratelimit-remaining:
|
135
|
+
- '4996'
|
136
|
+
body: ! '[{"url":"https://api.github.com/users/cypher","gravatar_id":"0176d9564601b43d75aff59f2cceed88","login":"cypher","avatar_url":"https://secure.gravatar.com/avatar/0176d9564601b43d75aff59f2cceed88?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":978},{"url":"https://api.github.com/users/tim","gravatar_id":"515a6f36db0157b7cf83f3b0368e9941","login":"tim","avatar_url":"https://secure.gravatar.com/avatar/515a6f36db0157b7cf83f3b0368e9941?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":2856},{"url":"https://api.github.com/users/SebastianRose","gravatar_id":"75bcdfe5499e68879fda2957572170ad","login":"SebastianRose","avatar_url":"https://secure.gravatar.com/avatar/75bcdfe5499e68879fda2957572170ad?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":23090},{"url":"https://api.github.com/users/cola-zero","gravatar_id":"e46e70d2689dfa229dac7ba0dc9f34e4","login":"cola-zero","avatar_url":"https://secure.gravatar.com/avatar/e46e70d2689dfa229dac7ba0dc9f34e4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":9118},{"url":"https://api.github.com/users/janfri","gravatar_id":"4c2cadf461b9c15ebf5726577b51e611","login":"janfri","avatar_url":"https://secure.gravatar.com/avatar/4c2cadf461b9c15ebf5726577b51e611?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":854},{"url":"https://api.github.com/users/nevans","gravatar_id":"dfaba90dcff3238dc9770e270232b4a1","login":"nevans","avatar_url":"https://secure.gravatar.com/avatar/dfaba90dcff3238dc9770e270232b4a1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":6142},{"url":"https://api.github.com/users/TreyE","gravatar_id":"2b405e0fc139db9b768cfab467955e04","login":"TreyE","avatar_url":"https://secure.gravatar.com/avatar/2b405e0fc139db9b768cfab467955e04?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":38384},{"url":"https://api.github.com/users/aaalex","gravatar_id":"aad77082a3f5b51259532217aadf450a","login":"aaalex","avatar_url":"https://secure.gravatar.com/avatar/aad77082a3f5b51259532217aadf450a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":11762},{"url":"https://api.github.com/users/beppu","gravatar_id":"32093c41c663ea62b17d66dab11b789f","login":"beppu","avatar_url":"https://secure.gravatar.com/avatar/32093c41c663ea62b17d66dab11b789f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":4425},{"url":"https://api.github.com/users/jdallien","gravatar_id":"490dc3575b1c341a84e89cba6305faf9","login":"jdallien","avatar_url":"https://secure.gravatar.com/avatar/490dc3575b1c341a84e89cba6305faf9?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":17927},{"url":"https://api.github.com/users/arn","gravatar_id":"17faa52c4ce95a86ac34b4d3010ea56d","login":"arn","avatar_url":"https://secure.gravatar.com/avatar/17faa52c4ce95a86ac34b4d3010ea56d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":6053},{"url":"https://api.github.com/users/llimllib","gravatar_id":"aa7c1350d93036592f58f165318044db","login":"llimllib","avatar_url":"https://secure.gravatar.com/avatar/aa7c1350d93036592f58f165318044db?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":7150},{"url":"https://api.github.com/users/jtrupiano","gravatar_id":"63d809dbf4d44297f73caad307972ec5","login":"jtrupiano","avatar_url":"https://secure.gravatar.com/avatar/63d809dbf4d44297f73caad307972ec5?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":12331},{"url":"https://api.github.com/users/lmarburger","gravatar_id":"f027637a680a05254c6f721f8ab57392","login":"lmarburger","avatar_url":"https://secure.gravatar.com/avatar/f027637a680a05254c6f721f8ab57392?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":23582},{"url":"https://api.github.com/users/lfaren","gravatar_id":"5f76cc23c75e77aa30ff1ac1fbf1ec54","login":"lfaren","avatar_url":"https://secure.gravatar.com/avatar/5f76cc23c75e77aa30ff1ac1fbf1ec54?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":142776},{"url":"https://api.github.com/users/slaney","gravatar_id":"3f4de376ba800ba092d9e1e332ede421","login":"slaney","avatar_url":"https://secure.gravatar.com/avatar/3f4de376ba800ba092d9e1e332ede421?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":5012},{"url":"https://api.github.com/users/stevenhaddox","gravatar_id":"1fdf54b0ccb88bb46f99b6d9352302dc","login":"stevenhaddox","avatar_url":"https://secure.gravatar.com/avatar/1fdf54b0ccb88bb46f99b6d9352302dc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":58004},{"url":"https://api.github.com/users/stonegao","gravatar_id":"dca772bde69d5a9f39a62ee79b122f0b","login":"stonegao","avatar_url":"https://secure.gravatar.com/avatar/dca772bde69d5a9f39a62ee79b122f0b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":42081},{"url":"https://api.github.com/users/riethmayer","gravatar_id":"788dec4942d6108c2cfb3ff2a9fb37ca","login":"riethmayer","avatar_url":"https://secure.gravatar.com/avatar/788dec4942d6108c2cfb3ff2a9fb37ca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":67637},{"url":"https://api.github.com/users/natebunnyfield","gravatar_id":"ed5c8e9a67490816384ff83e9d0e0a42","login":"natebunnyfield","avatar_url":"https://secure.gravatar.com/avatar/ed5c8e9a67490816384ff83e9d0e0a42?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":94285},{"url":"https://api.github.com/users/nerdEd","gravatar_id":"cf491f57897e7f31122ca6d03d6a49e4","login":"nerdEd","avatar_url":"https://secure.gravatar.com/avatar/cf491f57897e7f31122ca6d03d6a49e4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":1726},{"url":"https://api.github.com/users/jamesdaniels","gravatar_id":"3538353e7f9c08efddaabff15c9c6480","login":"jamesdaniels","avatar_url":"https://secure.gravatar.com/avatar/3538353e7f9c08efddaabff15c9c6480?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":44975},{"url":"https://api.github.com/users/jkamenik","gravatar_id":"d5cdad8cf459a2f3660d374e72eccf4b","login":"jkamenik","avatar_url":"https://secure.gravatar.com/avatar/d5cdad8cf459a2f3660d374e72eccf4b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":165914},{"url":"https://api.github.com/users/mnelson","gravatar_id":"58dac781cb69c3342f0a73c8936cf48b","login":"mnelson","avatar_url":"https://secure.gravatar.com/avatar/58dac781cb69c3342f0a73c8936cf48b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":51276},{"url":"https://api.github.com/users/devreq","gravatar_id":"7ea1a46afc3c483ef7ae7b6503b41793","login":"devreq","avatar_url":"https://secure.gravatar.com/avatar/7ea1a46afc3c483ef7ae7b6503b41793?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":230532},{"url":"https://api.github.com/users/flipsasser","gravatar_id":"ffca7d80230ae1f99914b74853bf06bb","login":"flipsasser","avatar_url":"https://secure.gravatar.com/avatar/ffca7d80230ae1f99914b74853bf06bb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":8594},{"url":"https://api.github.com/users/abachman","gravatar_id":"939848268c73b4049f90ee0703df7c68","login":"abachman","avatar_url":"https://secure.gravatar.com/avatar/939848268c73b4049f90ee0703df7c68?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":13002},{"url":"https://api.github.com/users/pjb3","gravatar_id":"6661ef9d747db3af8896cd94959d717d","login":"pjb3","avatar_url":"https://secure.gravatar.com/avatar/6661ef9d747db3af8896cd94959d717d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":726},{"url":"https://api.github.com/users/arcterex","gravatar_id":"5bc3ee98b5a5bd0cd936554de2bdc232","login":"arcterex","avatar_url":"https://secure.gravatar.com/avatar/5bc3ee98b5a5bd0cd936554de2bdc232?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":70160},{"url":"https://api.github.com/users/atmos","gravatar_id":"a86224d72ce21cd9f5bee6784d4b06c7","login":"atmos","avatar_url":"https://secure.gravatar.com/avatar/a86224d72ce21cd9f5bee6784d4b06c7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":38}]'
|
137
|
+
http_version:
|
138
|
+
recorded_at: Mon, 06 Feb 2012 21:13:14 GMT
|
139
|
+
recorded_with: VCR 2.0.0.rc1
|
@@ -94,6 +94,17 @@ module Leadlight
|
|
94
94
|
end
|
95
95
|
|
96
96
|
describe "#submit" do
|
97
|
+
let(:request_params) { stub }
|
98
|
+
let(:faraday_request) {
|
99
|
+
stub(options: {}, headers: {}, params: request_params)
|
100
|
+
}
|
101
|
+
|
102
|
+
before do
|
103
|
+
connection.stub(:run_request).
|
104
|
+
and_yield(faraday_request).
|
105
|
+
and_return(stub.as_null_object)
|
106
|
+
end
|
107
|
+
|
97
108
|
it "starts a request runnning" do
|
98
109
|
connection.should_receive(:run_request).
|
99
110
|
with(http_method, url, anything, {}).
|
@@ -102,11 +113,7 @@ module Leadlight
|
|
102
113
|
end
|
103
114
|
|
104
115
|
it "triggers the on_prepare_request hook in the block passed to #run_request" do
|
105
|
-
yielded
|
106
|
-
faraday_request = stub(options: {}, headers: {})
|
107
|
-
connection.stub(:run_request).
|
108
|
-
and_yield(faraday_request).
|
109
|
-
and_return(stub.as_null_object)
|
116
|
+
yielded = :nothing
|
110
117
|
subject.on_prepare_request do |request|
|
111
118
|
yielded = request
|
112
119
|
end
|
@@ -114,6 +121,21 @@ module Leadlight
|
|
114
121
|
yielded.should equal(faraday_request)
|
115
122
|
end
|
116
123
|
|
124
|
+
context "with request params" do
|
125
|
+
let(:params) {{ query: 'value' }}
|
126
|
+
|
127
|
+
it "passes params to request" do
|
128
|
+
request_params.should_receive(:update).with(params)
|
129
|
+
subject.submit
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with no request params" do
|
134
|
+
it "doesn't alter request params" do
|
135
|
+
request_params.should_not_receive(:update)
|
136
|
+
subject.submit
|
137
|
+
end
|
138
|
+
end
|
117
139
|
end
|
118
140
|
|
119
141
|
shared_examples_for "synchronous methods" do
|
@@ -228,6 +250,41 @@ module Leadlight
|
|
228
250
|
end
|
229
251
|
end
|
230
252
|
|
253
|
+
describe "#on_error" do
|
254
|
+
def submit_and_complete
|
255
|
+
t = Thread.new do
|
256
|
+
subject.submit
|
257
|
+
subject.wait
|
258
|
+
end
|
259
|
+
run_completion_handlers
|
260
|
+
t.join(1)
|
261
|
+
subject
|
262
|
+
end
|
263
|
+
|
264
|
+
it "yields to the block when response is an error" do
|
265
|
+
called = :not_set
|
266
|
+
block = proc{ called = true }
|
267
|
+
faraday_response.should_receive(:success?).and_return(false)
|
268
|
+
submit_and_complete.on_error(&block)
|
269
|
+
called.should be_true
|
270
|
+
end
|
271
|
+
|
272
|
+
it "does not yield to the block when response is sucess" do
|
273
|
+
called = :not_set
|
274
|
+
block = proc { called = true }
|
275
|
+
faraday_response.should_receive(:success?).and_return(true)
|
276
|
+
submit_and_complete.on_error(&block)
|
277
|
+
called.should eq(:not_set)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "passes the representation to the handler" do
|
281
|
+
passed = :not_set
|
282
|
+
block = ->(arg) { passed = arg }
|
283
|
+
faraday_response.should_receive(:success?).and_return(false)
|
284
|
+
submit_and_complete.on_error(&block)
|
285
|
+
passed.should equal(representation)
|
286
|
+
end
|
287
|
+
end
|
231
288
|
|
232
289
|
describe "#raise_on_error" do
|
233
290
|
def submit_and_complete
|
data/spec/leadlight_spec.rb
CHANGED
@@ -49,6 +49,7 @@ describe Leadlight, vcr: true do
|
|
49
49
|
tint 'root' do
|
50
50
|
match_path('/')
|
51
51
|
add_link_template '/users/{login}', 'user', 'Find user by login'
|
52
|
+
add_link '/not_exist', 'bad_link'
|
52
53
|
end
|
53
54
|
|
54
55
|
tint 'user' do
|
@@ -124,6 +125,24 @@ describe Leadlight, vcr: true do
|
|
124
125
|
followers.should have(61).items
|
125
126
|
end
|
126
127
|
end
|
128
|
+
|
129
|
+
describe 'bad links' do
|
130
|
+
class MyAwesomeError < StandardError
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should raise ResourceNotFound' do
|
134
|
+
expect{
|
135
|
+
session.root.bad_link
|
136
|
+
}.to raise_error(Leadlight::ResourceNotFound)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'enables custom error matching' do
|
140
|
+
expect{
|
141
|
+
handler = proc { raise MyAwesomeError }
|
142
|
+
session.root.link('bad_link').get.on_error(&handler).submit_and_wait
|
143
|
+
}.to raise_error(MyAwesomeError)
|
144
|
+
end
|
145
|
+
end
|
127
146
|
end
|
128
147
|
|
129
148
|
describe 'authorized GitHub example', vcr: { match_requests_on: [:method, :uri]}do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leadlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
16
|
-
requirement: &
|
16
|
+
requirement: &70265065325740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70265065325740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: faraday
|
27
|
-
requirement: &
|
27
|
+
requirement: &70265065324520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70265065324520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fattr
|
38
|
-
requirement: &
|
38
|
+
requirement: &70265065323140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70265065323140
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: link_header
|
49
|
-
requirement: &
|
49
|
+
requirement: &70265065321920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70265065321920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: multi_json
|
60
|
-
requirement: &
|
60
|
+
requirement: &70265065321120 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70265065321120
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mime-types
|
71
|
-
requirement: &
|
71
|
+
requirement: &70265065319720 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70265065319720
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: hookr
|
82
|
-
requirement: &
|
82
|
+
requirement: &70265065318640 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70265065318640
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rake
|
93
|
-
requirement: &
|
93
|
+
requirement: &70265065317280 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70265065317280
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rspec
|
104
|
-
requirement: &
|
104
|
+
requirement: &70265065316240 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70265065316240
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: vcr
|
115
|
-
requirement: &
|
115
|
+
requirement: &70265065314900 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ~>
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 2.0.0.rc1
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70265065314900
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: guard
|
126
|
-
requirement: &
|
126
|
+
requirement: &70265065313760 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70265065313760
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: guard-rspec
|
137
|
-
requirement: &
|
137
|
+
requirement: &70265065312460 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70265065312460
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: guard-bundler
|
148
|
-
requirement: &
|
148
|
+
requirement: &70265065311500 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70265065311500
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: ruby-debug19
|
159
|
-
requirement: &
|
159
|
+
requirement: &70265065310040 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70265065310040
|
168
168
|
description: Rose colored stained glass windows for HTTP.
|
169
169
|
email: avdi@avdi.org
|
170
170
|
executables: []
|
@@ -209,6 +209,8 @@ files:
|
|
209
209
|
- spec/cassettes/Leadlight/tinted_GitHub_example/_root/__location__/.yml
|
210
210
|
- spec/cassettes/Leadlight/tinted_GitHub_example/_root/should_be_a_204_no_content.yml
|
211
211
|
- spec/cassettes/Leadlight/tinted_GitHub_example/_user/has_the_expected_content.yml
|
212
|
+
- spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/enables_custom_error_matching.yml
|
213
|
+
- spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/should_raise_ResourceNotFound.yml
|
212
214
|
- spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/.yml
|
213
215
|
- spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_able_to_follow_next_link.yml
|
214
216
|
- spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable.yml
|