weary 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +95 -13
- data/Rakefile +5 -29
- data/VERSION +1 -1
- data/examples/batch.rb +20 -0
- data/examples/repo.rb +7 -11
- data/examples/status.rb +10 -2
- data/lib/weary.rb +40 -7
- data/lib/weary/base.rb +1 -2
- data/lib/weary/batch.rb +37 -0
- data/lib/weary/exceptions.rb +1 -1
- data/lib/weary/httpverb.rb +2 -2
- data/lib/weary/request.rb +116 -33
- data/lib/weary/resource.rb +1 -1
- data/lib/weary/response.rb +19 -23
- data/spec/spec_helper.rb +7 -18
- data/spec/weary/base_spec.rb +10 -11
- data/spec/weary/batch_spec.rb +71 -0
- data/spec/weary/httpverb_spec.rb +5 -0
- data/spec/weary/request_spec.rb +326 -33
- data/spec/weary/resource_spec.rb +2 -2
- data/spec/weary/response_spec.rb +137 -41
- data/spec/weary_spec.rb +54 -0
- data/weary.gemspec +14 -3
- metadata +28 -3
data/spec/weary/resource_spec.rb
CHANGED
@@ -242,8 +242,8 @@ describe Weary::Resource do
|
|
242
242
|
request = @test.build!(params, defaults, basic_auth)
|
243
243
|
|
244
244
|
request.class.should == Weary::Request
|
245
|
-
request.
|
246
|
-
request.
|
245
|
+
request.via.should == :get
|
246
|
+
request.credentials.should == basic_auth
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
data/spec/weary/response_spec.rb
CHANGED
@@ -2,71 +2,167 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
2
2
|
|
3
3
|
describe Weary::Response do
|
4
4
|
before do
|
5
|
-
|
5
|
+
FakeWeb.register_uri(:get, "http://twitter.com", :body => get_fixture('twitter.xml'))
|
6
|
+
FakeWeb.register_uri(:get, "http://github.com", :body => get_fixture('github.yml'))
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
after do
|
10
|
+
FakeWeb.clean_registry
|
10
11
|
end
|
11
12
|
|
12
|
-
it '
|
13
|
-
|
13
|
+
it 'wraps a raw Net::HTTPResponse' do
|
14
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'))
|
15
|
+
|
16
|
+
request = Weary::Request.new('http://vimeo.com')
|
17
|
+
response = request.perform
|
18
|
+
response.raw.is_a?(Net::HTTPResponse).should == true
|
14
19
|
end
|
15
20
|
|
16
|
-
it '
|
17
|
-
|
21
|
+
it 'stores the Request object that requested it' do
|
22
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'))
|
23
|
+
|
24
|
+
request = Weary::Request.new('http://vimeo.com')
|
25
|
+
response = request.perform
|
26
|
+
response.requester.should == request
|
18
27
|
end
|
19
28
|
|
20
|
-
it '
|
21
|
-
|
29
|
+
it 'has an HTTP code' do
|
30
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :status => http_status_message(418))
|
31
|
+
|
32
|
+
request = Weary::Request.new('http://vimeo.com')
|
33
|
+
response = request.perform
|
34
|
+
response.code.should == 418
|
22
35
|
end
|
23
36
|
|
24
|
-
it '
|
25
|
-
|
37
|
+
it 'has an HTTP message associated with it' do
|
38
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :status => http_status_message(418))
|
39
|
+
|
40
|
+
request = Weary::Request.new('http://vimeo.com')
|
41
|
+
response = request.perform
|
42
|
+
response.message.should == "I'm a teapot"
|
26
43
|
end
|
27
44
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
45
|
+
it 'knows if the request cycle was successful' do
|
46
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'))
|
47
|
+
|
48
|
+
request = Weary::Request.new('http://vimeo.com')
|
49
|
+
response = request.perform
|
50
|
+
response.success?.should == true
|
32
51
|
end
|
33
52
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
53
|
+
it 'stores the HTTP header' do
|
54
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :Server => 'Apache')
|
55
|
+
|
56
|
+
request = Weary::Request.new('http://vimeo.com')
|
57
|
+
response = request.perform
|
58
|
+
response.header['server'][0].should == 'Apache'
|
39
59
|
end
|
40
60
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
61
|
+
it 'stores the content-type of the response' do
|
62
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :'Content-Type' => 'text/json')
|
63
|
+
|
64
|
+
request = Weary::Request.new('http://vimeo.com')
|
65
|
+
response = request.perform
|
66
|
+
response.content_type.should == 'text/json'
|
46
67
|
end
|
47
68
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
69
|
+
it 'stores the cookies sent by the response' do
|
70
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :'Set-Cookie' => 'cookie=true')
|
71
|
+
|
72
|
+
request = Weary::Request.new('http://vimeo.com')
|
73
|
+
response = request.perform
|
74
|
+
response.cookie.should == 'cookie=true'
|
52
75
|
end
|
53
76
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
77
|
+
it 'stores the body of the response' do
|
78
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'))
|
79
|
+
|
80
|
+
request = Weary::Request.new('http://vimeo.com')
|
81
|
+
response = request.perform
|
82
|
+
response.body.should == get_fixture('vimeo.json')
|
58
83
|
end
|
59
84
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
85
|
+
it 'normalizes the format type of the response' do
|
86
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :'Content-Type' => 'text/json')
|
87
|
+
|
88
|
+
request = Weary::Request.new('http://vimeo.com')
|
89
|
+
response = request.perform
|
90
|
+
response.format.should == :json
|
64
91
|
end
|
65
92
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
93
|
+
it 'can follow redirects' do
|
94
|
+
FakeWeb.register_uri(:get, "http://markwunsch.com", :status => http_status_message(301), :Location => 'http://redirected.com')
|
95
|
+
FakeWeb.register_uri(:get, "http://redirected.com", :body => "Hello world")
|
96
|
+
|
97
|
+
request = Weary::Request.new('http://markwunsch.com')
|
98
|
+
request.follows = false
|
99
|
+
response = request.perform
|
100
|
+
response.code.should == 301
|
101
|
+
response.follow_redirect.code.should == 200
|
102
|
+
response.follow_redirect.body.should == "Hello world"
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'stores the url' do
|
106
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'))
|
107
|
+
|
108
|
+
request = Weary::Request.new('http://vimeo.com')
|
109
|
+
response = request.perform
|
110
|
+
response.url.to_s.should == 'http://vimeo.com'
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'Parsing' do
|
114
|
+
it 'parses JSON' do
|
115
|
+
FakeWeb.register_uri(:get, "http://vimeo.com", :body => get_fixture('vimeo.json'), :'Content-Type' => 'text/json')
|
116
|
+
|
117
|
+
request = Weary::Request.new('http://vimeo.com')
|
118
|
+
response = request.perform
|
119
|
+
response.parse[0].class.should == Hash
|
120
|
+
response.parse[0]['title'].should == '"The Noises Rest"'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'parses XML' do
|
124
|
+
FakeWeb.register_uri(:get, "http://twitter.com", :body => get_fixture('twitter.xml'), :'Content-Type' => 'application/xml')
|
125
|
+
|
126
|
+
request = Weary::Request.new('http://twitter.com')
|
127
|
+
response = request.perform
|
128
|
+
response.parse.class.should == Hash
|
129
|
+
response.parse['statuses'].size.should == 20
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'parses YAML' do
|
133
|
+
FakeWeb.register_uri(:get, "http://github.com", :body => get_fixture('github.yml'), :'Content-Type' => 'text/yaml')
|
134
|
+
|
135
|
+
request = Weary::Request.new('http://github.com')
|
136
|
+
response = request.perform
|
137
|
+
response.parse.class.should == Hash
|
138
|
+
response.parse['repository'][:name].should == 'rails'
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'can parse with the [] method' do
|
142
|
+
FakeWeb.register_uri(:get, "http://github.com", :body => get_fixture('github.yml'), :'Content-Type' => 'text/yaml')
|
143
|
+
|
144
|
+
request = Weary::Request.new('http://github.com')
|
145
|
+
response = request.perform
|
146
|
+
response['repository'][:name].should == 'rails'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'Exceptions' do
|
151
|
+
it 'raises an exception if there is a Server Error' do
|
152
|
+
FakeWeb.register_uri(:get, "http://github.com", :status => http_status_message(500))
|
153
|
+
|
154
|
+
request = Weary::Request.new('http://github.com')
|
155
|
+
response = request.perform
|
156
|
+
lambda { response.parse }.should raise_error
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'raises an exception if there is a Client Error' do
|
160
|
+
FakeWeb.register_uri(:get, "http://github.com", :status => http_status_message(404))
|
161
|
+
|
162
|
+
request = Weary::Request.new('http://github.com')
|
163
|
+
response = request.perform
|
164
|
+
lambda { response.parse }.should raise_error
|
165
|
+
end
|
70
166
|
end
|
71
167
|
|
72
168
|
end
|
data/spec/weary_spec.rb
CHANGED
@@ -1,4 +1,58 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
describe Weary do
|
4
|
+
it 'makes a request' do
|
5
|
+
r = Weary.request('http://google.com')
|
6
|
+
r.class.should == Weary::Request
|
7
|
+
r.uri.to_s.should == 'http://google.com'
|
8
|
+
r.via.should == :get
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can alter the request' do
|
12
|
+
block = lambda{|r| r.via = 'POST' }
|
13
|
+
r = Weary.request('http://google.com', :get, block)
|
14
|
+
r.via.should == :post
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'makes a GET request' do
|
18
|
+
r = Weary.get 'http://google.com'
|
19
|
+
r.class.should == Weary::Request
|
20
|
+
r.uri.to_s.should == 'http://google.com'
|
21
|
+
r.via.should == :get
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'makes a POST request' do
|
25
|
+
r = Weary.post 'http://google.com'
|
26
|
+
r.via.should == :post
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'makes a PUT request' do
|
30
|
+
r = Weary.put 'http://google.com'
|
31
|
+
r.via.should == :put
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'makes a DELETE request' do
|
35
|
+
r = Weary.delete 'http://google.com'
|
36
|
+
r.via.should == :delete
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'makes a HEAD request' do
|
40
|
+
r = Weary.head 'http://google.com'
|
41
|
+
r.via.should == :head
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'makes requests with an optional block' do
|
45
|
+
r = Weary.get 'http://google.com' do |req|
|
46
|
+
req.with = {:id => 'markwunsch'}
|
47
|
+
end
|
48
|
+
r.uri.query.should == r.with
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'prepares a Batch request' do
|
52
|
+
requests = [ Weary.get('http://twitter.com'),
|
53
|
+
Weary.get('http://github.com'),
|
54
|
+
Weary.get('http://vimeo.com'),
|
55
|
+
Weary.get('http://tumblr.com')]
|
56
|
+
Weary.batch(requests).class.should == Weary::Batch
|
57
|
+
end
|
4
58
|
end
|
data/weary.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{weary}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Wunsch"]
|
12
|
-
s.date = %q{2009-12-
|
13
|
-
s.description = %q{
|
12
|
+
s.date = %q{2009-12-30}
|
13
|
+
s.description = %q{A tiny DSL that makes the consumption of RESTful web services simple.}
|
14
14
|
s.email = %q{mark@markwunsch.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -22,10 +22,12 @@ Gem::Specification.new do |s|
|
|
22
22
|
"README.md",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
|
+
"examples/batch.rb",
|
25
26
|
"examples/repo.rb",
|
26
27
|
"examples/status.rb",
|
27
28
|
"lib/weary.rb",
|
28
29
|
"lib/weary/base.rb",
|
30
|
+
"lib/weary/batch.rb",
|
29
31
|
"lib/weary/exceptions.rb",
|
30
32
|
"lib/weary/httpverb.rb",
|
31
33
|
"lib/weary/request.rb",
|
@@ -36,6 +38,7 @@ Gem::Specification.new do |s|
|
|
36
38
|
"spec/fixtures/vimeo.json",
|
37
39
|
"spec/spec_helper.rb",
|
38
40
|
"spec/weary/base_spec.rb",
|
41
|
+
"spec/weary/batch_spec.rb",
|
39
42
|
"spec/weary/httpverb_spec.rb",
|
40
43
|
"spec/weary/request_spec.rb",
|
41
44
|
"spec/weary/resource_spec.rb",
|
@@ -52,11 +55,13 @@ Gem::Specification.new do |s|
|
|
52
55
|
s.test_files = [
|
53
56
|
"spec/spec_helper.rb",
|
54
57
|
"spec/weary/base_spec.rb",
|
58
|
+
"spec/weary/batch_spec.rb",
|
55
59
|
"spec/weary/httpverb_spec.rb",
|
56
60
|
"spec/weary/request_spec.rb",
|
57
61
|
"spec/weary/resource_spec.rb",
|
58
62
|
"spec/weary/response_spec.rb",
|
59
63
|
"spec/weary_spec.rb",
|
64
|
+
"examples/batch.rb",
|
60
65
|
"examples/repo.rb",
|
61
66
|
"examples/status.rb"
|
62
67
|
]
|
@@ -68,13 +73,19 @@ Gem::Specification.new do |s|
|
|
68
73
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
69
74
|
s.add_runtime_dependency(%q<crack>, [">= 0.1.2"])
|
70
75
|
s.add_runtime_dependency(%q<oauth>, [">= 0.3.5"])
|
76
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
77
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
71
78
|
else
|
72
79
|
s.add_dependency(%q<crack>, [">= 0.1.2"])
|
73
80
|
s.add_dependency(%q<oauth>, [">= 0.3.5"])
|
81
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
82
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
74
83
|
end
|
75
84
|
else
|
76
85
|
s.add_dependency(%q<crack>, [">= 0.1.2"])
|
77
86
|
s.add_dependency(%q<oauth>, [">= 0.3.5"])
|
87
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
88
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
78
89
|
end
|
79
90
|
end
|
80
91
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Wunsch
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,27 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.3.5
|
34
34
|
version:
|
35
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: fakeweb
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
description: A tiny DSL that makes the consumption of RESTful web services simple.
|
36
56
|
email: mark@markwunsch.com
|
37
57
|
executables: []
|
38
58
|
|
@@ -47,10 +67,12 @@ files:
|
|
47
67
|
- README.md
|
48
68
|
- Rakefile
|
49
69
|
- VERSION
|
70
|
+
- examples/batch.rb
|
50
71
|
- examples/repo.rb
|
51
72
|
- examples/status.rb
|
52
73
|
- lib/weary.rb
|
53
74
|
- lib/weary/base.rb
|
75
|
+
- lib/weary/batch.rb
|
54
76
|
- lib/weary/exceptions.rb
|
55
77
|
- lib/weary/httpverb.rb
|
56
78
|
- lib/weary/request.rb
|
@@ -61,6 +83,7 @@ files:
|
|
61
83
|
- spec/fixtures/vimeo.json
|
62
84
|
- spec/spec_helper.rb
|
63
85
|
- spec/weary/base_spec.rb
|
86
|
+
- spec/weary/batch_spec.rb
|
64
87
|
- spec/weary/httpverb_spec.rb
|
65
88
|
- spec/weary/request_spec.rb
|
66
89
|
- spec/weary/resource_spec.rb
|
@@ -98,10 +121,12 @@ summary: A little DSL for consuming RESTful web services
|
|
98
121
|
test_files:
|
99
122
|
- spec/spec_helper.rb
|
100
123
|
- spec/weary/base_spec.rb
|
124
|
+
- spec/weary/batch_spec.rb
|
101
125
|
- spec/weary/httpverb_spec.rb
|
102
126
|
- spec/weary/request_spec.rb
|
103
127
|
- spec/weary/resource_spec.rb
|
104
128
|
- spec/weary/response_spec.rb
|
105
129
|
- spec/weary_spec.rb
|
130
|
+
- examples/batch.rb
|
106
131
|
- examples/repo.rb
|
107
132
|
- examples/status.rb
|