rest-client 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.

Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +3 -0
  5. data/AUTHORS +75 -0
  6. data/Gemfile +7 -0
  7. data/README.rdoc +300 -0
  8. data/Rakefile +49 -0
  9. data/bin/restclient +93 -0
  10. data/history.md +160 -0
  11. data/lib/rest-client.rb +2 -0
  12. data/lib/rest_client.rb +2 -0
  13. data/lib/restclient.rb +170 -0
  14. data/lib/restclient/abstract_response.rb +106 -0
  15. data/lib/restclient/exceptions.rb +198 -0
  16. data/lib/restclient/net_http_ext.rb +55 -0
  17. data/lib/restclient/payload.rb +240 -0
  18. data/lib/restclient/platform.rb +29 -0
  19. data/lib/restclient/raw_response.rb +34 -0
  20. data/lib/restclient/request.rb +360 -0
  21. data/lib/restclient/resource.rb +169 -0
  22. data/lib/restclient/response.rb +26 -0
  23. data/lib/restclient/version.rb +7 -0
  24. data/rest-client.gemspec +26 -0
  25. data/spec/abstract_response_spec.rb +85 -0
  26. data/spec/base.rb +13 -0
  27. data/spec/exceptions_spec.rb +98 -0
  28. data/spec/integration/capath_digicert/244b5494.0 +19 -0
  29. data/spec/integration/capath_digicert/81b9768f.0 +19 -0
  30. data/spec/integration/capath_digicert/README +8 -0
  31. data/spec/integration/capath_digicert/digicert.crt +19 -0
  32. data/spec/integration/certs/digicert.crt +19 -0
  33. data/spec/integration/certs/verisign.crt +14 -0
  34. data/spec/integration/request_spec.rb +75 -0
  35. data/spec/integration_spec.rb +38 -0
  36. data/spec/master_shake.jpg +0 -0
  37. data/spec/payload_spec.rb +244 -0
  38. data/spec/raw_response_spec.rb +17 -0
  39. data/spec/request2_spec.rb +35 -0
  40. data/spec/request_spec.rb +528 -0
  41. data/spec/resource_spec.rb +136 -0
  42. data/spec/response_spec.rb +169 -0
  43. data/spec/restclient_spec.rb +73 -0
  44. metadata +192 -0
