rest-client 1.7.0.rc1-x86-mingw32

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.

Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +14 -0
  5. data/AUTHORS +81 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE +21 -0
  8. data/README.rdoc +325 -0
  9. data/Rakefile +117 -0
  10. data/bin/restclient +93 -0
  11. data/history.md +166 -0
  12. data/lib/rest-client.rb +2 -0
  13. data/lib/rest_client.rb +2 -0
  14. data/lib/restclient.rb +164 -0
  15. data/lib/restclient/abstract_response.rb +106 -0
  16. data/lib/restclient/exceptions.rb +203 -0
  17. data/lib/restclient/payload.rb +240 -0
  18. data/lib/restclient/platform.rb +30 -0
  19. data/lib/restclient/raw_response.rb +34 -0
  20. data/lib/restclient/request.rb +582 -0
  21. data/lib/restclient/resource.rb +169 -0
  22. data/lib/restclient/response.rb +24 -0
  23. data/lib/restclient/version.rb +7 -0
  24. data/lib/restclient/windows.rb +8 -0
  25. data/lib/restclient/windows/root_certs.rb +105 -0
  26. data/rest-client.gemspec +30 -0
  27. data/rest-client.windows.gemspec +19 -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/capath_verisign/415660c1.0 +14 -0
  33. data/spec/integration/capath_verisign/7651b327.0 +14 -0
  34. data/spec/integration/capath_verisign/README +8 -0
  35. data/spec/integration/capath_verisign/verisign.crt +14 -0
  36. data/spec/integration/certs/digicert.crt +19 -0
  37. data/spec/integration/certs/verisign.crt +14 -0
  38. data/spec/integration/integration_spec.rb +35 -0
  39. data/spec/integration/request_spec.rb +104 -0
  40. data/spec/spec_helper.rb +12 -0
  41. data/spec/unit/abstract_response_spec.rb +85 -0
  42. data/spec/unit/exceptions_spec.rb +95 -0
  43. data/spec/unit/master_shake.jpg +0 -0
  44. data/spec/unit/payload_spec.rb +245 -0
  45. data/spec/unit/raw_response_spec.rb +17 -0
  46. data/spec/unit/request2_spec.rb +32 -0
  47. data/spec/unit/request_spec.rb +905 -0
  48. data/spec/unit/resource_spec.rb +133 -0
  49. data/spec/unit/response_spec.rb +166 -0
  50. data/spec/unit/restclient_spec.rb +79 -0
  51. data/spec/unit/windows/root_certs_spec.rb +22 -0
  52. metadata +241 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56faaeb27556081aff1b82fd1290ec81c855c797
