cft_smartcloud 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG +8 -0
- data/LICENSE +178 -0
- data/README.rdoc +71 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/smartcloud +37 -0
- data/cft_smartcloud.gemspec +176 -0
- data/lib/cli_tools/README.txt +50 -0
- data/lib/cli_tools/ic-add-keypair.cmd +29 -0
- data/lib/cli_tools/ic-add-keypair.sh +15 -0
- data/lib/cli_tools/ic-allocate-address.cmd +29 -0
- data/lib/cli_tools/ic-allocate-address.sh +14 -0
- data/lib/cli_tools/ic-attach-volume.cmd +27 -0
- data/lib/cli_tools/ic-attach-volume.sh +27 -0
- data/lib/cli_tools/ic-clone-image.cmd +27 -0
- data/lib/cli_tools/ic-clone-image.sh +14 -0
- data/lib/cli_tools/ic-clone-volume.cmd +27 -0
- data/lib/cli_tools/ic-clone-volume.sh +60 -0
- data/lib/cli_tools/ic-cmd.cmd +41 -0
- data/lib/cli_tools/ic-cmd.sh +38 -0
- data/lib/cli_tools/ic-create-instance.cmd +27 -0
- data/lib/cli_tools/ic-create-instance.sh +14 -0
- data/lib/cli_tools/ic-create-password.cmd +27 -0
- data/lib/cli_tools/ic-create-password.sh +14 -0
- data/lib/cli_tools/ic-create-volume.cmd +27 -0
- data/lib/cli_tools/ic-create-volume.sh +14 -0
- data/lib/cli_tools/ic-delete-image.cmd +27 -0
- data/lib/cli_tools/ic-delete-image.sh +14 -0
- data/lib/cli_tools/ic-delete-instance.cmd +27 -0
- data/lib/cli_tools/ic-delete-instance.sh +14 -0
- data/lib/cli_tools/ic-delete-volume.cmd +27 -0
- data/lib/cli_tools/ic-delete-volume.sh +14 -0
- data/lib/cli_tools/ic-describe-address-offerings.cmd +27 -0
- data/lib/cli_tools/ic-describe-address-offerings.sh +14 -0
- data/lib/cli_tools/ic-describe-addresses.cmd +27 -0
- data/lib/cli_tools/ic-describe-addresses.sh +14 -0
- data/lib/cli_tools/ic-describe-image-agreement.cmd +27 -0
- data/lib/cli_tools/ic-describe-image-agreement.sh +14 -0
- data/lib/cli_tools/ic-describe-image.cmd +27 -0
- data/lib/cli_tools/ic-describe-image.sh +14 -0
- data/lib/cli_tools/ic-describe-images.cmd +27 -0
- data/lib/cli_tools/ic-describe-images.sh +14 -0
- data/lib/cli_tools/ic-describe-instance.cmd +27 -0
- data/lib/cli_tools/ic-describe-instance.sh +14 -0
- data/lib/cli_tools/ic-describe-instances.cmd +27 -0
- data/lib/cli_tools/ic-describe-instances.sh +14 -0
- data/lib/cli_tools/ic-describe-keypair.cmd +27 -0
- data/lib/cli_tools/ic-describe-keypair.sh +14 -0
- data/lib/cli_tools/ic-describe-keypairs.cmd +27 -0
- data/lib/cli_tools/ic-describe-keypairs.sh +14 -0
- data/lib/cli_tools/ic-describe-location.cmd +14 -0
- data/lib/cli_tools/ic-describe-location.sh +14 -0
- data/lib/cli_tools/ic-describe-locations.cmd +14 -0
- data/lib/cli_tools/ic-describe-locations.sh +14 -0
- data/lib/cli_tools/ic-describe-request.cmd +27 -0
- data/lib/cli_tools/ic-describe-request.sh +14 -0
- data/lib/cli_tools/ic-describe-vlans.cmd +27 -0
- data/lib/cli_tools/ic-describe-vlans.sh +14 -0
- data/lib/cli_tools/ic-describe-volume-offerings.cmd +27 -0
- data/lib/cli_tools/ic-describe-volume-offerings.sh +14 -0
- data/lib/cli_tools/ic-describe-volume.cmd +27 -0
- data/lib/cli_tools/ic-describe-volume.sh +14 -0
- data/lib/cli_tools/ic-describe-volumes.cmd +27 -0
- data/lib/cli_tools/ic-describe-volumes.sh +14 -0
- data/lib/cli_tools/ic-detach-volume.cmd +27 -0
- data/lib/cli_tools/ic-detach-volume.sh +27 -0
- data/lib/cli_tools/ic-extend-reservation.cmd +27 -0
- data/lib/cli_tools/ic-extend-reservation.sh +14 -0
- data/lib/cli_tools/ic-generate-keypair.cmd +27 -0
- data/lib/cli_tools/ic-generate-keypair.sh +14 -0
- data/lib/cli_tools/ic-release-address.cmd +27 -0
- data/lib/cli_tools/ic-release-address.sh +14 -0
- data/lib/cli_tools/ic-remove-keypair.cmd +27 -0
- data/lib/cli_tools/ic-remove-keypair.sh +14 -0
- data/lib/cli_tools/ic-restart-instance.cmd +27 -0
- data/lib/cli_tools/ic-restart-instance.sh +14 -0
- data/lib/cli_tools/ic-save-instance.cmd +27 -0
- data/lib/cli_tools/ic-save-instance.sh +14 -0
- data/lib/cli_tools/ic-set-default-key.cmd +27 -0
- data/lib/cli_tools/ic-set-default-key.sh +14 -0
- data/lib/cli_tools/ic-update-instance.cmd +27 -0
- data/lib/cli_tools/ic-update-instance.sh +14 -0
- data/lib/cli_tools/ic-update-keypair.cmd +27 -0
- data/lib/cli_tools/ic-update-keypair.sh +14 -0
- data/lib/cli_tools/lib/DeveloperCloud_API_Client_JAR.jar +0 -0
- data/lib/cli_tools/lib/DeveloperCloud_CMD_Tool.jar +0 -0
- data/lib/cli_tools/lib/commons-beanutils-1.6.1.jar +0 -0
- data/lib/cli_tools/lib/commons-cli-1.2.jar +0 -0
- data/lib/cli_tools/lib/commons-codec-1.3.jar +0 -0
- data/lib/cli_tools/lib/commons-collections-3.2.1.jar +0 -0
- data/lib/cli_tools/lib/commons-digester-1.8.jar +0 -0
- data/lib/cli_tools/lib/commons-httpclient-3.1.jar +0 -0
- data/lib/cli_tools/lib/commons-lang-2.3.jar +0 -0
- data/lib/cli_tools/lib/commons-logging-1.1.1.jar +0 -0
- data/lib/cli_tools/logging.properties +7 -0
- data/lib/cli_tools/manifest.rmd +26 -0
- data/lib/config/config.yml +50 -0
- data/lib/hash_fix.rb +37 -0
- data/lib/mime-types-1.16/History.txt +107 -0
- data/lib/mime-types-1.16/Install.txt +17 -0
- data/lib/mime-types-1.16/Licence.txt +15 -0
- data/lib/mime-types-1.16/Manifest.txt +12 -0
- data/lib/mime-types-1.16/README.txt +28 -0
- data/lib/mime-types-1.16/Rakefile +316 -0
- data/lib/mime-types-1.16/lib/mime/types.rb +751 -0
- data/lib/mime-types-1.16/lib/mime/types.rb.data +1324 -0
- data/lib/mime-types-1.16/mime-types.gemspec +43 -0
- data/lib/mime-types-1.16/setup.rb +1585 -0
- data/lib/mime-types-1.16/test/test_mime_type.rb +356 -0
- data/lib/mime-types-1.16/test/test_mime_types.rb +122 -0
- data/lib/mock_smartcloud.rb +53 -0
- data/lib/rest-client-1.6.3/README.rdoc +276 -0
- data/lib/rest-client-1.6.3/Rakefile +66 -0
- data/lib/rest-client-1.6.3/VERSION +1 -0
- data/lib/rest-client-1.6.3/bin/restclient +92 -0
- data/lib/rest-client-1.6.3/history.md +112 -0
- data/lib/rest-client-1.6.3/lib/rest-client.rb +2 -0
- data/lib/rest-client-1.6.3/lib/rest_client.rb +2 -0
- data/lib/rest-client-1.6.3/lib/restclient/abstract_response.rb +106 -0
- data/lib/rest-client-1.6.3/lib/restclient/exceptions.rb +193 -0
- data/lib/rest-client-1.6.3/lib/restclient/net_http_ext.rb +21 -0
- data/lib/rest-client-1.6.3/lib/restclient/payload.rb +220 -0
- data/lib/rest-client-1.6.3/lib/restclient/raw_response.rb +34 -0
- data/lib/rest-client-1.6.3/lib/restclient/request.rb +314 -0
- data/lib/rest-client-1.6.3/lib/restclient/resource.rb +169 -0
- data/lib/rest-client-1.6.3/lib/restclient/response.rb +24 -0
- data/lib/rest-client-1.6.3/lib/restclient.rb +174 -0
- data/lib/restclient_fix.rb +41 -0
- data/lib/smartcloud.rb +616 -0
- data/lib/smartcloud_logger.rb +20 -0
- data/lib/xml-simple-1.0.12/lib/xmlsimple.rb +1028 -0
- data/script/console +3 -0
- data/test/helper.rb +22 -0
- metadata +196 -0
@@ -0,0 +1,276 @@
|
|
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
|
+
== Cookies
|
221
|
+
|
222
|
+
Request and Response objects know about HTTP cookies, and will automatically
|
223
|
+
extract and set headers for them as needed:
|
224
|
+
|
225
|
+
response = RestClient.get 'http://example.com/action_which_sets_session_id'
|
226
|
+
response.cookies
|
227
|
+
# => {"_applicatioN_session_id" => "1234"}
|
228
|
+
|
229
|
+
response2 = RestClient.post(
|
230
|
+
'http://localhost:3000/',
|
231
|
+
{:param1 => "foo"},
|
232
|
+
{:cookies => {:session_id => "1234"}}
|
233
|
+
)
|
234
|
+
# ...response body
|
235
|
+
|
236
|
+
== SSL Client Certificates
|
237
|
+
|
238
|
+
RestClient::Resource.new(
|
239
|
+
'https://example.com',
|
240
|
+
:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
|
241
|
+
:ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
|
242
|
+
:ssl_ca_file => "ca_certificate.pem",
|
243
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
|
244
|
+
).get
|
245
|
+
|
246
|
+
Self-signed certificates can be generated with the openssl command-line tool.
|
247
|
+
|
248
|
+
== Hook
|
249
|
+
|
250
|
+
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.
|
251
|
+
|
252
|
+
Example:
|
253
|
+
|
254
|
+
# Add oath support using the oauth gem
|
255
|
+
require 'oauth'
|
256
|
+
access_token = ...
|
257
|
+
|
258
|
+
RestClient.add_before_execution_proc do |req, params|
|
259
|
+
access_token.sign! req
|
260
|
+
end
|
261
|
+
|
262
|
+
RestClient.get 'http://example.com'
|
263
|
+
|
264
|
+
== More
|
265
|
+
|
266
|
+
Need caching, more advanced logging or any ability provided by a rack middleware ?
|
267
|
+
|
268
|
+
Have a look at rest-client-components http://github.com/crohr/rest-client-components
|
269
|
+
|
270
|
+
== Meta
|
271
|
+
|
272
|
+
Written by Adam Wiggins, major modifications by Blake Mizerany, maintained by Julien Kirch
|
273
|
+
|
274
|
+
Patches contributed by many, including Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, François Beausoleil and Nick Plante.
|
275
|
+
|
276
|
+
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
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
1.6.3
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
4
|
+
require 'restclient'
|
5
|
+
|
6
|
+
require "yaml"
|
7
|
+
|
8
|
+
def usage(why = nil)
|
9
|
+
puts "failed for reason: #{why}" if why
|
10
|
+
puts "usage: restclient [get|put|post|delete] url|name [username] [password]"
|
11
|
+
puts " The verb is optional, if you leave it off you'll get an interactive shell."
|
12
|
+
puts " put and post both take the input body on stdin."
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
POSSIBLE_VERBS = ['get', 'put', 'post', 'delete']
|
17
|
+
|
18
|
+
if POSSIBLE_VERBS.include? ARGV.first
|
19
|
+
@verb = ARGV.shift
|
20
|
+
else
|
21
|
+
@verb = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
@url = ARGV.shift || 'http://localhost:4567'
|
25
|
+
|
26
|
+
config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
|
27
|
+
|
28
|
+
@url, @username, @password = if c = config[@url]
|
29
|
+
[c['url'], c['username'], c['password']]
|
30
|
+
else
|
31
|
+
[@url, * ARGV]
|
32
|
+
end
|
33
|
+
|
34
|
+
usage("invalid url '#{@url}") unless @url =~ /^https?/
|
35
|
+
usage("too few args") unless ARGV.size < 3
|
36
|
+
|
37
|
+
def r
|
38
|
+
@r ||= RestClient::Resource.new(@url, @username, @password)
|
39
|
+
end
|
40
|
+
|
41
|
+
r # force rc to load
|
42
|
+
|
43
|
+
if @verb
|
44
|
+
begin
|
45
|
+
if %w( put post ).include? @verb
|
46
|
+
puts r.send(@verb, STDIN.read)
|
47
|
+
else
|
48
|
+
puts r.send(@verb)
|
49
|
+
end
|
50
|
+
exit 0
|
51
|
+
rescue RestClient::Exception => e
|
52
|
+
puts e.response.body if e.respond_to? :response
|
53
|
+
raise
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
POSSIBLE_VERBS.each do |m|
|
58
|
+
eval <<-end_eval
|
59
|
+
def #{m} (path, *args, &b)
|
60
|
+
r[path]. #{m} (*args, &b)
|
61
|
+
end
|
62
|
+
end_eval
|
63
|
+
end
|
64
|
+
|
65
|
+
def method_missing(s, * args, & b)
|
66
|
+
if POSSIBLE_VERBS.include? s
|
67
|
+
begin
|
68
|
+
r.send(s, *args, & b)
|
69
|
+
rescue RestClient::RequestFailed => e
|
70
|
+
print STDERR, e.response.body
|
71
|
+
raise e
|
72
|
+
end
|
73
|
+
else
|
74
|
+
super
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
require 'irb'
|
79
|
+
require 'irb/completion'
|
80
|
+
|
81
|
+
if File.exists? ".irbrc"
|
82
|
+
ENV['IRBRC'] = ".irbrc"
|
83
|
+
end
|
84
|
+
|
85
|
+
if File.exists?(File.expand_path(rcfile = "~/.restclientrc"))
|
86
|
+
load(rcfile)
|
87
|
+
end
|
88
|
+
|
89
|
+
ARGV.clear
|
90
|
+
|
91
|
+
IRB.start
|
92
|
+
exit!
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# 1.6.3
|
2
|
+
- 1.6.2 was yanked
|
3
|
+
|
4
|
+
# 1.6.2
|
5
|
+
|
6
|
+
- add support for HEAD in resources (patch provided by tpresa)
|
7
|
+
- fix shell for 1.9.2
|
8
|
+
- workaround when some gem monkeypatch net/http (patch provided by Ian Warshak)
|
9
|
+
- DELETE requests should process parameters just like GET and HEAD
|
10
|
+
- adding :block_response parameter for manual processing
|
11
|
+
- limit number of redirections (patch provided by Chris Dinn)
|
12
|
+
- close and unlink the temp file created by playload (patch provided by Chris Green)
|
13
|
+
- make gemspec Rubygems 1.8 compatible (patch provided by David Backeus)
|
14
|
+
- added RestClient.reset_before_execution_procs (patch provided by Cloudify)
|
15
|
+
- added PATCH method (patch provided by Jeff Remer)
|
16
|
+
- hack for HTTP servers that use raw DEFLATE compression, see http://www.ruby-forum.com/topic/136825 (path provided by James Reeves)
|
17
|
+
|
18
|
+
# 1.6.1
|
19
|
+
|
20
|
+
- add response body in Exception#inspect
|
21
|
+
- add support for RestClient.options
|
22
|
+
- fix tests for 1.9.2 (patch provided by Niko Dittmann)
|
23
|
+
- block passing in Resource#[] (patch provided by Niko Dittmann)
|
24
|
+
- cookies set in a response should be kept in a redirect
|
25
|
+
- HEAD requests should process parameters just like GET (patch provided by Rob Eanes)
|
26
|
+
- exception message should never be nil (patch provided by Michael Klett)
|
27
|
+
|
28
|
+
# 1.6.0
|
29
|
+
|
30
|
+
- forgot to include rest-client.rb in the gem
|
31
|
+
- user, password and user-defined headers should survive a redirect
|
32
|
+
- added all missing status codes
|
33
|
+
- added parameter passing for get request using the :param key in header
|
34
|
+
- the warning about the logger when using a string was a bad idea
|
35
|
+
- multipart parameters names should not be escaped
|
36
|
+
- remove the cookie escaping introduced by migrating to CGI cookie parsing in 1.5.1
|
37
|
+
- add a streamed payload type (patch provided by Caleb Land)
|
38
|
+
- Exception#http_body works even when no response
|
39
|
+
|
40
|
+
# 1.5.1
|
41
|
+
|
42
|
+
- only converts headers keys which are Symbols
|
43
|
+
- use CGI for cookie parsing instead of custom code
|
44
|
+
- unescape user and password before using them (patch provided by Lars Gierth)
|
45
|
+
- expand ~ in ~/.restclientrc (patch provided by Mike Fletcher)
|
46
|
+
- ssl verification raise an exception when the ca certificate is incorrect (patch provided by Braintree)
|
47
|
+
|
48
|
+
# 1.5.0
|
49
|
+
|
50
|
+
- 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)
|
51
|
+
- added AbstractResponse.to_i to improve semantic
|
52
|
+
- multipart Payloads ignores the name attribute if it's not set (patch provided by Tekin Suleyman)
|
53
|
+
- correctly takes into account user headers whose keys are strings (path provided by Cyril Rohr)
|
54
|
+
- use binary mode for payload temp file
|
55
|
+
- concatenate cookies with ';'
|
56
|
+
- fixed deeper parameter handling
|
57
|
+
- do not quote the boundary in the Content-Type header (patch provided by W. Andrew Loe III)
|
58
|
+
|
59
|
+
# 1.4.2
|
60
|
+
|
61
|
+
- fixed RestClient.add_before_execution_proc (patch provided by Nicholas Wieland)
|
62
|
+
- fixed error when an exception is raised without a response (patch provided by Caleb Land)
|
63
|
+
|
64
|
+
# 1.4.1
|
65
|
+
|
66
|
+
- fixed parameters managment when using hash
|
67
|
+
|
68
|
+
# 1.4.0
|
69
|
+
|
70
|
+
- 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.
|
71
|
+
- enable repeated parameters RestClient.post 'http://example.com/resource', :param1 => ['one', 'two', 'three'], => :param2 => 'foo' (patch provided by Rodrigo Panachi)
|
72
|
+
- fixed the redirect code concerning relative path and query string combination (patch provided by Kevin Read)
|
73
|
+
- redirection code moved to Response so redirection can be customized using the block syntax
|
74
|
+
- only get and head redirections are now followed by default, as stated in the specification
|
75
|
+
- added RestClient.add_before_execution_proc to hack the http request, like for oauth
|
76
|
+
|
77
|
+
The response change may be breaking in rare cases.
|
78
|
+
|
79
|
+
# 1.3.1
|
80
|
+
|
81
|
+
- added compatibility to enable responses in exception to act like Net::HTTPResponse
|
82
|
+
|
83
|
+
# 1.3.0
|
84
|
+
|
85
|
+
- a block can be used to process a request's result, this enable to handle custom error codes or paththrought (design by Cyril Rohr)
|
86
|
+
- cleaner log API, add a warning for some cases but should be compatible
|
87
|
+
- accept multiple "Set-Cookie" headers, see http://www.ietf.org/rfc/rfc2109.txt (patch provided by Cyril Rohr)
|
88
|
+
- remove "Content-Length" and "Content-Type" headers when following a redirection (patch provided by haarts)
|
89
|
+
- 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
|
90
|
+
- changed "Content-Disposition: multipart/form-data" to "Content-Disposition: form-data" per RFC 2388 (patch provided by Kyle Crawford)
|
91
|
+
|
92
|
+
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.
|
93
|
+
|
94
|
+
# 1.2.0
|
95
|
+
|
96
|
+
- formatting changed from tabs to spaces
|
97
|
+
- logged requests now include generated headers
|
98
|
+
- 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
|
99
|
+
- should be 1.1.1 but renamed to 1.2.0 because 1.1.X versions has already been packaged on Debian
|
100
|
+
|
101
|
+
# 1.1.0
|
102
|
+
|
103
|
+
- new maintainer: Archiloque, the working repo is now at http://github.com/archiloque/rest-client
|
104
|
+
- a mailing list has been created at rest.client@librelist.com and an freenode irc channel #rest-client
|
105
|
+
- François Beausoleil' multipart code from http://github.com/francois/rest-client has been merged
|
106
|
+
- ability to use hash in hash as payload
|
107
|
+
- the mime-type code now rely on the mime-types gem http://mime-types.rubyforge.org/ instead of an internal partial list
|
108
|
+
- 204 response returns a Response instead of nil (patch provided by Elliott Draper)
|
109
|
+
|
110
|
+
All changes exept the last one should be fully compatible with the previous version.
|
111
|
+
|
112
|
+
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.
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module RestClient
|
4
|
+
|
5
|
+
module AbstractResponse
|
6
|
+
|
7
|
+
attr_reader :net_http_res, :args
|
8
|
+
|
9
|
+
# HTTP status code
|
10
|
+
def code
|
11
|
+
@code ||= @net_http_res.code.to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
# A hash of the headers, beautified with symbols and underscores.
|
15
|
+
# e.g. "Content-type" will become :content_type.
|
16
|
+
def headers
|
17
|
+
@headers ||= AbstractResponse.beautify_headers(@net_http_res.to_hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
# The raw headers.
|
21
|
+
def raw_headers
|
22
|
+
@raw_headers ||= @net_http_res.to_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
# Hash of cookies extracted from response headers
|
26
|
+
def cookies
|
27
|
+
@cookies ||= (self.headers[:set_cookie] || {}).inject({}) do |out, cookie_content|
|
28
|
+
out.merge parse_cookie(cookie_content)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return the default behavior corresponding to the response code:
|
33
|
+
# the response itself for code in 200..206, redirection for 301, 302 and 307 in get and head cases, redirection for 303 and an exception in other cases
|
34
|
+
def return! request = nil, result = nil, & block
|
35
|
+
if (200..207).include? code
|
36
|
+
self
|
37
|
+
elsif [301, 302, 307].include? code
|
38
|
+
unless [:get, :head].include? args[:method]
|
39
|
+
raise Exceptions::EXCEPTIONS_MAP[code].new(self, code)
|
40
|
+
else
|
41
|
+
follow_redirection(request, result, & block)
|
42
|
+
end
|
43
|
+
elsif code == 303
|
44
|
+
args[:method] = :get
|
45
|
+
args.delete :payload
|
46
|
+
follow_redirection(request, result, & block)
|
47
|
+
elsif Exceptions::EXCEPTIONS_MAP[code]
|
48
|
+
raise Exceptions::EXCEPTIONS_MAP[code].new(self, code)
|
49
|
+
else
|
50
|
+
raise RequestFailed.new(self, code)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_i
|
55
|
+
code
|
56
|
+
end
|
57
|
+
|
58
|
+
def description
|
59
|
+
"#{code} #{STATUSES[code]} | #{(headers[:content_type] || '').gsub(/;.*$/, '')} #{size} bytes\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Follow a redirection
|
63
|
+
def follow_redirection request = nil, result = nil, & block
|
64
|
+
url = headers[:location]
|
65
|
+
if url !~ /^http/
|
66
|
+
url = URI.parse(args[:url]).merge(url).to_s
|
67
|
+
end
|
68
|
+
args[:url] = url
|
69
|
+
if request
|
70
|
+
if request.max_redirects == 0
|
71
|
+
raise MaxRedirectsReached
|
72
|
+
end
|
73
|
+
args[:password] = request.password
|
74
|
+
args[:user] = request.user
|
75
|
+
args[:headers] = request.headers
|
76
|
+
args[:max_redirects] = request.max_redirects - 1
|
77
|
+
# pass any cookie set in the result
|
78
|
+
if result && result['set-cookie']
|
79
|
+
args[:headers][:cookies] = (args[:headers][:cookies] || {}).merge(parse_cookie(result['set-cookie']))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
Request.execute args, &block
|
83
|
+
end
|
84
|
+
|
85
|
+
def AbstractResponse.beautify_headers(headers)
|
86
|
+
headers.inject({}) do |out, (key, value)|
|
87
|
+
out[key.gsub(/-/, '_').downcase.to_sym] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
|
88
|
+
out
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Parse a cookie value and return its content in an Hash
|
95
|
+
def parse_cookie cookie_content
|
96
|
+
out = {}
|
97
|
+
CGI::Cookie::parse(cookie_content).each do |key, cookie|
|
98
|
+
unless ['expires', 'path'].include? key
|
99
|
+
out[CGI::escape(key)] = cookie.value[0] ? (CGI::escape(cookie.value[0]) || '') : ''
|
100
|
+
end
|
101
|
+
end
|
102
|
+
out
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|