rest-client-maestro 1.7.2.maestro

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +1 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +8 -0
  5. data/AUTHORS +69 -0
  6. data/Gemfile +7 -0
  7. data/README.rdoc +322 -0
  8. data/Rakefile +49 -0
  9. data/bin/restclient +93 -0
  10. data/history.md +134 -0
  11. data/lib/rest-client.rb +2 -0
  12. data/lib/rest_client.rb +2 -0
  13. data/lib/restclient/abstract_response.rb +106 -0
  14. data/lib/restclient/exceptions.rb +198 -0
  15. data/lib/restclient/net_http_ext.rb +55 -0
  16. data/lib/restclient/payload.rb +242 -0
  17. data/lib/restclient/raw_response.rb +34 -0
  18. data/lib/restclient/request.rb +346 -0
  19. data/lib/restclient/resource.rb +169 -0
  20. data/lib/restclient/response.rb +26 -0
  21. data/lib/restclient.rb +174 -0
  22. data/rest-client-maestro.gemspec +23 -0
  23. data/spec/integration/capath_equifax/578d5c04.0 +19 -0
  24. data/spec/integration/capath_equifax/594f1775.0 +19 -0
  25. data/spec/integration/capath_equifax/README +8 -0
  26. data/spec/integration/capath_equifax/equifax.crt +19 -0
  27. data/spec/integration/capath_verisign/415660c1.0 +14 -0
  28. data/spec/integration/capath_verisign/7651b327.0 +14 -0
  29. data/spec/integration/capath_verisign/README +8 -0
  30. data/spec/integration/capath_verisign/verisign.crt +14 -0
  31. data/spec/integration/certs/equifax.crt +19 -0
  32. data/spec/integration/certs/verisign.crt +14 -0
  33. data/spec/integration/integration_spec.rb +35 -0
  34. data/spec/integration/request_spec.rb +63 -0
  35. data/spec/spec_helper.rb +12 -0
  36. data/spec/unit/abstract_response_spec.rb +85 -0
  37. data/spec/unit/exceptions_spec.rb +95 -0
  38. data/spec/unit/master_shake.jpg +0 -0
  39. data/spec/unit/payload_spec.rb +245 -0
  40. data/spec/unit/raw_response_spec.rb +17 -0
  41. data/spec/unit/request2_spec.rb +32 -0
  42. data/spec/unit/request_spec.rb +621 -0
  43. data/spec/unit/resource_spec.rb +133 -0
  44. data/spec/unit/response_spec.rb +166 -0
  45. data/spec/unit/restclient_spec.rb +73 -0
  46. metadata +220 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .idea
3
+ .rvmrc
4
+ Gemfile.lock
5
+ doc
6
+ pkg
7
+ rdoc
8
+ scratchpad.rb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format progress --order random
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.4
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ branches:
7
+ except:
8
+ - "readme-edits"
data/AUTHORS ADDED
@@ -0,0 +1,69 @@
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
+ Blake Mizerany
8
+ Brad Ediger
9
+ Braintree
10
+ Brian Donovan
11
+ Caleb Land
12
+ Chris Dinn
13
+ Chris Green
14
+ Coda Hale
15
+ Crawford
16
+ Cyril Rohr
17
+ Dan Mayer
18
+ David Backeus
19
+ Dmitri Dolguikh
20
+ Dusty Doris
21
+ Dylan Egan
22
+ El Draper
23
+ Evan Smith
24
+ François Beausoleil
25
+ Gabriele Cirulli
26
+ Garry Shutler
27
+ Giovanni Cappellotto
28
+ Greg Borenstein
29
+ Harm Aarts
30
+ Hiro Asari
31
+ Hugh McGowan
32
+ Ian Warshak
33
+ Ivan Makfinsky
34
+ James Edward Gray II
35
+ Jari Bakken
36
+ Jeff Remer
37
+ JH. Chabran
38
+ John Barnette
39
+ Jordi Massaguer Pla
40
+ Juan Alvarez
41
+ Julien Kirch
42
+ Justin Coyne
43
+ Keith Rarick
44
+ Kenichi Kamiya
45
+ Kevin Read
46
+ Kyle VanderBeek
47
+ Lars Gierth
48
+ Lawrence Leonard Gilbert
49
+ Lee Jarvis
50
+ Lennon Day-Reynolds
51
+ macournoyer
52
+ Matthew Manning
53
+ Michael Klett
54
+ Mike Fletcher
55
+ Nicholas Wieland
56
+ Nick Plante
57
+ Niko Dittmann
58
+ Oscar Del Ben
59
+ Paul Dlug
60
+ Pedro Belo
61
+ rafael.ssouza
62
+ Rick "technoweenie"
63
+ Robert Eanes
64
+ Rodrigo Panachi
65
+ Syl Turner
66
+ T. Watanabe
67
+ Tekin
68
+ tpresa
69
+ W. Andrew Loe III
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
data/README.rdoc ADDED
@@ -0,0 +1,322 @@
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: http://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
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/)
data/Rakefile ADDED
@@ -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
+ RSpec::Core::RakeTask.new('spec')
11
+
12
+ desc "Run unit specs"
13
+ RSpec::Core::RakeTask.new('spec:unit') do |t|
14
+ t.pattern = 'spec/unit/*_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
+
data/bin/restclient ADDED
@@ -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!