rest-client 1.8.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.mailmap +10 -0
  4. data/.rspec +2 -1
  5. data/.rubocop +2 -0
  6. data/.rubocop-disables.yml +386 -0
  7. data/.rubocop.yml +8 -0
  8. data/.travis.yml +56 -8
  9. data/AUTHORS +26 -1
  10. data/README.md +901 -0
  11. data/Rakefile +27 -3
  12. data/bin/restclient +3 -5
  13. data/history.md +181 -0
  14. data/lib/restclient/abstract_response.rb +172 -55
  15. data/lib/restclient/exceptions.rb +96 -55
  16. data/lib/restclient/params_array.rb +72 -0
  17. data/lib/restclient/payload.rb +70 -74
  18. data/lib/restclient/platform.rb +19 -0
  19. data/lib/restclient/raw_response.rb +21 -7
  20. data/lib/restclient/request.rb +540 -281
  21. data/lib/restclient/resource.rb +19 -9
  22. data/lib/restclient/response.rb +75 -6
  23. data/lib/restclient/utils.rb +274 -0
  24. data/lib/restclient/version.rb +2 -1
  25. data/lib/restclient.rb +21 -3
  26. data/rest-client.gemspec +12 -10
  27. data/spec/ISS.jpg +0 -0
  28. data/spec/helpers.rb +54 -0
  29. data/spec/integration/_lib.rb +1 -0
  30. data/spec/integration/capath_digicert/3513523f.0 +22 -0
  31. data/spec/integration/capath_digicert/399e7759.0 +22 -0
  32. data/spec/integration/capath_digicert/digicert.crt +20 -17
  33. data/spec/integration/certs/digicert.crt +20 -17
  34. data/spec/integration/httpbin_spec.rb +128 -0
  35. data/spec/integration/integration_spec.rb +97 -14
  36. data/spec/integration/request_spec.rb +25 -2
  37. data/spec/spec_helper.rb +28 -1
  38. data/spec/unit/_lib.rb +1 -0
  39. data/spec/unit/abstract_response_spec.rb +95 -38
  40. data/spec/unit/exceptions_spec.rb +41 -28
  41. data/spec/unit/params_array_spec.rb +36 -0
  42. data/spec/unit/payload_spec.rb +118 -68
  43. data/spec/unit/raw_response_spec.rb +10 -6
  44. data/spec/unit/request2_spec.rb +34 -12
  45. data/spec/unit/request_spec.rb +745 -424
  46. data/spec/unit/resource_spec.rb +31 -27
  47. data/spec/unit/response_spec.rb +134 -57
  48. data/spec/unit/restclient_spec.rb +16 -15
  49. data/spec/unit/utils_spec.rb +147 -0
  50. data/spec/unit/windows/root_certs_spec.rb +3 -3
  51. metadata +79 -29
  52. data/README.rdoc +0 -324
  53. data/spec/integration/capath_digicert/244b5494.0 +0 -19
  54. data/spec/integration/capath_digicert/81b9768f.0 +0 -19
  55. data/spec/unit/master_shake.jpg +0 -0
