rest-client 1.6.1 → 1.6.14
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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/AUTHORS +75 -0
- data/Gemfile +7 -0
- data/README.rdoc +52 -21
- data/Rakefile +15 -35
- data/bin/restclient +45 -39
- data/history.md +67 -1
- data/lib/restclient.rb +11 -6
- data/lib/restclient/abstract_response.rb +6 -2
- data/lib/restclient/exceptions.rb +22 -5
- data/lib/restclient/net_http_ext.rb +41 -7
- data/lib/restclient/payload.rb +28 -8
- data/lib/restclient/platform.rb +29 -0
- data/lib/restclient/request.rb +96 -36
- data/lib/restclient/resource.rb +17 -0
- data/lib/restclient/response.rb +3 -1
- data/lib/restclient/version.rb +7 -0
- data/rest-client.gemspec +26 -0
- data/spec/abstract_response_spec.rb +28 -10
- data/spec/base.rb +1 -4
- data/spec/exceptions_spec.rb +31 -12
- data/spec/integration/capath_digicert/244b5494.0 +19 -0
- data/spec/integration/capath_digicert/81b9768f.0 +19 -0
- data/spec/integration/capath_digicert/README +8 -0
- data/spec/integration/capath_digicert/digicert.crt +19 -0
- data/spec/integration/certs/digicert.crt +19 -0
- data/spec/integration/certs/verisign.crt +14 -14
- data/spec/integration/request_spec.rb +54 -4
- data/spec/integration_spec.rb +9 -9
- data/spec/master_shake.jpg +0 -0
- data/spec/payload_spec.rb +60 -35
- data/spec/raw_response_spec.rb +4 -4
- data/spec/request2_spec.rb +22 -4
- data/spec/request_spec.rb +129 -130
- data/spec/resource_spec.rb +30 -18
- data/spec/response_spec.rb +48 -36
- data/spec/restclient_spec.rb +6 -1
- metadata +142 -74
- data/VERSION +0 -1
- data/spec/integration/certs/equifax.crt +0 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 317f1bdcf77b2dae0fe9a08a165a56c71fb9c3d79b71c8d6c5a12cb1e4868a4e
|
4
|
+
data.tar.gz: d2a662189817597ff1fca0e6685cdd5d06bdac1ca72bf9a932f1d7def456b26b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f789e7291285e26aa719119331d0d1a6322ec618a25eb2626a1a8486e3584fb07e52d25dfb7a56972cb495e5e2cad6c67eae5f3da98d66974d51f3c4fc2566f1
|
7
|
+
data.tar.gz: cf43508dbbc1f6977b3e8ad047651591760b8f386e3daa472888fc81f262b3d2669798f847b88fdd7b6f6f77b2a44990688c88efc53e02072bb9f284459c6b41
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format progress --order random
|
data/.travis.yml
ADDED
data/AUTHORS
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
The Ruby REST Client would not be what it is today without the help of
|
2
|
+
the following kind souls:
|
3
|
+
|
4
|
+
Adam Jacob
|
5
|
+
Adam Wiggins
|
6
|
+
Aman Gupta
|
7
|
+
Andy Brody
|
8
|
+
Blake Mizerany
|
9
|
+
Brad Ediger
|
10
|
+
Braintree
|
11
|
+
Brian Donovan
|
12
|
+
Caleb Land
|
13
|
+
Chris Dinn
|
14
|
+
Chris Green
|
15
|
+
Coda Hale
|
16
|
+
Crawford
|
17
|
+
Cyril Rohr
|
18
|
+
Dan Mayer
|
19
|
+
David Backeus
|
20
|
+
Dmitri Dolguikh
|
21
|
+
Dusty Doris
|
22
|
+
Dylan Egan
|
23
|
+
El Draper
|
24
|
+
Evan Smith
|
25
|
+
François Beausoleil
|
26
|
+
Gabriele Cirulli
|
27
|
+
Garry Shutler
|
28
|
+
Giovanni Cappellotto
|
29
|
+
Greg Borenstein
|
30
|
+
Harm Aarts
|
31
|
+
Hiro Asari
|
32
|
+
Hugh McGowan
|
33
|
+
Ian Warshak
|
34
|
+
Ivan Makfinsky
|
35
|
+
James Edward Gray II
|
36
|
+
Jari Bakken
|
37
|
+
Jeff Remer
|
38
|
+
JH. Chabran
|
39
|
+
John Barnette
|
40
|
+
Jon Rowe
|
41
|
+
Jordi Massaguer Pla
|
42
|
+
Juan Alvarez
|
43
|
+
Julien Kirch
|
44
|
+
Justin Coyne
|
45
|
+
Keith Rarick
|
46
|
+
Kenichi Kamiya
|
47
|
+
Kevin Read
|
48
|
+
Kosuke Asami
|
49
|
+
Kyle VanderBeek
|
50
|
+
Lars Gierth
|
51
|
+
Lawrence Leonard Gilbert
|
52
|
+
Lee Jarvis
|
53
|
+
Lennon Day-Reynolds
|
54
|
+
macournoyer
|
55
|
+
Matthew Manning
|
56
|
+
Michael Klett
|
57
|
+
Mike Fletcher
|
58
|
+
Nicholas Wieland
|
59
|
+
Nick Plante
|
60
|
+
Niko Dittmann
|
61
|
+
Oscar Del Ben
|
62
|
+
Pablo Astigarraga
|
63
|
+
Paul Dlug
|
64
|
+
Pedro Belo
|
65
|
+
rafael.ssouza
|
66
|
+
Philip Corliss
|
67
|
+
Rick "technoweenie"
|
68
|
+
Robert Eanes
|
69
|
+
Rodrigo Panachi
|
70
|
+
Syl Turner
|
71
|
+
T. Watanabe
|
72
|
+
Tekin
|
73
|
+
tpresa
|
74
|
+
W. Andrew Loe III
|
75
|
+
Waynn Lue
|
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
= REST Client -- simple DSL for accessing HTTP and REST resources
|
2
2
|
|
3
|
+
Build status: {<img src="https://travis-ci.org/rest-client/rest-client.svg?branch=1.6-legacy" alt="Build Status" />}[https://travis-ci.org/rest-client/rest-client]
|
4
|
+
|
3
5
|
A simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style
|
4
6
|
of specifying actions: get, put, post, delete.
|
5
7
|
|
6
|
-
* Main page:
|
8
|
+
* Main page: https://github.com/rest-client/rest-client
|
7
9
|
* Mailing list: rest.client@librelist.com (send a mail to subscribe).
|
8
|
-
* IRC: #rest-client at freenode
|
9
10
|
|
10
11
|
== Usage: Raw URL
|
11
12
|
|
12
13
|
require 'rest_client'
|
13
14
|
|
14
15
|
RestClient.get 'http://example.com/resource'
|
15
|
-
|
16
|
+
|
16
17
|
RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
|
17
18
|
|
18
19
|
RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json}
|
@@ -79,10 +80,10 @@ See RestClient::Resource docs for details.
|
|
79
80
|
|
80
81
|
== Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
|
81
82
|
|
82
|
-
* for
|
83
|
-
* for
|
84
|
-
* for result code 303 the redirection will be followed and the request transformed into a
|
85
|
-
* for other cases a RestClient::Exception holding the Response will be raised
|
83
|
+
* for result codes between 200 and 207, a RestClient::Response will be returned
|
84
|
+
* for result codes 301, 302 or 307, the redirection will be followed if the request is a GET or a HEAD
|
85
|
+
* for result code 303, the redirection will be followed and the request transformed into a GET
|
86
|
+
* for other cases, a RestClient::Exception holding the Response will be raised; a specific exception class will be thrown for known error codes
|
86
87
|
|
87
88
|
RestClient.get 'http://example.com/resource'
|
88
89
|
➔ RestClient::ResourceNotFound: RestClient::ResourceNotFound
|
@@ -96,7 +97,7 @@ See RestClient::Resource docs for details.
|
|
96
97
|
|
97
98
|
== Result handling
|
98
99
|
|
99
|
-
A block can be passed to the RestClient method
|
100
|
+
A block can be passed to the RestClient method. This block will then be called with the Response.
|
100
101
|
Response.return! can be called to invoke the default response's behavior.
|
101
102
|
|
102
103
|
# Don't raise exceptions but return the response
|
@@ -128,16 +129,25 @@ Response.return! can be called to invoke the default response's behavior.
|
|
128
129
|
end
|
129
130
|
}
|
130
131
|
|
131
|
-
== Non-normalized URIs
|
132
|
+
== Non-normalized URIs
|
132
133
|
|
133
|
-
If you
|
134
|
+
If you need to normalize URIs, e.g. to work with International Resource Identifiers (IRIs),
|
135
|
+
use the addressable gem (http://addressable.rubyforge.org/api/) in your code:
|
134
136
|
|
135
137
|
require 'addressable/uri'
|
136
138
|
RestClient.get(Addressable::URI.parse("http://www.詹姆斯.com/").normalize.to_str)
|
137
139
|
|
138
140
|
== Lower-level access
|
139
141
|
|
140
|
-
For cases not covered by the general API, you can use the RestClient::
|
142
|
+
For cases not covered by the general API, you can use the RestClient::Request class, which provides a lower-level API.
|
143
|
+
|
144
|
+
You can:
|
145
|
+
|
146
|
+
* specify ssl parameters
|
147
|
+
* override cookies
|
148
|
+
* manually handle the response (e.g. to operate on it as a stream rather than reading it all into memory)
|
149
|
+
|
150
|
+
See RestClient::Request's documentation for more information.
|
141
151
|
|
142
152
|
== Shell
|
143
153
|
|
@@ -179,10 +189,10 @@ Use as a one-off, curl-style:
|
|
179
189
|
|
180
190
|
== Logging
|
181
191
|
|
182
|
-
To enable logging you can
|
192
|
+
To enable logging you can:
|
183
193
|
|
184
|
-
* set RestClient.log with a
|
185
|
-
*
|
194
|
+
* set RestClient.log with a Ruby Logger, or
|
195
|
+
* set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
|
186
196
|
|
187
197
|
$ RESTCLIENT_LOG=stdout path/to/my/program
|
188
198
|
|
@@ -205,11 +215,19 @@ RestClient.proxy:
|
|
205
215
|
RestClient.get "http://some/resource"
|
206
216
|
# => response from some/resource as proxied through proxy.example.com
|
207
217
|
|
208
|
-
Often the proxy
|
218
|
+
Often the proxy URL is set in an environment variable, so you can do this to
|
209
219
|
use whatever proxy the system is configured to use:
|
210
220
|
|
211
221
|
RestClient.proxy = ENV['http_proxy']
|
212
222
|
|
223
|
+
== Query parameters
|
224
|
+
|
225
|
+
Request objects know about query parameters and will automatically add them to
|
226
|
+
the URL for GET, HEAD and DELETE requests, escaping the keys and values as needed:
|
227
|
+
|
228
|
+
RestClient.get 'http://example.com/resource', :params => {:foo => 'bar', :baz => 'qux'}
|
229
|
+
# will GET http://example.com/resource?foo=bar&baz=qux
|
230
|
+
|
213
231
|
== Cookies
|
214
232
|
|
215
233
|
Request and Response objects know about HTTP cookies, and will automatically
|
@@ -240,11 +258,12 @@ Self-signed certificates can be generated with the openssl command-line tool.
|
|
240
258
|
|
241
259
|
== Hook
|
242
260
|
|
243
|
-
RestClient.add_before_execution_proc add a Proc to be called before each execution
|
261
|
+
RestClient.add_before_execution_proc add a Proc to be called before each execution.
|
262
|
+
It's handy if you need direct access to the HTTP request.
|
244
263
|
|
245
264
|
Example:
|
246
265
|
|
247
|
-
# Add
|
266
|
+
# Add oauth support using the oauth gem
|
248
267
|
require 'oauth'
|
249
268
|
access_token = ...
|
250
269
|
|
@@ -256,14 +275,26 @@ Example:
|
|
256
275
|
|
257
276
|
== More
|
258
277
|
|
259
|
-
Need caching, more advanced logging or any ability provided by
|
278
|
+
Need caching, more advanced logging or any ability provided by Rack middleware?
|
279
|
+
|
280
|
+
Have a look at rest-client-components: http://github.com/crohr/rest-client-components
|
281
|
+
|
282
|
+
== Credits
|
260
283
|
|
261
|
-
|
284
|
+
REST Client Team:: Matthew Manning, Lawrence Leonard Gilbert, Andy Brody
|
262
285
|
|
263
|
-
|
286
|
+
Creator:: Adam Wiggins
|
264
287
|
|
265
|
-
|
288
|
+
Maintainer Emeritus:: Julien Kirch
|
289
|
+
|
290
|
+
Major contributions:: Blake Mizerany, Julien Kirch
|
266
291
|
|
267
292
|
Patches contributed by many, including Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, François Beausoleil and Nick Plante.
|
268
293
|
|
294
|
+
== Legal
|
295
|
+
|
269
296
|
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
297
|
+
|
298
|
+
"Master Shake" photo (http://www.flickr.com/photos/solgrundy/924205581/) by
|
299
|
+
"SolGrundy"; used under terms of the Creative Commons Attribution-ShareAlike 2.0
|
300
|
+
Generic license (http://creativecommons.org/licenses/by-sa/2.0/)
|
data/Rakefile
CHANGED
@@ -1,53 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
Jeweler::Tasks.new do |s|
|
6
|
-
s.name = "rest-client"
|
7
|
-
s.description = "A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
|
8
|
-
s.summary = "Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions."
|
9
|
-
s.author = "Adam Wiggins"
|
10
|
-
s.email = "rest.client@librelist.com"
|
11
|
-
s.homepage = "http://github.com/archiloque/rest-client"
|
12
|
-
s.rubyforge_project = "rest-client"
|
13
|
-
s.has_rdoc = true
|
14
|
-
s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
|
15
|
-
s.executables = %w(restclient)
|
16
|
-
s.add_dependency("mime-types", ">= 1.16")
|
17
|
-
s.add_development_dependency("webmock", ">= 0.9.1")
|
18
|
-
s.add_development_dependency("rspec")
|
1
|
+
begin
|
2
|
+
# optionally load `rake build/install/release tasks'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
rescue LoadError
|
19
5
|
end
|
20
6
|
|
21
|
-
|
22
|
-
|
23
|
-
############################
|
24
|
-
|
25
|
-
require 'spec/rake/spectask'
|
7
|
+
require "rspec/core/rake_task"
|
26
8
|
|
27
9
|
desc "Run all specs"
|
28
10
|
task :spec => ["spec:unit", "spec:integration"]
|
29
11
|
|
30
12
|
desc "Run unit specs"
|
31
|
-
|
32
|
-
t.
|
33
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
13
|
+
RSpec::Core::RakeTask.new('spec:unit') do |t|
|
14
|
+
t.pattern = ['spec/*_spec.rb']
|
34
15
|
end
|
35
16
|
|
36
17
|
desc "Run integration specs"
|
37
|
-
|
38
|
-
t.
|
39
|
-
t.spec_files = FileList['spec/integration/*_spec.rb']
|
18
|
+
RSpec::Core::RakeTask.new('spec:integration') do |t|
|
19
|
+
t.pattern = ['spec/integration/*_spec.rb']
|
40
20
|
end
|
41
21
|
|
42
22
|
desc "Print specdocs"
|
43
|
-
|
44
|
-
t.
|
45
|
-
t.
|
23
|
+
RSpec::Core::RakeTask.new(:doc) do |t|
|
24
|
+
t.rspec_opts = ["--format", "specdoc", "--dry-run"]
|
25
|
+
t.pattern = ['spec/*_spec.rb']
|
46
26
|
end
|
47
27
|
|
48
28
|
desc "Run all examples with RCov"
|
49
|
-
|
50
|
-
t.
|
29
|
+
RSpec::Core::RakeTask.new('rcov') do |t|
|
30
|
+
t.pattern = ['spec/*_spec.rb']
|
51
31
|
t.rcov = true
|
52
32
|
t.rcov_opts = ['--exclude', 'examples']
|
53
33
|
end
|
@@ -56,7 +36,7 @@ task :default => :spec
|
|
56
36
|
|
57
37
|
############################
|
58
38
|
|
59
|
-
require '
|
39
|
+
require 'rdoc/task'
|
60
40
|
|
61
41
|
Rake::RDocTask.new do |t|
|
62
42
|
t.rdoc_dir = 'rdoc'
|
data/bin/restclient
CHANGED
@@ -1,22 +1,25 @@
|
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
puts "failed for reason: #{why}" if why
|
11
|
+
puts "usage: restclient [get|put|post|delete] url|name [username] [password]"
|
12
|
+
puts " The verb is optional, if you leave it off you'll get an interactive shell."
|
13
|
+
puts " put and post both take the input body on stdin."
|
14
|
+
exit(1)
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
POSSIBLE_VERBS = ['get', 'put', 'post', 'delete']
|
18
|
+
|
19
|
+
if POSSIBLE_VERBS.include? ARGV.first
|
20
|
+
@verb = ARGV.shift
|
18
21
|
else
|
19
|
-
|
22
|
+
@verb = nil
|
20
23
|
end
|
21
24
|
|
22
25
|
@url = ARGV.shift || 'http://localhost:4567'
|
@@ -24,61 +27,64 @@ end
|
|
24
27
|
config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
|
25
28
|
|
26
29
|
@url, @username, @password = if c = config[@url]
|
27
|
-
|
30
|
+
[c['url'], c['username'], c['password']]
|
28
31
|
else
|
29
|
-
|
32
|
+
[@url, * ARGV]
|
30
33
|
end
|
31
34
|
|
32
35
|
usage("invalid url '#{@url}") unless @url =~ /^https?/
|
33
36
|
usage("too few args") unless ARGV.size < 3
|
34
37
|
|
35
38
|
def r
|
36
|
-
|
39
|
+
@r ||= RestClient::Resource.new(@url, @username, @password)
|
37
40
|
end
|
38
41
|
|
39
42
|
r # force rc to load
|
40
43
|
|
41
44
|
if @verb
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
begin
|
46
|
+
if %w( put post ).include? @verb
|
47
|
+
puts r.send(@verb, STDIN.read)
|
48
|
+
else
|
49
|
+
puts r.send(@verb)
|
50
|
+
end
|
51
|
+
exit 0
|
52
|
+
rescue RestClient::Exception => e
|
53
|
+
puts e.response.body if e.respond_to? :response
|
54
|
+
raise
|
55
|
+
end
|
53
56
|
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
def
|
58
|
+
POSSIBLE_VERBS.each do |m|
|
59
|
+
eval <<-end_eval
|
60
|
+
def #{m}(path, *args, &b)
|
58
61
|
r[path].#{m}(*args, &b)
|
59
62
|
end
|
60
|
-
|
63
|
+
end_eval
|
61
64
|
end
|
62
65
|
|
63
|
-
def method_missing(s, *args, &b)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
def method_missing(s, * args, & b)
|
67
|
+
if POSSIBLE_VERBS.include? s
|
68
|
+
begin
|
69
|
+
r.send(s, *args, & b)
|
70
|
+
rescue RestClient::RequestFailed => e
|
71
|
+
print STDERR, e.response.body
|
72
|
+
raise e
|
73
|
+
end
|
74
|
+
else
|
75
|
+
super
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
79
|
require 'irb'
|
74
80
|
require 'irb/completion'
|
75
81
|
|
76
82
|
if File.exists? ".irbrc"
|
77
|
-
|
83
|
+
ENV['IRBRC'] = ".irbrc"
|
78
84
|
end
|
79
85
|
|
80
|
-
if File.exists?(
|
81
|
-
|
86
|
+
if File.exists?(File.expand_path(rcfile = "~/.restclientrc"))
|
87
|
+
load(rcfile)
|
82
88
|
end
|
83
89
|
|
84
90
|
ARGV.clear
|