4
+ data.tar.gz: e626690be3edd5179562aac07a35a830e7f79d40
5
+ SHA512:
6
+ metadata.gz: db3bbc532eea61761c352520802d7562b20cba56c100c15e012132118d9f25fca341db9d88b6ca251a70437bc87fb4f677ee772081e8ff3e888b932d08d20c35
7
+ data.tar.gz: 94185f24c2e6d82690ec20658456307fdbe40173f5acd9d191a263997dd7d4a65debe57ffd5b20db54ce3b82bbd165b9da54fa4609687ad80c9e1e5717b0a0ca
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .idea
3
+ .rvmrc
4
+ Gemfile.lock
5
+ doc
6
+ pkg
7
+ rdoc
8
+ scratchpad.rb
9
+ /.bundle/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format progress --order random
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ # Forgo 2.1.0 until Travis has a satisfactory fix for
7
+ # https://github.com/travis-ci/travis-ci/issues/2220
8
+ - "2.1" # always the latest 2.1.x
9
+ - "jruby-19mode"
10
+ script:
11
+ bundle exec rake test
12
+ branches:
13
+ except:
14
+ - "readme-edits"
data/AUTHORS ADDED
@@ -0,0 +1,81 @@
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 Frohoff
15
+ Chris Green
16
+ Coda Hale
17
+ Crawford
18
+ Cyril Rohr
19
+ Dan Mayer
20
+ David Backeus
21
+ David Perkowski
22
+ Dmitri Dolguikh
23
+ Dusty Doris
24
+ Dylan Egan
25
+ El Draper
26
+ Evan Smith
27
+ François Beausoleil
28
+ Gabriele Cirulli
29
+ Garry Shutler
30
+ Giovanni Cappellotto
31
+ Greg Borenstein
32
+ Harm Aarts
33
+ Hiro Asari
34
+ Hugh McGowan
35
+ Ian Warshak
36
+ Ivan Makfinsky
37
+ JH. Chabran
38
+ James Edward Gray II
39
+ Jari Bakken
40
+ Jeff Remer
41
+ Jeffrey Hardy
42
+ Jeremy Kemper
43
+ John Barnette
44
+ Jon Rowe
45
+ Jordi Massaguer Pla
46
+ Juan Alvarez
47
+ Julien Kirch
48
+ Justin Coyne
49
+ Justin Lambert
50
+ Keith Rarick
51
+ Kenichi Kamiya
52
+ Kevin Read
53
+ Kosuke Asami
54
+ Kyle VanderBeek
55
+ Lars Gierth
56
+ Lawrence Leonard Gilbert
57
+ Lee Jarvis
58
+ Lennon Day-Reynolds
59
+ Marc-André Cournoyer
60
+ Matthew Manning
61
+ Michael Klett
62
+ Mike Fletcher
63
+ Nicholas Wieland
64
+ Nick Plante
65
+ Niko Dittmann
66
+ Oscar Del Ben
67
+ Pablo Astigarraga
68
+ Paul Dlug
69
+ Pedro Belo
70
+ Philip Corliss
71
+ Pierre-Louis Gottfrois
72
+ Rafael Ssouza
73
+ Rick "technoweenie"
74
+ Robert Eanes
75
+ Rodrigo Panachi
76
+ Syl Turner
77
+ T. Watanabe
78
+ Tekin
79
+ W. Andrew Loe III
80
+ Waynn Lue
81
+ tpresa
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ if !!File::ALT_SEPARATOR
4
+ gemspec :name => 'rest-client.windows'
5
+ else
6
+ gemspec :name => 'rest-client'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rake'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2008-2014 Rest Client Authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,325 @@
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.png" />}[https://travis-ci.org/rest-client/rest-client]
4
+
5
+
6
+ A simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style
7
+ of specifying actions: get, put, post, delete.
8
+
9
+ * Main page: https://github.com/rest-client/rest-client
10
+ * Mailing list: rest.client@librelist.com (send a mail to subscribe).
11
+
12
+ == Requirements
13
+
14
+ MRI Ruby 1.9.2 and newer are supported. Alternative interpreters compatible with
15
+ 1.9.1+ should work as well.
16
+
17
+ Ruby 1.8.7 is no longer supported. That's because the Ruby 1.8.7 interpreter
18
+ itself no longer has official support, _not_ _even_ _security_ _patches!_ If you
19
+ have been putting off upgrading your servers, now is the time.
20
+ ({More info is on the Ruby developers'
21
+ blog.}[http://www.ruby-lang.org/en/news/2013/06/30/we-retire-1-8-7/])
22
+
23
+ The rest-client gem depends on these other gems for installation and usage:
24
+
25
+ * {mime-types}[http://rubygems.org/gems/mime-types]
26
+ * {netrc}[http://rubygems.org/gems/netrc]
27
+ * {rdoc}[http://rubygems.org/gems/rdoc]
28
+
29
+ If you want to hack on the code, you should also have {the Bundler
30
+ gem}[http://bundler.io/] installed so it can manage all necessary development
31
+ dependencies for you.
32
+
33
+ == Usage: Raw URL
34
+
35
+ require 'rest_client'
36
+
37
+ RestClient.get 'http://example.com/resource'
38
+
39
+ RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
40
+
41
+ RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json}
42
+
43
+ RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
44
+
45
+ RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
46
+
47
+ RestClient.delete 'http://example.com/resource'
48
+
49
+ response = RestClient.get 'http://example.com/resource'
50
+ response.code
51
+ ➔ 200
52
+ response.cookies
53
+ ➔ {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
54
+ response.headers
55
+ ➔ {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
56
+ response.to_str
57
+ ➔ \n<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html ....
58
+
59
+ RestClient.post( url,
60
+ {
61
+ :transfer => {
62
+ :path => '/foo/bar',
63
+ :owner => 'that_guy',
64
+ :group => 'those_guys'
65
+ },
66
+ :upload => {
67
+ :file => File.new(path, 'rb')
68
+ }
69
+ })
70
+
71
+ == Multipart
72
+
73
+ Yeah, that's right! This does multipart sends for you!
74
+
75
+ RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
76
+
77
+ This does two things for you:
78
+
79
+ * Auto-detects that you have a File value sends it as multipart
80
+ * Auto-detects the mime of the file and sets it in the HEAD of the payload for each entry
81
+
82
+ If you are sending params that do not contain a File object but the payload needs to be multipart then:
83
+
84
+ RestClient.post '/data', {:foo => 'bar', :multipart => true}
85
+
86
+ == Usage: ActiveResource-Style
87
+
88
+ resource = RestClient::Resource.new 'http://example.com/resource'
89
+ resource.get
90
+
91
+ private_resource = RestClient::Resource.new 'https://example.com/private/resource', 'user', 'pass'
92
+ private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
93
+
94
+ See RestClient::Resource module docs for details.
95
+
96
+ == Usage: Resource Nesting
97
+
98
+ site = RestClient::Resource.new('http://example.com')
99
+ site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
100
+
101
+ See RestClient::Resource docs for details.
102
+
103
+ == Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
104
+
105
+ * for result codes between 200 and 207, a RestClient::Response will be returned
106
+ * for result codes 301, 302 or 307, the redirection will be followed if the request is a GET or a HEAD
107
+ * for result code 303, the redirection will be followed and the request transformed into a GET
108
+ * for other cases, a RestClient::Exception holding the Response will be raised; a specific exception class will be thrown for known error codes
109
+
110
+ RestClient.get 'http://example.com/resource'
111
+ ➔ RestClient::ResourceNotFound: RestClient::ResourceNotFound
112
+
113
+ begin
114
+ RestClient.get 'http://example.com/resource'
115
+ rescue => e
116
+ e.response
117
+ end
118
+ ➔ 404 Resource Not Found | text/html 282 bytes
119
+
120
+ == Result handling
121
+
122
+ A block can be passed to the RestClient method. This block will then be called with the Response.
123
+ Response.return! can be called to invoke the default response's behavior.
124
+
125
+ # Don't raise exceptions but return the response
126
+ RestClient.get('http://example.com/resource'){|response, request, result| response }
127
+ ➔ 404 Resource Not Found | text/html 282 bytes
128
+
129
+ # Manage a specific error code
130
+ RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
131
+ case response.code
132
+ when 200
133
+ p "It worked !"
134
+ response
135
+ when 423
136
+ raise SomeCustomExceptionIfYouWant
137
+ else
138
+ response.return!(request, result, &block)
139
+ end
140
+ }
141
+
142
+ # Follow redirections for all request types and not only for get and head
143
+ # RFC : "If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD,
144
+ # the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,
145
+ # since this might change the conditions under which the request was issued."
146
+ RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
147
+ if [301, 302, 307].include? response.code
148
+ response.follow_redirection(request, result, &block)
149
+ else
150
+ response.return!(request, result, &block)
151
+ end
152
+ }
153
+
154
+ == Non-normalized URIs
155
+
156
+ If you need to normalize URIs, e.g. to work with International Resource Identifiers (IRIs),
157
+ use the addressable gem (http://addressable.rubyforge.org/api/) in your code:
158
+
159
+ require 'addressable/uri'
160
+ RestClient.get(Addressable::URI.parse("http://www.詹姆斯.com/").normalize.to_str)
161
+
162
+ == Lower-level access
163
+
164
+ For cases not covered by the general API, you can use the RestClient::Request class, which provides a lower-level API.
165
+
166
+ You can:
167
+
168
+ * specify ssl parameters
169
+ * override cookies
170
+ * manually handle the response (e.g. to operate on it as a stream rather than reading it all into memory)
171
+
172
+ See RestClient::Request's documentation for more information.
173
+
174
+ == Shell
175
+
176
+ The restclient shell command gives an IRB session with RestClient already loaded:
177
+
178
+ $ restclient
179
+ >> RestClient.get 'http://example.com'
180
+
181
+ Specify a URL argument for get/post/put/delete on that resource:
182
+
183
+ $ restclient http://example.com
184
+ >> put '/resource', 'data'
185
+
186
+ Add a user and password for authenticated resources:
187
+
188
+ $ restclient https://example.com user pass
189
+ >> delete '/private/resource'
190
+
191
+ Create ~/.restclient for named sessions:
192
+
193
+ sinatra:
194
+ url: http://localhost:4567
195
+ rack:
196
+ url: http://localhost:9292
197
+ private_site:
198
+ url: http://example.com
199
+ username: user
200
+ password: pass
201
+
202
+ Then invoke:
203
+
204
+ $ restclient private_site
205
+
206
+ Use as a one-off, curl-style:
207
+
208
+ $ restclient get http://example.com/resource > output_body
209
+
210
+ $ restclient put http://example.com/resource < input_body
211
+
212
+ == Logging
213
+
214
+ To enable logging you can:
215
+
216
+ * set RestClient.log with a Ruby Logger, or
217
+ * set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
218
+
219
+ $ RESTCLIENT_LOG=stdout path/to/my/program
220
+
221
+ Either produces logs like this:
222
+
223
+ RestClient.get "http://some/resource"
224
+ # => 200 OK | text/html 250 bytes
225
+ RestClient.put "http://some/resource", "payload"
226
+ # => 401 Unauthorized | application/xml 340 bytes
227
+
228
+ Note that these logs are valid Ruby, so you can paste them into the restclient
229
+ shell or a script to replay your sequence of rest calls.
230
+
231
+ == Proxy
232
+
233
+ All calls to RestClient, including Resources, will use the proxy specified by
234
+ RestClient.proxy:
235
+
236
+ RestClient.proxy = "http://proxy.example.com/"
237
+ RestClient.get "http://some/resource"
238
+ # => response from some/resource as proxied through proxy.example.com
239
+
240
+ Often the proxy URL is set in an environment variable, so you can do this to
241
+ use whatever proxy the system is configured to use:
242
+
243
+ RestClient.proxy = ENV['http_proxy']
244
+
245
+ == Query parameters
246
+
247
+ Request objects know about query parameters and will automatically add them to
248
+ the URL for GET, HEAD and DELETE requests, escaping the keys and values as needed:
249
+
250
+ RestClient.get 'http://example.com/resource', :params => {:foo => 'bar', :baz => 'qux'}
251
+ # will GET http://example.com/resource?foo=bar&baz=qux
252
+
253
+ == Cookies
254
+
255
+ Request and Response objects know about HTTP cookies, and will automatically
256
+ extract and set headers for them as needed:
257
+
258
+ response = RestClient.get 'http://example.com/action_which_sets_session_id'
259
+ response.cookies
260
+ # => {"_applicatioN_session_id" => "1234"}
261
+
262
+ response2 = RestClient.post(
263
+ 'http://localhost:3000/',
264
+ {:param1 => "foo"},
265
+ {:cookies => {:session_id => "1234"}}
266
+ )
267
+ # ...response body
268
+
269
+ == SSL Client Certificates
270
+
271
+ RestClient::Resource.new(
272
+ 'https://example.com',
273
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
274
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
275
+ :ssl_ca_file => "ca_certificate.pem",
276
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
277
+ ).get
278
+
279
+ Self-signed certificates can be generated with the openssl command-line tool.
280
+
281
+ == Hook
282
+
283
+ RestClient.add_before_execution_proc add a Proc to be called before each execution.
284
+ It's handy if you need direct access to the HTTP request.
285
+
286
+ Example:
287
+
288
+ # Add oauth support using the oauth gem
289
+ require 'oauth'
290
+ access_token = ...
291
+
292
+ RestClient.add_before_execution_proc do |req, params|
293
+ access_token.sign! req
294
+ end
295
+
296
+ RestClient.get 'http://example.com'
297
+
298
+ == More
299
+
300
+ Need caching, more advanced logging or any ability provided by Rack middleware?
301
+
302
+ Have a look at rest-client-components: http://github.com/crohr/rest-client-components
303
+
304
+ == Credits
305
+
306
+ REST Client Team:: Matthew Manning, Lawrence Leonard Gilbert, Andy Brody
307
+
308
+ Creator:: Adam Wiggins
309
+
310
+ Maintainer Emeritus:: Julien Kirch
311
+
312
+ Major contributions:: Blake Mizerany, Julien Kirch
313
+
314
+ Patches contributed by many, including Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, François Beausoleil and Nick Plante.
315
+
316
+ == Legal
317
+
318
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
319
+
320
+ "Master Shake" photo (http://www.flickr.com/photos/solgrundy/924205581/) by
321
+ "SolGrundy"; used under terms of the Creative Commons Attribution-ShareAlike 2.0
322
+ Generic license (http://creativecommons.org/licenses/by-sa/2.0/)
323
+
324
+ Code for reading Windows root certificate store derived from work by Puppet;
325
+ used under terms of the Apache License, Version 2.0.