data/README.rdoc DELETED
@@ -1,324 +0,0 @@
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=master" 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
- == Requirements
12
-
13
- MRI Ruby 1.9.2 and newer are supported. Alternative interpreters compatible with
14
- 1.9.1+ should work as well.
15
-
16
- Ruby 1.8.7 is no longer supported. That's because the Ruby 1.8.7 interpreter
17
- itself no longer has official support, _not_ _even_ _security_ _patches!_ If you
18
- have been putting off upgrading your servers, now is the time.
19
- ({More info is on the Ruby developers'
20
- blog.}[http://www.ruby-lang.org/en/news/2013/06/30/we-retire-1-8-7/])
21
-
22
- The rest-client gem depends on these other gems for installation and usage:
23
-
24
- * {mime-types}[http://rubygems.org/gems/mime-types]
25
- * {netrc}[http://rubygems.org/gems/netrc]
26
- * {rdoc}[http://rubygems.org/gems/rdoc]
27
-
28
- If you want to hack on the code, you should also have {the Bundler
29
- gem}[http://bundler.io/] installed so it can manage all necessary development
30
- dependencies for you.
31
-
32
- == Usage: Raw URL
33
-
34
- require 'rest_client'
35
-
36
- RestClient.get 'http://example.com/resource'
37
-
38
- RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
39
-
40
- RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json}
41
-
42
- RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
43
-
44
- RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
45
-
46
- RestClient.delete 'http://example.com/resource'
47
-
48
- response = RestClient.get 'http://example.com/resource'
49
- response.code
50
- ➔ 200
51
- response.cookies
52
- ➔ {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
53
- response.headers
54
- ➔ {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
55
- response.to_str
56
- ➔ \n<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html ....
57
-
58
- RestClient.post( url,
59
- {
60
- :transfer => {
61
- :path => '/foo/bar',
62
- :owner => 'that_guy',
63
- :group => 'those_guys'
64
- },
65
- :upload => {
66
- :file => File.new(path, 'rb')
67
- }
68
- })
69
-
70
- == Multipart
71
-
72
- Yeah, that's right! This does multipart sends for you!
73
-
74
- RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
75
-
76
- This does two things for you:
77
-
78
- * Auto-detects that you have a File value sends it as multipart
79
- * Auto-detects the mime of the file and sets it in the HEAD of the payload for each entry
80
-
81
- If you are sending params that do not contain a File object but the payload needs to be multipart then:
82
-
83
- RestClient.post '/data', {:foo => 'bar', :multipart => true}
84
-
85
- == Usage: ActiveResource-Style
86
-
87
- resource = RestClient::Resource.new 'http://example.com/resource'
88
- resource.get
89
-
90
- private_resource = RestClient::Resource.new 'https://example.com/private/resource', 'user', 'pass'
91
- private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
92
-
93
- See RestClient::Resource module docs for details.
94
-
95
- == Usage: Resource Nesting
96
-
97
- site = RestClient::Resource.new('http://example.com')
98
- site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
99
-
100
- See RestClient::Resource docs for details.
101
-
102
- == Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
103
-
104
- * for result codes between 200 and 207, a RestClient::Response will be returned
105
- * for result codes 301, 302 or 307, the redirection will be followed if the request is a GET or a HEAD
106
- * for result code 303, the redirection will be followed and the request transformed into a GET
107
- * for other cases, a RestClient::Exception holding the Response will be raised; a specific exception class will be thrown for known error codes
108
-
109
- RestClient.get 'http://example.com/resource'
110
- ➔ RestClient::ResourceNotFound: RestClient::ResourceNotFound
111
-
112
- begin
113
- RestClient.get 'http://example.com/resource'
114
- rescue => e
115
- e.response
116
- end
117
- ➔ 404 Resource Not Found | text/html 282 bytes
118
-
119
- == Result handling
120
-
121
- A block can be passed to the RestClient method. This block will then be called with the Response.
122
- Response.return! can be called to invoke the default response's behavior.
123
-
124
- # Don't raise exceptions but return the response
125
- RestClient.get('http://example.com/resource'){|response, request, result| response }
126
- ➔ 404 Resource Not Found | text/html 282 bytes
127
-
128
- # Manage a specific error code
129
- RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
130
- case response.code
131
- when 200
132
- p "It worked !"
133
- response
134
- when 423
135
- raise SomeCustomExceptionIfYouWant
136
- else
137
- response.return!(request, result, &block)
138
- end
139
- }
140
-
141
- # Follow redirections for all request types and not only for get and head
142
- # RFC : "If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD,
143
- # the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,
144
- # since this might change the conditions under which the request was issued."
145
- RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
146
- if [301, 302, 307].include? response.code
147
- response.follow_redirection(request, result, &block)
148
- else
149
- response.return!(request, result, &block)
150
- end
151
- }
152
-
153
- == Non-normalized URIs
154
-
155
- If you need to normalize URIs, e.g. to work with International Resource Identifiers (IRIs),
156
- use the addressable gem (http://addressable.rubyforge.org/api/) in your code:
157
-
158
- require 'addressable/uri'
159
- RestClient.get(Addressable::URI.parse("http://www.詹姆斯.com/").normalize.to_str)
160
-
161
- == Lower-level access
162
-
163
- For cases not covered by the general API, you can use the RestClient::Request class, which provides a lower-level API.
164
-
165
- You can:
166
-
167
- * specify ssl parameters
168
- * override cookies
169
- * manually handle the response (e.g. to operate on it as a stream rather than reading it all into memory)
170
-
171
- See RestClient::Request's documentation for more information.
172
-
173
- == Shell
174
-
175
- The restclient shell command gives an IRB session with RestClient already loaded:
176
-
177
- $ restclient
178
- >> RestClient.get 'http://example.com'
179
-
180
- Specify a URL argument for get/post/put/delete on that resource:
181
-
182
- $ restclient http://example.com
183
- >> put '/resource', 'data'
184
-
185
- Add a user and password for authenticated resources:
186
-
187
- $ restclient https://example.com user pass
188
- >> delete '/private/resource'
189
-
190
- Create ~/.restclient for named sessions:
191
-
192
- sinatra:
193
- url: http://localhost:4567
194
- rack:
195
- url: http://localhost:9292
196
- private_site:
197
- url: http://example.com
198
- username: user
199
- password: pass
200
-
201
- Then invoke:
202
-
203
- $ restclient private_site
204
-
205
- Use as a one-off, curl-style:
206
-
207
- $ restclient get http://example.com/resource > output_body
208
-
209
- $ restclient put http://example.com/resource < input_body
210
-
211
- == Logging
212
-
213
- To enable logging you can:
214
-
215
- * set RestClient.log with a Ruby Logger, or
216
- * set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
217
-
218
- $ RESTCLIENT_LOG=stdout path/to/my/program
219
-
220
- Either produces logs like this:
221
-
222
- RestClient.get "http://some/resource"
223
- # => 200 OK | text/html 250 bytes
224
- RestClient.put "http://some/resource", "payload"
225
- # => 401 Unauthorized | application/xml 340 bytes
226
-
227
- Note that these logs are valid Ruby, so you can paste them into the restclient
228
- shell or a script to replay your sequence of rest calls.
229
-
230
- == Proxy
231
-
232
- All calls to RestClient, including Resources, will use the proxy specified by
233
- RestClient.proxy:
234
-
235
- RestClient.proxy = "http://proxy.example.com/"
236
- RestClient.get "http://some/resource"
237
- # => response from some/resource as proxied through proxy.example.com
238
-
239
- Often the proxy URL is set in an environment variable, so you can do this to
240
- use whatever proxy the system is configured to use:
241
-
242
- RestClient.proxy = ENV['http_proxy']
243
-
244
- == Query parameters
245
-
246
- Request objects know about query parameters and will automatically add them to
247
- the URL for GET, HEAD and DELETE requests, escaping the keys and values as needed:
248
-
249
- RestClient.get 'http://example.com/resource', :params => {:foo => 'bar', :baz => 'qux'}
250
- # will GET http://example.com/resource?foo=bar&baz=qux
251
-
252
- == Cookies
253
-
254
- Request and Response objects know about HTTP cookies, and will automatically
255
- extract and set headers for them as needed:
256
-
257
- response = RestClient.get 'http://example.com/action_which_sets_session_id'
258
- response.cookies
259
- # => {"_applicatioN_session_id" => "1234"}
260
-
261
- response2 = RestClient.post(
262
- 'http://localhost:3000/',
263
- {:param1 => "foo"},
264
- {:cookies => {:session_id => "1234"}}
265
- )
266
- # ...response body
267
-
268
- == SSL Client Certificates
269
-
270
- RestClient::Resource.new(
271
- 'https://example.com',
272
- :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
273
- :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
274
- :ssl_ca_file => "ca_certificate.pem",
275
- :verify_ssl => OpenSSL::SSL::VERIFY_PEER
276
- ).get
277
-
278
- Self-signed certificates can be generated with the openssl command-line tool.
279
-
280
- == Hook
281
-
282
- RestClient.add_before_execution_proc add a Proc to be called before each execution.
283
- It's handy if you need direct access to the HTTP request.
284
-
285
- Example:
286
-
287
- # Add oauth support using the oauth gem
288
- require 'oauth'
289
- access_token = ...
290
-
291
- RestClient.add_before_execution_proc do |req, params|
292
- access_token.sign! req
293
- end
294
-
295
- RestClient.get 'http://example.com'
296
-
297
- == More
298
-
299
- Need caching, more advanced logging or any ability provided by Rack middleware?
300
-
301
- Have a look at rest-client-components: http://github.com/crohr/rest-client-components
302
-
303
- == Credits
304
-
305
- REST Client Team:: Matthew Manning, Lawrence Leonard Gilbert, Andy Brody
306
-
307
- Creator:: Adam Wiggins
308
-
309
- Maintainer Emeritus:: Julien Kirch
310
-
311
- Major contributions:: Blake Mizerany, Julien Kirch
312
-
313
- Patches contributed by many, including Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, François Beausoleil and Nick Plante.
314
-
315
- == Legal
316
-
317
- Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
318
-
319
- "Master Shake" photo (http://www.flickr.com/photos/solgrundy/924205581/) by
320
- "SolGrundy"; used under terms of the Creative Commons Attribution-ShareAlike 2.0
321
- Generic license (http://creativecommons.org/licenses/by-sa/2.0/)
322
-
323
- Code for reading Windows root certificate store derived from work by Puppet;
324
- used under terms of the Apache License, Version 2.0.
@@ -1,19 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
3
- EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
4
- KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
5
- MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
6
- MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
7
- Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
8
- Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
9
- OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
10
- MRuNs8ckRZqnrG0AFFoEt7oT61EKmE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