rest-client 1.6.3 → 1.6.5
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.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/bin/restclient +5 -4
- data/history.md +12 -0
- data/lib/restclient/payload.rb +16 -1
- data/lib/restclient/request.rb +19 -19
- data/spec/integration/request_spec.rb +4 -4
- data/spec/payload_spec.rb +21 -16
- data/spec/request_spec.rb +1 -1
- metadata +49 -75
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.5
|
data/bin/restclient
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
$:.unshift File.dirname(__FILE__) + "/../lib"
|
4
|
-
require 'restclient'
|
5
4
|
|
6
|
-
require
|
5
|
+
require 'rubygems'
|
6
|
+
require 'restclient'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
def usage(why = nil)
|
9
10
|
puts "failed for reason: #{why}" if why
|
@@ -56,8 +57,8 @@ end
|
|
56
57
|
|
57
58
|
POSSIBLE_VERBS.each do |m|
|
58
59
|
eval <<-end_eval
|
59
|
-
def #{m}
|
60
|
-
r[path]
|
60
|
+
def #{m}(path, *args, &b)
|
61
|
+
r[path].#{m}(*args, &b)
|
61
62
|
end
|
62
63
|
end_eval
|
63
64
|
end
|
data/history.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
+
# 1.6.5
|
2
|
+
|
3
|
+
- RFC6265 requires single SP after ';' for separating parameters pairs in the 'Cookie:' header (patch provided by Hiroshi Nakamura)
|
4
|
+
- enable url parameters for all actions
|
5
|
+
- detect file parameters in arrays
|
6
|
+
- allow disabling the timeouts by passing -1 (patch provided by Sven Böhm)
|
7
|
+
|
8
|
+
# 1.6.4
|
9
|
+
|
10
|
+
- fix restclient script compatibility with 1.9.2
|
11
|
+
|
1
12
|
# 1.6.3
|
13
|
+
|
2
14
|
- 1.6.2 was yanked
|
3
15
|
|
4
16
|
# 1.6.2
|
data/lib/restclient/payload.rb
CHANGED
@@ -27,12 +27,27 @@ module RestClient
|
|
27
27
|
case v
|
28
28
|
when Hash
|
29
29
|
has_file?(v)
|
30
|
+
when Array
|
31
|
+
has_file_array?(v)
|
30
32
|
else
|
31
33
|
v.respond_to?(:path) && v.respond_to?(:read)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
38
|
+
def has_file_array?(params)
|
39
|
+
params.any? do |v|
|
40
|
+
case v
|
41
|
+
when Hash
|
42
|
+
has_file?(v)
|
43
|
+
when Array
|
44
|
+
has_file_array?(v)
|
45
|
+
else
|
46
|
+
v.respond_to?(:path) && v.respond_to?(:read)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
class Base
|
37
52
|
def initialize(params)
|
38
53
|
build_stream(params)
|
@@ -70,7 +85,7 @@ module RestClient
|
|
70
85
|
result = []
|
71
86
|
value.each do |elem|
|
72
87
|
if elem.is_a? Hash
|
73
|
-
result +=
|
88
|
+
result += flatten_params(elem, calculated_key)
|
74
89
|
elsif elem.is_a? Array
|
75
90
|
result += flatten_params_array(elem, calculated_key)
|
76
91
|
else
|
data/lib/restclient/request.rb
CHANGED
@@ -20,7 +20,7 @@ module RestClient
|
|
20
20
|
# * :raw_response return a low-level RawResponse instead of a Response
|
21
21
|
# * :max_redirects maximum number of redirections (default to 10)
|
22
22
|
# * :verify_ssl enable ssl verification, possible values are constants from OpenSSL::SSL
|
23
|
-
# * :timeout and :open_timeout
|
23
|
+
# * :timeout and :open_timeout passing in -1 will disable the timeout by setting the corresponding net timeout values to nil
|
24
24
|
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file
|
25
25
|
class Request
|
26
26
|
|
@@ -37,7 +37,7 @@ module RestClient
|
|
37
37
|
@method = args[:method] or raise ArgumentError, "must pass :method"
|
38
38
|
@headers = args[:headers] || {}
|
39
39
|
if args[:url]
|
40
|
-
@url =
|
40
|
+
@url = process_url_params(args[:url], headers)
|
41
41
|
else
|
42
42
|
raise ArgumentError, "must pass :url"
|
43
43
|
end
|
@@ -64,24 +64,20 @@ module RestClient
|
|
64
64
|
transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
|
65
65
|
end
|
66
66
|
|
67
|
-
# Extract the query parameters
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
true
|
75
|
-
else
|
76
|
-
false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
unless get_params.empty?
|
80
|
-
query_string = get_params.collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
81
|
-
url + "?#{query_string}"
|
67
|
+
# Extract the query parameters and append them to the url
|
68
|
+
def process_url_params url, headers
|
69
|
+
url_params = {}
|
70
|
+
headers.delete_if do |key, value|
|
71
|
+
if 'params' == key.to_s.downcase && value.is_a?(Hash)
|
72
|
+
url_params.merge! value
|
73
|
+
true
|
82
74
|
else
|
83
|
-
|
75
|
+
false
|
84
76
|
end
|
77
|
+
end
|
78
|
+
unless url_params.empty?
|
79
|
+
query_string = url_params.collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
80
|
+
url + "?#{query_string}"
|
85
81
|
else
|
86
82
|
url
|
87
83
|
end
|
@@ -89,7 +85,7 @@ module RestClient
|
|
89
85
|
|
90
86
|
def make_headers user_headers
|
91
87
|
unless @cookies.empty?
|
92
|
-
user_headers[:cookie] = @cookies.map { |(key, val)| "#{key.to_s}=#{CGI::unescape(val)}" }.sort.join(';')
|
88
|
+
user_headers[:cookie] = @cookies.map { |(key, val)| "#{key.to_s}=#{CGI::unescape(val)}" }.sort.join('; ')
|
93
89
|
end
|
94
90
|
headers = stringify_headers(default_headers).merge(stringify_headers(user_headers))
|
95
91
|
headers.merge!(@payload.headers) if @payload
|
@@ -161,6 +157,10 @@ module RestClient
|
|
161
157
|
net.read_timeout = @timeout if @timeout
|
162
158
|
net.open_timeout = @open_timeout if @open_timeout
|
163
159
|
|
160
|
+
# disable the timeout if the timeout value is -1
|
161
|
+
net.read_timeout = nil if @timeout == -1
|
162
|
+
net.out_timeout = nil if @open_timeout == -1
|
163
|
+
|
164
164
|
RestClient.before_execution_procs.each do |before_proc|
|
165
165
|
before_proc.call(req, args)
|
166
166
|
end
|
@@ -5,9 +5,9 @@ describe RestClient::Request do
|
|
5
5
|
it "is successful with the correct ca_file" do
|
6
6
|
request = RestClient::Request.new(
|
7
7
|
:method => :get,
|
8
|
-
:url => 'https://www.
|
8
|
+
:url => 'https://www.mozilla.com',
|
9
9
|
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
10
|
-
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "
|
10
|
+
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "equifax.crt")
|
11
11
|
)
|
12
12
|
expect { request.execute }.to_not raise_error
|
13
13
|
end
|
@@ -15,9 +15,9 @@ describe RestClient::Request do
|
|
15
15
|
it "is unsuccessful with an incorrect ca_file" do
|
16
16
|
request = RestClient::Request.new(
|
17
17
|
:method => :get,
|
18
|
-
:url => 'https://www.
|
18
|
+
:url => 'https://www.mozilla.com',
|
19
19
|
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
20
|
-
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "
|
20
|
+
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt")
|
21
21
|
)
|
22
22
|
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
23
23
|
end
|
data/spec/payload_spec.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require File.join(
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'base')
|
2
2
|
|
3
3
|
describe RestClient::Payload do
|
4
4
|
context "A regular Payload" do
|
5
5
|
it "should use standard enctype as default content-type" do
|
6
6
|
RestClient::Payload::UrlEncoded.new({}).headers['Content-Type'].
|
7
|
-
|
7
|
+
should == 'application/x-www-form-urlencoded'
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should form properly encoded params" do
|
11
11
|
RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s.
|
12
|
-
|
12
|
+
should == "foo=bar"
|
13
13
|
["foo=bar&baz=qux", "baz=qux&foo=bar"].should include(
|
14
|
-
|
14
|
+
RestClient::Payload::UrlEncoded.new({:foo => 'bar', :baz => 'qux'}).to_s)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should escape parameters" do
|
18
18
|
RestClient::Payload::UrlEncoded.new({'foo ' => 'bar'}).to_s.
|
19
|
-
|
19
|
+
should == "foo%20=bar"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should properly handle hashes as parameter" do
|
23
|
-
RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'
|
24
|
-
|
25
|
-
RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'
|
26
|
-
|
23
|
+
RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'}}).to_s.
|
24
|
+
should == "foo[bar]=baz"
|
25
|
+
RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'}}}).to_s.
|
26
|
+
should == "foo[bar][baz]=qux"
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should handle many attributes inside a hash" do
|
@@ -37,22 +37,22 @@ describe RestClient::Payload do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should handle attributes inside a an array inside an array inside an hash" do
|
40
|
-
parameters = RestClient::Payload::UrlEncoded.new({"foo" => [
|
40
|
+
parameters = RestClient::Payload::UrlEncoded.new({"foo" => [[{"bar" => 'baz'}, {"bar" => 'qux'}]]}).to_s
|
41
41
|
parameters.should include("foo[bar]=baz", "foo[bar]=qux")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should form properly use symbols as parameters" do
|
45
45
|
RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
|
46
|
-
|
47
|
-
RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz
|
48
|
-
|
46
|
+
should == "foo=bar"
|
47
|
+
RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz}}).to_s.
|
48
|
+
should == "foo[bar]=baz"
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should properly handle arrays as repeated parameters" do
|
52
52
|
RestClient::Payload::UrlEncoded.new({:foo => ['bar']}).to_s.
|
53
|
-
|
53
|
+
should == "foo[]=bar"
|
54
54
|
RestClient::Payload::UrlEncoded.new({:foo => ['bar', 'baz']}).to_s.
|
55
|
-
|
55
|
+
should == "foo[]=bar&foo[]=baz"
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -202,11 +202,16 @@ Content-Type: text/plain\r
|
|
202
202
|
RestClient::Payload.generate("data").should be_kind_of(RestClient::Payload::Base)
|
203
203
|
end
|
204
204
|
|
205
|
-
it "should recognize nested multipart payloads" do
|
205
|
+
it "should recognize nested multipart payloads in hashes" do
|
206
206
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
207
207
|
RestClient::Payload.generate({"foo" => {"file" => f}}).should be_kind_of(RestClient::Payload::Multipart)
|
208
208
|
end
|
209
209
|
|
210
|
+
it "should recognize nested multipart payloads in arrays" do
|
211
|
+
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
212
|
+
RestClient::Payload.generate({"foo" => [f]}).should be_kind_of(RestClient::Payload::Multipart)
|
213
|
+
end
|
214
|
+
|
210
215
|
it "should recognize file payloads that can be streamed" do
|
211
216
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
212
217
|
RestClient::Payload.generate(f).should be_kind_of(RestClient::Payload::Streamed)
|
data/spec/request_spec.rb
CHANGED
@@ -106,7 +106,7 @@ describe RestClient::Request do
|
|
106
106
|
URI.stub!(:parse).and_return(mock('uri', :user => nil, :password => nil))
|
107
107
|
@request = RestClient::Request.new(:method => 'get', :url => 'example.com', :cookies => {:session_id => '1', :user_id => "someone" })
|
108
108
|
@request.should_receive(:default_headers).and_return({'Foo' => 'bar'})
|
109
|
-
@request.make_headers({}).should == { 'Foo' => 'bar', 'Cookie' => 'session_id=1;user_id=someone'}
|
109
|
+
@request.make_headers({}).should == { 'Foo' => 'bar', 'Cookie' => 'session_id=1; user_id=someone'}
|
110
110
|
end
|
111
111
|
|
112
112
|
it "determines the Net::HTTP class to instantiate by the method name" do
|
metadata
CHANGED
@@ -1,78 +1,60 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 6
|
9
|
-
- 3
|
10
|
-
version: 1.6.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Adam Wiggins
|
14
9
|
- Julien Kirch
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2011-08-22 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: mime-types
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &2156612920 !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 16
|
33
|
-
version: "1.16"
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.16'
|
34
23
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: webmock
|
38
24
|
prerelease: false
|
39
|
-
|
25
|
+
version_requirements: *2156612920
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: webmock
|
28
|
+
requirement: &2156612280 !ruby/object:Gem::Requirement
|
40
29
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 57
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 9
|
48
|
-
- 1
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
49
33
|
version: 0.9.1
|
50
34
|
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: rspec
|
54
35
|
prerelease: false
|
55
|
-
|
36
|
+
version_requirements: *2156612280
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &2156611740 !ruby/object:Gem::Requirement
|
56
40
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
64
45
|
type: :development
|
65
|
-
|
66
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2156611740
|
48
|
+
description: ! 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework
|
49
|
+
style of specifying actions: get, put, post, delete.'
|
67
50
|
email: rest.client@librelist.com
|
68
|
-
executables:
|
51
|
+
executables:
|
69
52
|
- restclient
|
70
53
|
extensions: []
|
71
|
-
|
72
|
-
extra_rdoc_files:
|
54
|
+
extra_rdoc_files:
|
73
55
|
- README.rdoc
|
74
56
|
- history.md
|
75
|
-
files:
|
57
|
+
files:
|
76
58
|
- README.rdoc
|
77
59
|
- Rakefile
|
78
60
|
- VERSION
|
@@ -106,38 +88,30 @@ files:
|
|
106
88
|
- history.md
|
107
89
|
homepage: http://github.com/archiloque/rest-client
|
108
90
|
licenses: []
|
109
|
-
|
110
91
|
post_install_message:
|
111
92
|
rdoc_options: []
|
112
|
-
|
113
|
-
require_paths:
|
93
|
+
require_paths:
|
114
94
|
- lib
|
115
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
96
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
|
122
|
-
- 0
|
123
|
-
version: "0"
|
124
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
102
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
segments:
|
131
|
-
- 0
|
132
|
-
version: "0"
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
133
107
|
requirements: []
|
134
|
-
|
135
108
|
rubyforge_project:
|
136
|
-
rubygems_version: 1.8.
|
109
|
+
rubygems_version: 1.8.8
|
137
110
|
signing_key:
|
138
111
|
specification_version: 3
|
139
|
-
summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
|
140
|
-
|
112
|
+
summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
|
113
|
+
specifying actions.
|
114
|
+
test_files:
|
141
115
|
- spec/abstract_response_spec.rb
|
142
116
|
- spec/base.rb
|
143
117
|
- spec/exceptions_spec.rb
|