rest-client 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- data/README.rdoc +3 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/restclient.rb +32 -31
- data/lib/restclient/exceptions.rb +70 -69
- data/lib/restclient/mixin/response.rb +40 -40
- data/lib/restclient/net_http_ext.rb +11 -11
- data/lib/restclient/payload.rb +175 -168
- data/lib/restclient/raw_response.rb +22 -22
- data/lib/restclient/request.rb +283 -248
- data/lib/restclient/resource.rb +132 -132
- data/lib/restclient/response.rb +13 -13
- data/spec/exceptions_spec.rb +45 -45
- data/spec/mixin/response_spec.rb +38 -38
- data/spec/payload_spec.rb +92 -92
- data/spec/raw_response_spec.rb +11 -11
- data/spec/request_spec.rb +517 -493
- data/spec/resource_spec.rb +57 -57
- data/spec/response_spec.rb +15 -15
- data/spec/restclient_spec.rb +49 -49
- metadata +2 -2
data/spec/resource_spec.rb
CHANGED
@@ -1,75 +1,75 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
|
3
3
|
describe RestClient::Resource do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
before do
|
5
|
+
@resource = RestClient::Resource.new('http://some/resource', :user => 'jane', :password => 'mypass', :headers => { 'X-Something' => '1'})
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
context "Resource delegation" do
|
9
|
+
it "GET" do
|
10
|
+
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => { 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
11
|
+
@resource.get
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
it "POST" do
|
15
|
+
RestClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'abc', :headers => { :content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
16
|
+
@resource.post 'abc', :content_type => 'image/jpg'
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
it "PUT" do
|
20
|
+
RestClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'abc', :headers => { :content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
21
|
+
@resource.put 'abc', :content_type => 'image/jpg'
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
it "DELETE" do
|
25
|
+
RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => { 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
26
|
+
@resource.delete
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
it "overrides resource headers" do
|
30
|
+
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => { 'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
|
31
|
+
@resource.get 'X-Something' => '2'
|
32
|
+
end
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
it "can instantiate with no user/password" do
|
36
|
+
@resource = RestClient::Resource.new('http://some/resource')
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
it "is backwards compatible with previous constructor" do
|
40
|
+
@resource = RestClient::Resource.new('http://some/resource', 'user', 'pass')
|
41
|
+
@resource.user.should == 'user'
|
42
|
+
@resource.password.should == 'pass'
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
it "concatenates urls, inserting a slash when it needs one" do
|
46
|
+
@resource.concat_urls('http://example.com', 'resource').should == 'http://example.com/resource'
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
it "concatenates urls, using no slash if the first url ends with a slash" do
|
50
|
+
@resource.concat_urls('http://example.com/', 'resource').should == 'http://example.com/resource'
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
it "concatenates urls, using no slash if the second url starts with a slash" do
|
54
|
+
@resource.concat_urls('http://example.com', '/resource').should == 'http://example.com/resource'
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
it "concatenates even non-string urls, :posts + 1 => 'posts/1'" do
|
58
|
+
@resource.concat_urls(:posts, 1).should == 'posts/1'
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
it "offers subresources via []" do
|
62
|
+
parent = RestClient::Resource.new('http://example.com')
|
63
|
+
parent['posts'].url.should == 'http://example.com/posts'
|
64
|
+
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
it "transports options to subresources" do
|
67
|
+
parent = RestClient::Resource.new('http://example.com', :user => 'user', :password => 'password')
|
68
|
+
parent['posts'].user.should == 'user'
|
69
|
+
parent['posts'].password.should == 'password'
|
70
|
+
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
it "prints its url with to_s" do
|
73
|
+
RestClient::Resource.new('x').to_s.should == 'x'
|
74
|
+
end
|
75
75
|
end
|
data/spec/response_spec.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
|
3
3
|
describe RestClient::Response do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
before do
|
5
|
+
@net_http_res = mock('net http response', :to_hash => {"Status" => ["200 OK"]})
|
6
|
+
@response = RestClient::Response.new('abc', @net_http_res)
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
it "behaves like string" do
|
10
|
+
@response.should == 'abc'
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
it "accepts nil strings and sets it to empty for the case of HEAD" do
|
14
|
+
RestClient::Response.new(nil, @net_http_res).should == ""
|
15
|
+
end
|
16
|
+
|
17
|
+
it "test headers and raw headers" do
|
18
|
+
@response.raw_headers["Status"][0].should == "200 OK"
|
19
|
+
@response.headers[:status].should == "200 OK"
|
20
|
+
end
|
21
21
|
end
|
data/spec/restclient_spec.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
|
3
3
|
describe RestClient do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
4
|
+
describe "API" do
|
5
|
+
it "GET" do
|
6
|
+
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
|
7
|
+
RestClient.get('http://some/resource')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "POST" do
|
11
|
+
RestClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
12
|
+
RestClient.post('http://some/resource', 'payload')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "PUT" do
|
16
|
+
RestClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
17
|
+
RestClient.put('http://some/resource', 'payload')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "DELETE" do
|
21
|
+
RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
|
22
|
+
RestClient.delete('http://some/resource')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "HEAD" do
|
26
|
+
RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
|
27
|
+
RestClient.head('http://some/resource')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "logging" do
|
32
|
+
after do
|
33
|
+
RestClient.log = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "gets the log source from the RESTCLIENT_LOG environment variable" do
|
37
|
+
ENV.stub!(:[]).with('RESTCLIENT_LOG').and_return('from env')
|
38
|
+
RestClient.log = 'from class method'
|
39
|
+
RestClient.log.should == 'from env'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets a destination for log output, used if no environment variable is set" do
|
43
|
+
ENV.stub!(:[]).with('RESTCLIENT_LOG').and_return(nil)
|
44
|
+
RestClient.log = 'from class method'
|
45
|
+
RestClient.log.should == 'from class method'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns nil (no logging) if neither are set (default)" do
|
49
|
+
ENV.stub!(:[]).with('RESTCLIENT_LOG').and_return(nil)
|
50
|
+
RestClient.log.should == nil
|
51
|
+
end
|
52
|
+
end
|
53
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2010-01-03 00:00:00 +01:00
|
14
14
|
default_executable: restclient
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|