@@ -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
@@ -0,0 +1,8 @@
1
+ .idea
2
+ .rvmrc
3
+ doc
4
+ rdoc
5
+ pkg
6
+ *.gem
7
+ scratchpad.rb
8
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format progress --order random
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
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
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ end
@@ -0,0 +1,300 @@
1
+ = REST Client -- simple DSL for accessing HTTP and REST resources
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
+
5
+ A simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style
6
+ of specifying actions: get, put, post, delete.
7
+
8
+ * Main page: https://github.com/rest-client/rest-client
9
+ * Mailing list: rest.client@librelist.com (send a mail to subscribe).
10
+
11
+ == Usage: Raw URL
12
+
13
+ require 'rest_client'
14
+
15
+ RestClient.get 'http://example.com/resource'
16
+
17
+ RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
18
+
19
+ RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json}
20
+
21
+ RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
22
+
23
+ RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
24
+
25
+ RestClient.delete 'http://example.com/resource'
26
+
27
+ response = RestClient.get 'http://example.com/resource'
28
+ response.code
29
+ ➔ 200
30
+ response.cookies
31
+ ➔ {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
32
+ response.headers
33
+ ➔ {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
34
+ response.to_str
35
+ ➔ \n<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html ....
36
+
37
+ RestClient.post( url,
38
+ {
39
+ :transfer => {
40
+ :path => '/foo/bar',
41
+ :owner => 'that_guy',
42
+ :group => 'those_guys'
43
+ },
44
+ :upload => {
45
+ :file => File.new(path, 'rb')
46
+ }
47
+ })
48
+
49
+ == Multipart
50
+
51
+ Yeah, that's right! This does multipart sends for you!
52
+
53
+ RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
54
+
55
+ This does two things for you:
56
+
57
+ * Auto-detects that you have a File value sends it as multipart
58
+ * Auto-detects the mime of the file and sets it in the HEAD of the payload for each entry
59
+
60
+ If you are sending params that do not contain a File object but the payload needs to be multipart then:
61
+
62
+ RestClient.post '/data', :foo => 'bar', :multipart => true
63
+
64
+ == Usage: ActiveResource-Style
65
+
66
+ resource = RestClient::Resource.new 'http://example.com/resource'
67
+ resource.get
68
+
69
+ private_resource = RestClient::Resource.new 'https://example.com/private/resource', 'user', 'pass'
70
+ private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
71
+
72
+ See RestClient::Resource module docs for details.
73
+
74
+ == Usage: Resource Nesting
75
+
76
+ site = RestClient::Resource.new('http://example.com')
77
+ site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
78
+
79
+ See RestClient::Resource docs for details.
80
+
81
+ == Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
82
+
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
87
+
88
+ RestClient.get 'http://example.com/resource'
89
+ ➔ RestClient::ResourceNotFound: RestClient::ResourceNotFound
90
+
91
+ begin
92
+ RestClient.get 'http://example.com/resource'
93
+ rescue => e
94
+ e.response
95
+ end
96
+ ➔ 404 Resource Not Found | text/html 282 bytes
97
+
98
+ == Result handling
99
+
100
+ A block can be passed to the RestClient method. This block will then be called with the Response.
101
+ Response.return! can be called to invoke the default response's behavior.
102
+
103
+ # Don't raise exceptions but return the response
104
+ RestClient.get('http://example.com/resource'){|response, request, result| response }
105
+ ➔ 404 Resource Not Found | text/html 282 bytes
106
+
107
+ # Manage a specific error code
108
+ RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
109
+ case response.code
110
+ when 200
111
+ p "It worked !"
112
+ response
113
+ when 423
114
+ raise SomeCustomExceptionIfYouWant
115
+ else
116
+ response.return!(request, result, &block)
117
+ end
118
+ }
119
+
120
+ # Follow redirections for all request types and not only for get and head
121
+ # RFC : "If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD,
122
+ # the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,
123
+ # since this might change the conditions under which the request was issued."
124
+ RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
125
+ if [301, 302, 307].include? response.code
126
+ response.follow_redirection(request, result, &block)
127
+ else
128
+ response.return!(request, result, &block)
129
+ end
130
+ }
131
+
132
+ == Non-normalized URIs
133
+
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:
136
+
137
+ require 'addressable/uri'
138
+ RestClient.get(Addressable::URI.parse("http://www.詹姆斯.com/").normalize.to_str)
139
+
140
+ == Lower-level access
141
+
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.
151
+
152
+ == Shell
153
+
154
+ The restclient shell command gives an IRB session with RestClient already loaded:
155
+
156
+ $ restclient
157
+ >> RestClient.get 'http://example.com'
158
+
159
+ Specify a URL argument for get/post/put/delete on that resource:
160
+
161
+ $ restclient http://example.com
162
+ >> put '/resource', 'data'
163
+
164
+ Add a user and password for authenticated resources:
165
+
166
+ $ restclient https://example.com user pass
167
+ >> delete '/private/resource'
168
+
169
+ Create ~/.restclient for named sessions:
170
+
171
+ sinatra:
172
+ url: http://localhost:4567
173
+ rack:
174
+ url: http://localhost:9292
175
+ private_site:
176
+ url: http://example.com
177
+ username: user
178
+ password: pass
179
+
180
+ Then invoke:
181
+
182
+ $ restclient private_site
183
+
184
+ Use as a one-off, curl-style:
185
+
186
+ $ restclient get http://example.com/resource > output_body
187
+
188
+ $ restclient put http://example.com/resource < input_body
189
+
190
+ == Logging
191
+
192
+ To enable logging you can:
193
+
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"):
196
+
197
+ $ RESTCLIENT_LOG=stdout path/to/my/program
198
+
199
+ Either produces logs like this:
200
+
201
+ RestClient.get "http://some/resource"
202
+ # => 200 OK | text/html 250 bytes
203
+ RestClient.put "http://some/resource", "payload"
204
+ # => 401 Unauthorized | application/xml 340 bytes
205
+
206
+ Note that these logs are valid Ruby, so you can paste them into the restclient
207
+ shell or a script to replay your sequence of rest calls.
208
+
209
+ == Proxy
210
+
211
+ All calls to RestClient, including Resources, will use the proxy specified by
212
+ RestClient.proxy:
213
+
214
+ RestClient.proxy = "http://proxy.example.com/"
215
+ RestClient.get "http://some/resource"
216
+ # => response from some/resource as proxied through proxy.example.com
217
+
218
+ Often the proxy URL is set in an environment variable, so you can do this to
219
+ use whatever proxy the system is configured to use:
220
+
221
+ RestClient.proxy = ENV['http_proxy']
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
+
231
+ == Cookies
232
+
233
+ Request and Response objects know about HTTP cookies, and will automatically
234
+ extract and set headers for them as needed:
235
+
236
+ response = RestClient.get 'http://example.com/action_which_sets_session_id'
237
+ response.cookies
238
+ # => {"_applicatioN_session_id" => "1234"}
239
+
240
+ response2 = RestClient.post(
241
+ 'http://localhost:3000/',
242
+ {:param1 => "foo"},
243
+ {:cookies => {:session_id => "1234"}}
244
+ )
245
+ # ...response body
246
+
247
+ == SSL Client Certificates
248
+
249
+ RestClient::Resource.new(
250
+ 'https://example.com',
251
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
252
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
253
+ :ssl_ca_file => "ca_certificate.pem",
254
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
255
+ ).get
256
+
257
+ Self-signed certificates can be generated with the openssl command-line tool.
258
+
259
+ == Hook
260
+
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.
263
+
264
+ Example:
265
+
266
+ # Add oauth support using the oauth gem
267
+ require 'oauth'
268
+ access_token = ...
269
+
270
+ RestClient.add_before_execution_proc do |req, params|
271
+ access_token.sign! req
272
+ end
273
+
274
+ RestClient.get 'http://example.com'
275
+
276
+ == More
277
+
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
283
+
284
+ REST Client Team:: Matthew Manning, Lawrence Leonard Gilbert, Andy Brody
285
+
286
+ Creator:: Adam Wiggins
287
+
288
+ Maintainer Emeritus:: Julien Kirch
289
+
290
+ Major contributions:: Blake Mizerany, Julien Kirch
291
+
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.
293
+
294
+ == Legal
295
+
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/)
@@ -0,0 +1,49 @@
1
+ begin
2
+ # optionally load `rake build/install/release tasks'
3
+ require 'bundler/gem_tasks'
4
+ rescue LoadError
5
+ end
6
+
7
+ require "rspec/core/rake_task"
8
+
9
+ desc "Run all specs"
10
+ task :spec => ["spec:unit", "spec:integration"]
11
+
12
+ desc "Run unit specs"
13
+ RSpec::Core::RakeTask.new('spec:unit') do |t|
14
+ t.pattern = ['spec/*_spec.rb']
15
+ end
16
+
17
+ desc "Run integration specs"
18
+ RSpec::Core::RakeTask.new('spec:integration') do |t|
19
+ t.pattern = ['spec/integration/*_spec.rb']
20
+ end
21
+
22
+ desc "Print specdocs"
23
+ RSpec::Core::RakeTask.new(:doc) do |t|
24
+ t.rspec_opts = ["--format", "specdoc", "--dry-run"]
25
+ t.pattern = ['spec/*_spec.rb']
26
+ end
27
+
28
+ desc "Run all examples with RCov"
29
+ RSpec::Core::RakeTask.new('rcov') do |t|
30
+ t.pattern = ['spec/*_spec.rb']
31
+ t.rcov = true
32
+ t.rcov_opts = ['--exclude', 'examples']
33
+ end
34
+
35
+ task :default => :spec
36
+
37
+ ############################
38
+
39
+ require 'rdoc/task'
40
+
41
+ Rake::RDocTask.new do |t|
42
+ t.rdoc_dir = 'rdoc'
43
+ t.title = "rest-client, fetch RESTful resources effortlessly"
44
+ t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
45
+ t.options << '--charset' << 'utf-8'
46
+ t.rdoc_files.include('README.rdoc')
47
+ t.rdoc_files.include('lib/*.rb')
48
+ end
49
+