auser-poolparty 1.2.10 → 1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/bin/cloud +1 -1
- data/bin/cloud-list +19 -7
- data/bin/cloud-provision +3 -0
- data/bin/cloud-run +37 -0
- data/bin/server-list-active +1 -1
- data/config/jeweler.rb +2 -2
- data/examples/basic.rb +4 -3
- data/examples/fairchild.rb +2 -2
- data/examples/metavirt_cloud.rb +18 -8
- data/examples/simple.rb +4 -3
- data/examples/vmrun_cloud.rb +2 -5
- data/lib/poolparty.rb +1 -1
- data/lib/poolparty/core/object.rb +6 -4
- data/lib/poolparty/core/string.rb +2 -1
- data/lib/poolparty/helpers/optioner.rb +1 -1
- data/lib/poolparty/modules/callbacks.rb +2 -0
- data/lib/poolparty/modules/cloud_resourcer.rb +4 -5
- data/lib/poolparty/modules/daemonizable.rb +4 -5
- data/lib/poolparty/modules/definable_resource.rb +1 -0
- data/lib/poolparty/modules/pinger.rb +5 -1
- data/lib/poolparty/monitors/monitor_daemon.rb +159 -0
- data/lib/poolparty/monitors/monitor_rack.rb +21 -11
- data/lib/poolparty/monitors/monitors/clock_monitor.rb +5 -0
- data/lib/poolparty/monitors/monitors/elections_monitor.rb +49 -0
- data/lib/poolparty/monitors/monitors/neighborhood_monitor.rb +7 -7
- data/lib/poolparty/monitors/monitors/stats_monitor.rb +15 -3
- data/lib/poolparty/net/init.rb +1 -1
- data/lib/poolparty/net/remote_instance.rb +43 -39
- data/lib/poolparty/net/remoter/connections.rb +6 -3
- data/lib/poolparty/net/remoter/interactive.rb +18 -11
- data/lib/poolparty/net/remoter_base.rb +39 -12
- data/lib/poolparty/net/remoter_bases/ec2/ec2.rb +23 -19
- data/lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb +15 -33
- data/lib/poolparty/net/remoter_bases/ec2/ec2_response_object.rb +28 -20
- data/lib/poolparty/net/remoter_bases/libvirt/libvirt.rb +73 -0
- data/lib/poolparty/net/remoter_bases/libvirt/libvirt_instance.rb +64 -0
- data/lib/poolparty/net/remoter_bases/metavirt/metavirt.rb +27 -17
- data/lib/poolparty/net/remoter_bases/metavirt/metavirt_instance.rb +20 -35
- data/lib/poolparty/net/remoter_bases/vmrun/vmrun.rb +35 -17
- data/lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb +32 -24
- data/lib/poolparty/plugins/apache2/apache.rb +1 -1
- data/lib/poolparty/plugins/chef/chef.rb +12 -26
- data/lib/poolparty/plugins/chef/chef_deploy.rb +5 -23
- data/lib/poolparty/plugins/chef/chef_deploy_definition.rb +32 -0
- data/lib/poolparty/plugins/chef/chef_library.rb +7 -0
- data/lib/poolparty/plugins/chef/chef_recipe.rb +7 -0
- data/lib/poolparty/plugins/chef/include_chef_recipe.rb +14 -0
- data/lib/poolparty/{resources → plugins}/host.rb +5 -4
- data/lib/poolparty/plugins/line_in_file.rb +1 -1
- data/lib/poolparty/{resources → plugins}/sshkey.rb +10 -8
- data/lib/poolparty/poolparty/cloud.rb +7 -0
- data/lib/poolparty/poolparty/default.rb +0 -2
- data/lib/poolparty/poolparty/pool.rb +13 -3
- data/lib/poolparty/provision/boot_strapper.rb +8 -8
- data/lib/poolparty/resources/exec.rb +7 -0
- data/lib/poolparty/resources/group.rb +3 -3
- data/lib/poolparty/resources/user.rb +6 -1
- data/lib/poolparty/templates/monitor.ru +12 -0
- data/spec/poolparty/net/remoter_bases/ec2_remote_instance_spec.rb +0 -2
- data/spec/poolparty/net/remoter_bases/ec2_spec.rb +7 -4
- data/spec/poolparty/poolparty/example_spec.rb +21 -21
- data/spec/poolparty/poolparty/pool_spec.rb +2 -1
- data/spec/poolparty/resources/sshkey_spec.rb +39 -40
- data/tasks/poolparty.rake +27 -1
- data/test/fixtures/fake_clouds.rb +11 -0
- data/test/poolparty/dependency_resolver/chef_resolver_test.rb +82 -0
- data/test/poolparty/monitors/test_base_monitor.rb +2 -2
- data/test/poolparty/monitors/test_monitor_rack.rb +11 -24
- data/test/poolparty/net/remoter_base_test.rb +4 -5
- data/test/poolparty/net/remoter_bases/libvirt/libvirt_test.rb +70 -0
- data/test/poolparty/net/remoter_bases/metavirt/metavirt_test.rb +32 -3
- data/test/poolparty/plugins/chef_plugin_test.rb +23 -0
- data/test/poolparty/poolparty/pool_test.rb +22 -0
- data/vendor/gems/dslify/lib/dslify.rb +3 -0
- data/vendor/gems/dslify/test/dslify_test.rb +4 -15
- data/vendor/gems/git-style-binaries/README.markdown +6 -0
- data/vendor/gems/git-style-binaries/Rakefile +1 -1
- data/vendor/gems/git-style-binaries/VERSION.yml +1 -1
- data/vendor/gems/git-style-binaries/doc/gsb-screencast.png +0 -0
- data/vendor/gems/git-style-binaries/doc/poolparty-binaries.screenplay +11 -13
- data/vendor/gems/git-style-binaries/git-style-binaries.gemspec +12 -3
- data/vendor/gems/git-style-binaries/lib/git-style-binary.rb +15 -1
- data/vendor/gems/git-style-binaries/test/running_binaries_test.rb +2 -2
- data/vendor/gems/suitcase/VERSION.yml +1 -1
- data/vendor/gems/suitcase/lib/suitcase/zipper.rb +73 -25
- data/vendor/gems/suitcase/suitcase.gemspec +5 -5
- data/vendor/gems/suitcase/test/suitcase_test.rb +12 -6
- data/vendor/gems/suitcase/test/test_dir/gems/famoseagle-carrot-0.6.0.gem +0 -0
- metadata +24 -52
- data/spec/poolparty/resources/host_spec.rb +0 -35
- data/vendor/gems/rest-client/README.rdoc +0 -151
- data/vendor/gems/rest-client/Rakefile +0 -85
- data/vendor/gems/rest-client/bin/restclient +0 -87
- data/vendor/gems/rest-client/lib/rest_client.rb +0 -2
- data/vendor/gems/rest-client/lib/restclient.rb +0 -93
- data/vendor/gems/rest-client/lib/restclient/exceptions.rb +0 -84
- data/vendor/gems/rest-client/lib/restclient/mixin/response.rb +0 -43
- data/vendor/gems/rest-client/lib/restclient/raw_response.rb +0 -30
- data/vendor/gems/rest-client/lib/restclient/request.rb +0 -232
- data/vendor/gems/rest-client/lib/restclient/resource.rb +0 -146
- data/vendor/gems/rest-client/lib/restclient/response.rb +0 -20
- data/vendor/gems/rest-client/rest-client.gemspec +0 -21
- data/vendor/gems/rest-client/spec/base.rb +0 -4
- data/vendor/gems/rest-client/spec/exceptions_spec.rb +0 -54
- data/vendor/gems/rest-client/spec/mixin/response_spec.rb +0 -46
- data/vendor/gems/rest-client/spec/raw_response_spec.rb +0 -17
- data/vendor/gems/rest-client/spec/request_spec.rb +0 -442
- data/vendor/gems/rest-client/spec/resource_spec.rb +0 -75
- data/vendor/gems/rest-client/spec/response_spec.rb +0 -16
- data/vendor/gems/rest-client/spec/restclient_spec.rb +0 -53
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe "Host" do
|
4
|
-
describe "instances" do
|
5
|
-
before(:each) do
|
6
|
-
@tc = TestBaseClass.new do
|
7
|
-
has_host({:name => "node10"}) do
|
8
|
-
aka "backup_mysql_master"
|
9
|
-
ip "10.0.0.1"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
@host = @tc.resource(:host).first
|
13
|
-
end
|
14
|
-
it "have the name in the options" do
|
15
|
-
@host.name.should == "node10"
|
16
|
-
end
|
17
|
-
it "should store the mode (from within the block)" do
|
18
|
-
@host.ip.should == "10.0.0.1"
|
19
|
-
end
|
20
|
-
describe "into PuppetResolver" do
|
21
|
-
before(:each) do
|
22
|
-
@compiled = PuppetResolver.new(@tc.to_properties_hash).compile
|
23
|
-
end
|
24
|
-
it "should set the name to the name of the host" do
|
25
|
-
@compiled.should match(/host \{ "node10"/)
|
26
|
-
end
|
27
|
-
it "set the ip to the ip" do
|
28
|
-
@compiled.should match(/ip => "10.0.0.1"/)
|
29
|
-
end
|
30
|
-
it "should say it's alias is set" do
|
31
|
-
@compiled.should match(/alias => "backup_mysql_master"/)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
= REST Client -- simple DSL for accessing REST resources
|
2
|
-
|
3
|
-
A simple REST client for Ruby, inspired by the Sinatra's microframework style
|
4
|
-
of specifying actions: get, put, post, delete.
|
5
|
-
|
6
|
-
== Usage: Raw URL
|
7
|
-
|
8
|
-
require 'rest_client'
|
9
|
-
|
10
|
-
RestClient.get 'http://example.com/resource'
|
11
|
-
RestClient.get 'https://user:password@example.com/private/resource'
|
12
|
-
|
13
|
-
RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
|
14
|
-
|
15
|
-
RestClient.delete 'http://example.com/resource'
|
16
|
-
|
17
|
-
See RestClient module docs for details.
|
18
|
-
|
19
|
-
== Usage: ActiveResource-Style
|
20
|
-
|
21
|
-
resource = RestClient::Resource.new 'http://example.com/resource'
|
22
|
-
resource.get
|
23
|
-
|
24
|
-
private_resource = RestClient::Resource.new 'https://example.com/private/resource', :user => 'adam', :password => 'secret', :timeout => 20, :open_timeout => 5
|
25
|
-
private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
|
26
|
-
|
27
|
-
See RestClient::Resource module docs for details.
|
28
|
-
|
29
|
-
== Usage: Resource Nesting
|
30
|
-
|
31
|
-
site = RestClient::Resource.new('http://example.com')
|
32
|
-
site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
|
33
|
-
|
34
|
-
See RestClient::Resource docs for details.
|
35
|
-
|
36
|
-
== Shell
|
37
|
-
|
38
|
-
The restclient shell command gives an IRB session with RestClient already loaded:
|
39
|
-
|
40
|
-
$ restclient
|
41
|
-
>> RestClient.get 'http://example.com'
|
42
|
-
|
43
|
-
Specify a URL argument for get/post/put/delete on that resource:
|
44
|
-
|
45
|
-
$ restclient http://example.com
|
46
|
-
>> put '/resource', 'data'
|
47
|
-
|
48
|
-
Add a user and password for authenticated resources:
|
49
|
-
|
50
|
-
$ restclient https://example.com user pass
|
51
|
-
>> delete '/private/resource'
|
52
|
-
|
53
|
-
Create ~/.restclient for named sessions:
|
54
|
-
|
55
|
-
sinatra:
|
56
|
-
url: http://localhost:4567
|
57
|
-
rack:
|
58
|
-
url: http://localhost:9292
|
59
|
-
private_site:
|
60
|
-
url: http://example.com
|
61
|
-
username: user
|
62
|
-
password: pass
|
63
|
-
|
64
|
-
Then invoke:
|
65
|
-
|
66
|
-
$ restclient private_site
|
67
|
-
|
68
|
-
Use as a one-off, curl-style:
|
69
|
-
|
70
|
-
$ restclient get http://example.com/resource > output_body
|
71
|
-
|
72
|
-
$ restclient put http://example.com/resource < input_body
|
73
|
-
|
74
|
-
== Logging
|
75
|
-
|
76
|
-
Write calls to a log filename (can also be "stdout" or "stderr"):
|
77
|
-
|
78
|
-
RestClient.log = '/tmp/restclient.log'
|
79
|
-
|
80
|
-
Or set an environment variable to avoid modifying the code:
|
81
|
-
|
82
|
-
$ RESTCLIENT_LOG=stdout path/to/my/program
|
83
|
-
|
84
|
-
Either produces logs like this:
|
85
|
-
|
86
|
-
RestClient.get "http://some/resource"
|
87
|
-
# => 200 OK | text/html 250 bytes
|
88
|
-
RestClient.put "http://some/resource", "payload"
|
89
|
-
# => 401 Unauthorized | application/xml 340 bytes
|
90
|
-
|
91
|
-
Note that these logs are valid Ruby, so you can paste them into the restclient
|
92
|
-
shell or a script to replay your sequence of rest calls.
|
93
|
-
|
94
|
-
== Proxy
|
95
|
-
|
96
|
-
All calls to RestClient, including Resources, will use the proxy specified by
|
97
|
-
RestClient.proxy:
|
98
|
-
|
99
|
-
RestClient.proxy = "http://proxy.example.com/"
|
100
|
-
RestClient.get "http://some/resource"
|
101
|
-
# => response from some/resource as proxied through proxy.example.com
|
102
|
-
|
103
|
-
Often the proxy url is set in an environment variable, so you can do this to
|
104
|
-
use whatever proxy the system is configured to use:
|
105
|
-
|
106
|
-
RestClient.proxy = ENV['http_proxy']
|
107
|
-
|
108
|
-
== Cookies
|
109
|
-
|
110
|
-
Request and Response objects know about HTTP cookies, and will automatically
|
111
|
-
extract and set headers for them as needed:
|
112
|
-
|
113
|
-
response = RestClient.get 'http://example.com/action_which_sets_session_id'
|
114
|
-
response.cookies
|
115
|
-
# => {"_applicatioN_session_id" => "1234"}
|
116
|
-
|
117
|
-
response2 = RestClient.post(
|
118
|
-
'http://localhost:3000/',
|
119
|
-
{:param1 => "foo"},
|
120
|
-
{:cookies => {:session_id => "1234"}}
|
121
|
-
)
|
122
|
-
# ...response body
|
123
|
-
|
124
|
-
== SSL Client Certificates
|
125
|
-
|
126
|
-
RestClient::Resource.new(
|
127
|
-
'https://example.com',
|
128
|
-
:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
|
129
|
-
:ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
|
130
|
-
:ssl_ca_file => "ca_certificate.pem",
|
131
|
-
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
|
132
|
-
).get
|
133
|
-
|
134
|
-
Self-signed certificates can be generated with the openssl command-line tool.
|
135
|
-
|
136
|
-
== Meta
|
137
|
-
|
138
|
-
Written by Adam Wiggins (adam at heroku dot com)
|
139
|
-
|
140
|
-
Patches contributed by: Chris Anderson, Greg Borenstein, Ardekantur, Pedro
|
141
|
-
Belo, Rafael Souza, Rick Olson, Aman Gupta, Blake Mizerany, Brian Donovan, Ivan
|
142
|
-
Makfinsky, Marc-André Cournoyer, Coda Hale, Tetsuo Watanabe, Dusty Doris,
|
143
|
-
Lennon Day-Reynolds, James Edward Gray II, Cyril Rohr, Juan Alvarez, and Adam
|
144
|
-
Jacob
|
145
|
-
|
146
|
-
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
147
|
-
|
148
|
-
http://rest-client.heroku.com
|
149
|
-
|
150
|
-
http://github.com/adamwiggins/rest-client
|
151
|
-
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'spec/rake/spectask'
|
3
|
-
|
4
|
-
desc "Run all specs"
|
5
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
6
|
-
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
7
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
8
|
-
end
|
9
|
-
|
10
|
-
desc "Print specdocs"
|
11
|
-
Spec::Rake::SpecTask.new(:doc) do |t|
|
12
|
-
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
13
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "Run all examples with RCov"
|
17
|
-
Spec::Rake::SpecTask.new('rcov') do |t|
|
18
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
19
|
-
t.rcov = true
|
20
|
-
t.rcov_opts = ['--exclude', 'examples']
|
21
|
-
end
|
22
|
-
|
23
|
-
task :default => :spec
|
24
|
-
|
25
|
-
######################################################
|
26
|
-
|
27
|
-
require 'rake'
|
28
|
-
require 'rake/testtask'
|
29
|
-
require 'rake/clean'
|
30
|
-
require 'rake/gempackagetask'
|
31
|
-
require 'rake/rdoctask'
|
32
|
-
require 'fileutils'
|
33
|
-
|
34
|
-
version = "0.9.2"
|
35
|
-
name = "rest-client"
|
36
|
-
|
37
|
-
spec = Gem::Specification.new do |s|
|
38
|
-
s.name = name
|
39
|
-
s.version = version
|
40
|
-
s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
|
41
|
-
s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
|
42
|
-
s.author = "Adam Wiggins"
|
43
|
-
s.email = "adam@heroku.com"
|
44
|
-
s.homepage = "http://rest-client.heroku.com/"
|
45
|
-
s.rubyforge_project = "rest-client"
|
46
|
-
|
47
|
-
s.platform = Gem::Platform::RUBY
|
48
|
-
s.has_rdoc = true
|
49
|
-
|
50
|
-
s.files = %w(Rakefile README.rdoc) + Dir.glob("{lib,spec}/**/*")
|
51
|
-
s.executables = ['restclient']
|
52
|
-
|
53
|
-
s.require_path = "lib"
|
54
|
-
end
|
55
|
-
|
56
|
-
Rake::GemPackageTask.new(spec) do |p|
|
57
|
-
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
58
|
-
end
|
59
|
-
|
60
|
-
task :install => [ :package ] do
|
61
|
-
sh %{sudo gem install pkg/#{name}-#{version}.gem}
|
62
|
-
end
|
63
|
-
|
64
|
-
task :uninstall => [ :clean ] do
|
65
|
-
sh %{sudo gem uninstall #{name}}
|
66
|
-
end
|
67
|
-
|
68
|
-
Rake::TestTask.new do |t|
|
69
|
-
t.libs << "spec"
|
70
|
-
t.test_files = FileList['spec/*_spec.rb']
|
71
|
-
t.verbose = true
|
72
|
-
end
|
73
|
-
|
74
|
-
Rake::RDocTask.new do |t|
|
75
|
-
t.rdoc_dir = 'rdoc'
|
76
|
-
t.title = "rest-client, fetch RESTful resources effortlessly"
|
77
|
-
t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
78
|
-
t.options << '--charset' << 'utf-8'
|
79
|
-
t.rdoc_files.include('README.rdoc')
|
80
|
-
t.rdoc_files.include('lib/restclient.rb')
|
81
|
-
t.rdoc_files.include('lib/restclient/*.rb')
|
82
|
-
end
|
83
|
-
|
84
|
-
CLEAN.include [ 'pkg', '*.gem', '.config' ]
|
85
|
-
|
@@ -1,87 +0,0 @@
|
|
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
|
-
if %w(get put post delete).include? ARGV.first
|
17
|
-
@verb = ARGV.shift
|
18
|
-
else
|
19
|
-
@verb = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
@url = ARGV.shift || 'http://localhost:4567'
|
23
|
-
|
24
|
-
config = YAML.load(File.read(ENV['HOME'] + "/.restclient")) rescue {}
|
25
|
-
|
26
|
-
@url, @username, @password = if c = config[@url]
|
27
|
-
[c['url'], c['username'], c['password']]
|
28
|
-
else
|
29
|
-
[@url, *ARGV]
|
30
|
-
end
|
31
|
-
|
32
|
-
usage("invalid url '#{@url}") unless @url =~ /^https?/
|
33
|
-
usage("too few args") unless ARGV.size < 3
|
34
|
-
|
35
|
-
def r
|
36
|
-
@r ||= RestClient::Resource.new(@url, @username, @password)
|
37
|
-
end
|
38
|
-
|
39
|
-
r # force rc to load
|
40
|
-
|
41
|
-
if @verb
|
42
|
-
begin
|
43
|
-
if %w(put post).include? @verb
|
44
|
-
puts r.send(@verb, STDIN.read)
|
45
|
-
else
|
46
|
-
puts r.send(@verb)
|
47
|
-
end
|
48
|
-
exit 0
|
49
|
-
rescue RestClient::Exception => e
|
50
|
-
puts e.response.body if e.respond_to? :response
|
51
|
-
raise
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
%w(get post put delete).each do |m|
|
56
|
-
eval <<-end_eval
|
57
|
-
def #{m}(path, *args, &b)
|
58
|
-
r[path].#{m}(*args, &b)
|
59
|
-
end
|
60
|
-
end_eval
|
61
|
-
end
|
62
|
-
|
63
|
-
def method_missing(s, *args, &b)
|
64
|
-
super unless r.respond_to?(s)
|
65
|
-
begin
|
66
|
-
r.send(s, *args, &b)
|
67
|
-
rescue RestClient::RequestFailed => e
|
68
|
-
print STDERR, e.response.body
|
69
|
-
raise e
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
require 'irb'
|
74
|
-
require 'irb/completion'
|
75
|
-
|
76
|
-
if File.exists? ".irbrc"
|
77
|
-
ENV['IRBRC'] = ".irbrc"
|
78
|
-
end
|
79
|
-
|
80
|
-
if File.exists?(rcfile = "~/.restclientrc")
|
81
|
-
load(rcfile)
|
82
|
-
end
|
83
|
-
|
84
|
-
ARGV.clear
|
85
|
-
|
86
|
-
IRB.start
|
87
|
-
exit!
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/https'
|
3
|
-
require 'zlib'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
require File.dirname(__FILE__) + '/restclient/request'
|
7
|
-
require File.dirname(__FILE__) + '/restclient/mixin/response'
|
8
|
-
require File.dirname(__FILE__) + '/restclient/response'
|
9
|
-
require File.dirname(__FILE__) + '/restclient/raw_response'
|
10
|
-
require File.dirname(__FILE__) + '/restclient/resource'
|
11
|
-
require File.dirname(__FILE__) + '/restclient/exceptions'
|
12
|
-
|
13
|
-
# This module's static methods are the entry point for using the REST client.
|
14
|
-
#
|
15
|
-
# # GET
|
16
|
-
# xml = RestClient.get 'http://example.com/resource'
|
17
|
-
# jpg = RestClient.get 'http://example.com/resource', :accept => 'image/jpg'
|
18
|
-
#
|
19
|
-
# # authentication and SSL
|
20
|
-
# RestClient.get 'https://user:password@example.com/private/resource'
|
21
|
-
#
|
22
|
-
# # POST or PUT with a hash sends parameters as a urlencoded form body
|
23
|
-
# RestClient.post 'http://example.com/resource', :param1 => 'one'
|
24
|
-
#
|
25
|
-
# # nest hash parameters
|
26
|
-
# RestClient.post 'http://example.com/resource', :nested => { :param1 => 'one' }
|
27
|
-
#
|
28
|
-
# # POST and PUT with raw payloads
|
29
|
-
# RestClient.post 'http://example.com/resource', 'the post body', :content_type => 'text/plain'
|
30
|
-
# RestClient.post 'http://example.com/resource.xml', xml_doc
|
31
|
-
# RestClient.put 'http://example.com/resource.pdf', File.read('my.pdf'), :content_type => 'application/pdf'
|
32
|
-
#
|
33
|
-
# # DELETE
|
34
|
-
# RestClient.delete 'http://example.com/resource'
|
35
|
-
#
|
36
|
-
# # retreive the response http code and headers
|
37
|
-
# res = RestClient.get 'http://example.com/some.jpg'
|
38
|
-
# res.code # => 200
|
39
|
-
# res.headers[:content_type] # => 'image/jpg'
|
40
|
-
#
|
41
|
-
# # HEAD
|
42
|
-
# RestClient.head('http://example.com').headers
|
43
|
-
#
|
44
|
-
# To use with a proxy, just set RestClient.proxy to the proper http proxy:
|
45
|
-
#
|
46
|
-
# RestClient.proxy = "http://proxy.example.com/"
|
47
|
-
#
|
48
|
-
# Or inherit the proxy from the environment:
|
49
|
-
#
|
50
|
-
# RestClient.proxy = ENV['http_proxy']
|
51
|
-
#
|
52
|
-
# For live tests of RestClient, try using http://rest-test.heroku.com, which echoes back information about the rest call:
|
53
|
-
#
|
54
|
-
# >> RestClient.put 'http://rest-test.heroku.com/resource', :foo => 'baz'
|
55
|
-
# => "PUT http://rest-test.heroku.com/resource with a 7 byte payload, content type application/x-www-form-urlencoded {\"foo\"=>\"baz\"}"
|
56
|
-
#
|
57
|
-
module RestClient
|
58
|
-
def self.get(url, headers={})
|
59
|
-
Request.execute(:method => :get, :url => url, :headers => headers)
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.post(url, payload, headers={})
|
63
|
-
Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers)
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.put(url, payload, headers={})
|
67
|
-
Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers)
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.delete(url, headers={})
|
71
|
-
Request.execute(:method => :delete, :url => url, :headers => headers)
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.head(url, headers={})
|
75
|
-
Request.execute(:method => :head, :url => url, :headers => headers)
|
76
|
-
end
|
77
|
-
|
78
|
-
class << self
|
79
|
-
attr_accessor :proxy
|
80
|
-
end
|
81
|
-
|
82
|
-
# Print log of RestClient calls. Value can be stdout, stderr, or a filename.
|
83
|
-
# You can also configure logging by the environment variable RESTCLIENT_LOG.
|
84
|
-
def self.log=(log)
|
85
|
-
@@log = log
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.log # :nodoc:
|
89
|
-
return ENV['RESTCLIENT_LOG'] if ENV['RESTCLIENT_LOG']
|
90
|
-
return @@log if defined? @@log
|
91
|
-
nil
|
92
|
-
end
|
93
|
-
end
|