rest-client_jxb_fix 1.6.7

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.
@@ -0,0 +1,285 @@
1
+ = REST Client -- simple DSL for accessing HTTP and REST resources
2
+
3
+ A simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style
4
+ of specifying actions: get, put, post, delete.
5
+
6
+ * Main page: http://github.com/archiloque/rest-client
7
+ * Mailing list: rest.client@librelist.com (send a mail to subscribe).
8
+
9
+ == Usage: Raw URL
10
+
11
+ require 'rest_client'
12
+
13
+ RestClient.get 'http://example.com/resource'
14
+
15
+ RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
16
+
17
+ RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json}
18
+
19
+ RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
20
+
21
+ RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
22
+
23
+ RestClient.delete 'http://example.com/resource'
24
+
25
+ response = RestClient.get 'http://example.com/resource'
26
+ response.code
27
+ ➔ 200
28
+ response.cookies
29
+ ➔ {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
30
+ response.headers
31
+ ➔ {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
32
+ response.to_str
33
+ ➔ \n<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html ....
34
+
35
+ RestClient.post( url,
36
+ {
37
+ :transfer => {
38
+ :path => '/foo/bar',
39
+ :owner => 'that_guy',
40
+ :group => 'those_guys'
41
+ },
42
+ :upload => {
43
+ :file => File.new(path, 'rb')
44
+ }
45
+ })
46
+
47
+ == Multipart
48
+
49
+ Yeah, that's right! This does multipart sends for you!
50
+
51
+ RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
52
+
53
+ This does two things for you:
54
+
55
+ * Auto-detects that you have a File value sends it as multipart
56
+ * Auto-detects the mime of the file and sets it in the HEAD of the payload for each entry
57
+
58
+ If you are sending params that do not contain a File object but the payload needs to be multipart then:
59
+
60
+ RestClient.post '/data', :foo => 'bar', :multipart => true
61
+
62
+ == Usage: ActiveResource-Style
63
+
64
+ resource = RestClient::Resource.new 'http://example.com/resource'
65
+ resource.get
66
+
67
+ private_resource = RestClient::Resource.new 'https://example.com/private/resource', 'user', 'pass'
68
+ private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
69
+
70
+ See RestClient::Resource module docs for details.
71
+
72
+ == Usage: Resource Nesting
73
+
74
+ site = RestClient::Resource.new('http://example.com')
75
+ site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
76
+
77
+ See RestClient::Resource docs for details.
78
+
79
+ == Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
80
+
81
+ * for results code between 200 and 207 a RestClient::Response will be returned
82
+ * for results code 301, 302 or 307 the redirection will be followed if the request is a get or a head
83
+ * for result code 303 the redirection will be followed and the request transformed into a get
84
+ * for other cases a RestClient::Exception holding the Response will be raised, a specific exception class will be thrown for know error codes
85
+
86
+ RestClient.get 'http://example.com/resource'
87
+ ➔ RestClient::ResourceNotFound: RestClient::ResourceNotFound
88
+
89
+ begin
90
+ RestClient.get 'http://example.com/resource'
91
+ rescue => e
92
+ e.response
93
+ end
94
+ ➔ 404 Resource Not Found | text/html 282 bytes
95
+
96
+ == Result handling
97
+
98
+ A block can be passed to the RestClient method, this block will then be called with the Response.
99
+ Response.return! can be called to invoke the default response's behavior.
100
+
101
+ # Don't raise exceptions but return the response
102
+ RestClient.get('http://example.com/resource'){|response, request, result| response }
103
+ ➔ 404 Resource Not Found | text/html 282 bytes
104
+
105
+ # Manage a specific error code
106
+ RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
107
+ case response.code
108
+ when 200
109
+ p "It worked !"
110
+ response
111
+ when 423
112
+ raise SomeCustomExceptionIfYouWant
113
+ else
114
+ response.return!(request, result, &block)
115
+ end
116
+ }
117
+
118
+ # Follow redirections for all request types and not only for get and head
119
+ # RFC : "If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD,
120
+ # the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,
121
+ # since this might change the conditions under which the request was issued."
122
+ RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
123
+ if [301, 302, 307].include? response.code
124
+ response.follow_redirection(request, result, &block)
125
+ else
126
+ response.return!(request, result, &block)
127
+ end
128
+ }
129
+
130
+ == Non-normalized URIs.
131
+
132
+ If you want to use non-normalized URIs, you can normalize them with the addressable gem (http://addressable.rubyforge.org/api/).
133
+
134
+ require 'addressable/uri'
135
+ RestClient.get(Addressable::URI.parse("http://www.詹姆斯.com/").normalize.to_str)
136
+
137
+ == Lower-level access
138
+
139
+ For cases not covered by the general API, you can use the RestClient::Request class which provide a lower-level API.
140
+
141
+ You can:
142
+
143
+ * specify ssl parameters
144
+ * override cookies
145
+ * manually handle the response (so you can operate on the response stream than reading it fully in memory)
146
+
147
+ see the class' rdoc for more information.
148
+
149
+ == Shell
150
+
151
+ The restclient shell command gives an IRB session with RestClient already loaded:
152
+
153
+ $ restclient
154
+ >> RestClient.get 'http://example.com'
155
+
156
+ Specify a URL argument for get/post/put/delete on that resource:
157
+
158
+ $ restclient http://example.com
159
+ >> put '/resource', 'data'
160
+
161
+ Add a user and password for authenticated resources:
162
+
163
+ $ restclient https://example.com user pass
164
+ >> delete '/private/resource'
165
+
166
+ Create ~/.restclient for named sessions:
167
+
168
+ sinatra:
169
+ url: http://localhost:4567
170
+ rack:
171
+ url: http://localhost:9292
172
+ private_site:
173
+ url: http://example.com
174
+ username: user
175
+ password: pass
176
+
177
+ Then invoke:
178
+
179
+ $ restclient private_site
180
+
181
+ Use as a one-off, curl-style:
182
+
183
+ $ restclient get http://example.com/resource > output_body
184
+
185
+ $ restclient put http://example.com/resource < input_body
186
+
187
+ == Logging
188
+
189
+ To enable logging you can
190
+
191
+ * set RestClient.log with a ruby Logger
192
+ * or set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
193
+
194
+ $ RESTCLIENT_LOG=stdout path/to/my/program
195
+
196
+ Either produces logs like this:
197
+
198
+ RestClient.get "http://some/resource"
199
+ # => 200 OK | text/html 250 bytes
200
+ RestClient.put "http://some/resource", "payload"
201
+ # => 401 Unauthorized | application/xml 340 bytes
202
+
203
+ Note that these logs are valid Ruby, so you can paste them into the restclient
204
+ shell or a script to replay your sequence of rest calls.
205
+
206
+ == Proxy
207
+
208
+ All calls to RestClient, including Resources, will use the proxy specified by
209
+ RestClient.proxy:
210
+
211
+ RestClient.proxy = "http://proxy.example.com/"
212
+ RestClient.get "http://some/resource"
213
+ # => response from some/resource as proxied through proxy.example.com
214
+
215
+ Often the proxy url is set in an environment variable, so you can do this to
216
+ use whatever proxy the system is configured to use:
217
+
218
+ RestClient.proxy = ENV['http_proxy']
219
+
220
+ == Query parameters
221
+
222
+ Request objects know about query parameters and will automatically add them to
223
+ the url for GET, HEAD and DELETE requests and escape the keys and values as
224
+ needed:
225
+
226
+ RestClient.get 'http://example.com/resource', :params => {:foo => 'bar', :baz => 'qux'}
227
+ # will GET http://example.com/resource?foo=bar&baz=qux
228
+
229
+ == Cookies
230
+
231
+ Request and Response objects know about HTTP cookies, and will automatically
232
+ extract and set headers for them as needed:
233
+
234
+ response = RestClient.get 'http://example.com/action_which_sets_session_id'
235
+ response.cookies
236
+ # => {"_applicatioN_session_id" => "1234"}
237
+
238
+ response2 = RestClient.post(
239
+ 'http://localhost:3000/',
240
+ {:param1 => "foo"},
241
+ {:cookies => {:session_id => "1234"}}
242
+ )
243
+ # ...response body
244
+
245
+ == SSL Client Certificates
246
+
247
+ RestClient::Resource.new(
248
+ 'https://example.com',
249
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
250
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
251
+ :ssl_ca_file => "ca_certificate.pem",
252
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
253
+ ).get
254
+
255
+ Self-signed certificates can be generated with the openssl command-line tool.
256
+
257
+ == Hook
258
+
259
+ RestClient.add_before_execution_proc add a Proc to be called before each execution, it's handy if you need a direct access to the http request.
260
+
261
+ Example:
262
+
263
+ # Add oath support using the oauth gem
264
+ require 'oauth'
265
+ access_token = ...
266
+
267
+ RestClient.add_before_execution_proc do |req, params|
268
+ access_token.sign! req
269
+ end
270
+
271
+ RestClient.get 'http://example.com'
272
+
273
+ == More
274
+
275
+ Need caching, more advanced logging or any ability provided by a rack middleware ?
276
+
277
+ Have a look at rest-client-components http://github.com/crohr/rest-client-components
278
+
279
+ == Meta
280
+
281
+ Written by Adam Wiggins, major modifications by Blake Mizerany, maintained by Julien Kirch
282
+
283
+ Patches contributed by many, including Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, François Beausoleil and Nick Plante.
284
+
285
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -0,0 +1,66 @@
1
+ require 'rake'
2
+
3
+ require 'jeweler'
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.authors = ["Adam Wiggins", "Julien Kirch"]
10
+ s.email = "rest.client@librelist.com"
11
+ s.homepage = "http://github.com/archiloque/rest-client"
12
+ s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
13
+ s.test_files = FileList["{spec}/**/*"]
14
+ s.add_runtime_dependency("mime-types", ">= 1.16")
15
+ s.add_development_dependency("webmock", ">= 0.9.1")
16
+ s.add_development_dependency("rspec")
17
+ s.extra_rdoc_files = [ 'README.rdoc', 'history.md']
18
+ end
19
+
20
+ ############################
21
+
22
+ require 'spec/rake/spectask'
23
+
24
+ desc "Run all specs"
25
+ task :spec => ["spec:unit", "spec:integration"]
26
+
27
+ desc "Run unit specs"
28
+ Spec::Rake::SpecTask.new('spec:unit') do |t|
29
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
30
+ t.spec_files = FileList['spec/*_spec.rb']
31
+ end
32
+
33
+ desc "Run integration specs"
34
+ Spec::Rake::SpecTask.new('spec:integration') do |t|
35
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
36
+ t.spec_files = FileList['spec/integration/*_spec.rb']
37
+ end
38
+
39
+ desc "Print specdocs"
40
+ Spec::Rake::SpecTask.new(:doc) do |t|
41
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
42
+ t.spec_files = FileList['spec/*_spec.rb']
43
+ end
44
+
45
+ desc "Run all examples with RCov"
46
+ Spec::Rake::SpecTask.new('rcov') do |t|
47
+ t.spec_files = FileList['spec/*_spec.rb']
48
+ t.rcov = true
49
+ t.rcov_opts = ['--exclude', 'examples']
50
+ end
51
+
52
+ task :default => :spec
53
+
54
+ ############################
55
+
56
+ require 'rake/rdoctask'
57
+
58
+ Rake::RDocTask.new do |t|
59
+ t.rdoc_dir = 'rdoc'
60
+ t.title = "rest-client, fetch RESTful resources effortlessly"
61
+ t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
62
+ t.options << '--charset' << 'utf-8'
63
+ t.rdoc_files.include('README.rdoc')
64
+ t.rdoc_files.include('lib/*.rb')
65
+ end
66
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.6.7
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + "/../lib"
4
+
5
+ require 'rubygems'
6
+ require 'restclient'
7
+ require 'yaml'
8
+
9
+ def usage(why = nil)
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)
15
+ end
16
+
17
+ POSSIBLE_VERBS = ['get', 'put', 'post', 'delete']
18
+
19
+ if POSSIBLE_VERBS.include? ARGV.first
20
+ @verb = ARGV.shift
21
+ else
22
+ @verb = nil
23
+ end
24
+
25
+ @url = ARGV.shift || 'http://localhost:4567'
26
+
27
+ config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
28
+
29
+ @url, @username, @password = if c = config[@url]
30
+ [c['url'], c['username'], c['password']]
31
+ else
32
+ [@url, * ARGV]
33
+ end
34
+
35
+ usage("invalid url '#{@url}") unless @url =~ /^https?/
36
+ usage("too few args") unless ARGV.size < 3
37
+
38
+ def r
39
+ @r ||= RestClient::Resource.new(@url, @username, @password)
40
+ end
41
+
42
+ r # force rc to load
43
+
44
+ if @verb
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
56
+ end
57
+
58
+ POSSIBLE_VERBS.each do |m|
59
+ eval <<-end_eval
60
+ def #{m}(path, *args, &b)
61
+ r[path].#{m}(*args, &b)
62
+ end
63
+ end_eval
64
+ end
65
+
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
77
+ end
78
+
79
+ require 'irb'
80
+ require 'irb/completion'
81
+
82
+ if File.exists? ".irbrc"
83
+ ENV['IRBRC'] = ".irbrc"
84
+ end
85
+
86
+ if File.exists?(File.expand_path(rcfile = "~/.restclientrc"))
87
+ load(rcfile)
88
+ end
89
+
90
+ ARGV.clear
91
+
92
+ IRB.start
93
+ exit!
@@ -0,0 +1,134 @@
1
+ # 1.6.7
2
+
3
+ - rebuild with 1.8.7 to avoid https://github.com/rubygems/rubygems/pull/57
4
+
5
+ # 1.6.6
6
+
7
+ - 1.6.5 was yanked
8
+
9
+ # 1.6.5
10
+
11
+ - RFC6265 requires single SP after ';' for separating parameters pairs in the 'Cookie:' header (patch provided by Hiroshi Nakamura)
12
+ - enable url parameters for all actions
13
+ - detect file parameters in arrays
14
+ - allow disabling the timeouts by passing -1 (patch provided by Sven Böhm)
15
+
16
+ # 1.6.4
17
+
18
+ - fix restclient script compatibility with 1.9.2
19
+ - fix unlinking temp file (patch provided by Evan Smith)
20
+ - monkeypatching ruby for http patch method (patch provided by Syl Turner)
21
+
22
+ # 1.6.3
23
+
24
+ - 1.6.2 was yanked
25
+
26
+ # 1.6.2
27
+
28
+ - add support for HEAD in resources (patch provided by tpresa)
29
+ - fix shell for 1.9.2
30
+ - workaround when some gem monkeypatch net/http (patch provided by Ian Warshak)
31
+ - DELETE requests should process parameters just like GET and HEAD
32
+ - adding :block_response parameter for manual processing
33
+ - limit number of redirections (patch provided by Chris Dinn)
34
+ - close and unlink the temp file created by playload (patch provided by Chris Green)
35
+ - make gemspec Rubygems 1.8 compatible (patch provided by David Backeus)
36
+ - added RestClient.reset_before_execution_procs (patch provided by Cloudify)
37
+ - added PATCH method (patch provided by Jeff Remer)
38
+ - hack for HTTP servers that use raw DEFLATE compression, see http://www.ruby-forum.com/topic/136825 (path provided by James Reeves)
39
+
40
+ # 1.6.1
41
+
42
+ - add response body in Exception#inspect
43
+ - add support for RestClient.options
44
+ - fix tests for 1.9.2 (patch provided by Niko Dittmann)
45
+ - block passing in Resource#[] (patch provided by Niko Dittmann)
46
+ - cookies set in a response should be kept in a redirect
47
+ - HEAD requests should process parameters just like GET (patch provided by Rob Eanes)
48
+ - exception message should never be nil (patch provided by Michael Klett)
49
+
50
+ # 1.6.0
51
+
52
+ - forgot to include rest-client.rb in the gem
53
+ - user, password and user-defined headers should survive a redirect
54
+ - added all missing status codes
55
+ - added parameter passing for get request using the :param key in header
56
+ - the warning about the logger when using a string was a bad idea
57
+ - multipart parameters names should not be escaped
58
+ - remove the cookie escaping introduced by migrating to CGI cookie parsing in 1.5.1
59
+ - add a streamed payload type (patch provided by Caleb Land)
60
+ - Exception#http_body works even when no response
61
+
62
+ # 1.5.1
63
+
64
+ - only converts headers keys which are Symbols
65
+ - use CGI for cookie parsing instead of custom code
66
+ - unescape user and password before using them (patch provided by Lars Gierth)
67
+ - expand ~ in ~/.restclientrc (patch provided by Mike Fletcher)
68
+ - ssl verification raise an exception when the ca certificate is incorrect (patch provided by Braintree)
69
+
70
+ # 1.5.0
71
+
72
+ - the response is now a String with the Response module a.k.a. the change in 1.4.0 was a mistake (Response.body is returning self for compatability)
73
+ - added AbstractResponse.to_i to improve semantic
74
+ - multipart Payloads ignores the name attribute if it's not set (patch provided by Tekin Suleyman)
75
+ - correctly takes into account user headers whose keys are strings (path provided by Cyril Rohr)
76
+ - use binary mode for payload temp file
77
+ - concatenate cookies with ';'
78
+ - fixed deeper parameter handling
79
+ - do not quote the boundary in the Content-Type header (patch provided by W. Andrew Loe III)
80
+
81
+ # 1.4.2
82
+
83
+ - fixed RestClient.add_before_execution_proc (patch provided by Nicholas Wieland)
84
+ - fixed error when an exception is raised without a response (patch provided by Caleb Land)
85
+
86
+ # 1.4.1
87
+
88
+ - fixed parameters managment when using hash
89
+
90
+ # 1.4.0
91
+
92
+ - Response is no more a String, and the mixin is replaced by an abstract_response, existing calls are redirected to response body with a warning.
93
+ - enable repeated parameters RestClient.post 'http://example.com/resource', :param1 => ['one', 'two', 'three'], => :param2 => 'foo' (patch provided by Rodrigo Panachi)
94
+ - fixed the redirect code concerning relative path and query string combination (patch provided by Kevin Read)
95
+ - redirection code moved to Response so redirection can be customized using the block syntax
96
+ - only get and head redirections are now followed by default, as stated in the specification
97
+ - added RestClient.add_before_execution_proc to hack the http request, like for oauth
98
+
99
+ The response change may be breaking in rare cases.
100
+
101
+ # 1.3.1
102
+
103
+ - added compatibility to enable responses in exception to act like Net::HTTPResponse
104
+
105
+ # 1.3.0
106
+
107
+ - a block can be used to process a request's result, this enable to handle custom error codes or paththrought (design by Cyril Rohr)
108
+ - cleaner log API, add a warning for some cases but should be compatible
109
+ - accept multiple "Set-Cookie" headers, see http://www.ietf.org/rfc/rfc2109.txt (patch provided by Cyril Rohr)
110
+ - remove "Content-Length" and "Content-Type" headers when following a redirection (patch provided by haarts)
111
+ - all http error codes have now a corresponding exception class and all of them contain the Reponse -> this means that the raised exception can be different
112
+ - changed "Content-Disposition: multipart/form-data" to "Content-Disposition: form-data" per RFC 2388 (patch provided by Kyle Crawford)
113
+
114
+ The only breaking change should be the exception classes, but as the new classes inherits from the existing ones, the breaking cases should be rare.
115
+
116
+ # 1.2.0
117
+
118
+ - formatting changed from tabs to spaces
119
+ - logged requests now include generated headers
120
+ - accept and content-type headers can now be specified using extentions: RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
121
+ - should be 1.1.1 but renamed to 1.2.0 because 1.1.X versions has already been packaged on Debian
122
+
123
+ # 1.1.0
124
+
125
+ - new maintainer: Archiloque, the working repo is now at http://github.com/archiloque/rest-client
126
+ - a mailing list has been created at rest.client@librelist.com and an freenode irc channel #rest-client
127
+ - François Beausoleil' multipart code from http://github.com/francois/rest-client has been merged
128
+ - ability to use hash in hash as payload
129
+ - the mime-type code now rely on the mime-types gem http://mime-types.rubyforge.org/ instead of an internal partial list
130
+ - 204 response returns a Response instead of nil (patch provided by Elliott Draper)
131
+
132
+ All changes exept the last one should be fully compatible with the previous version.
133
+
134
+ NOTE: due to a dependency problem and to the last change, heroku users should update their heroku gem to >= 1.5.3 to be able to use this version.