cft_smartcloud 0.2.2 → 0.3.0
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.
- data/.gitignore +1 -0
- data/CHANGELOG +11 -0
- data/README.md +106 -0
- data/VERSION +1 -1
- data/bin/cft_smartcloud +33 -7
- data/bin/smartcloud +33 -7
- data/cft_smartcloud.gemspec +84 -20
- data/lib/config/config.yml +2 -0
- data/lib/curl_client.rb +42 -0
- data/lib/rest-client-1.6.6-master/.gitignore +6 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/README.rdoc +10 -1
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/Rakefile +0 -0
- data/lib/rest-client-1.6.6-master/VERSION +1 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/bin/restclient +5 -4
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/history.md +22 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/rest-client.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/rest_client.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/abstract_response.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/exceptions.rb +0 -0
- data/lib/rest-client-1.6.6-master/lib/restclient/net_http_ext.rb +55 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/payload.rb +17 -2
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/raw_response.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/request.rb +21 -19
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/resource.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/response.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient.rb +0 -0
- data/lib/rest-client-1.6.6-master/rest-client.gemspec +76 -0
- data/lib/rest-client-1.6.6-master/spec/abstract_response_spec.rb +85 -0
- data/lib/rest-client-1.6.6-master/spec/base.rb +16 -0
- data/lib/rest-client-1.6.6-master/spec/exceptions_spec.rb +98 -0
- data/lib/rest-client-1.6.6-master/spec/integration/certs/equifax.crt +19 -0
- data/lib/rest-client-1.6.6-master/spec/integration/certs/verisign.crt +14 -0
- data/lib/rest-client-1.6.6-master/spec/integration/request_spec.rb +25 -0
- data/lib/rest-client-1.6.6-master/spec/integration_spec.rb +38 -0
- data/lib/rest-client-1.6.6-master/spec/master_shake.jpg +0 -0
- data/lib/rest-client-1.6.6-master/spec/payload_spec.rb +234 -0
- data/lib/rest-client-1.6.6-master/spec/raw_response_spec.rb +17 -0
- data/lib/rest-client-1.6.6-master/spec/request2_spec.rb +40 -0
- data/lib/rest-client-1.6.6-master/spec/request_spec.rb +536 -0
- data/lib/rest-client-1.6.6-master/spec/resource_spec.rb +134 -0
- data/lib/rest-client-1.6.6-master/spec/response_spec.rb +169 -0
- data/lib/rest-client-1.6.6-master/spec/restclient_spec.rb +73 -0
- data/lib/slop-2.3.1/.gemtest +0 -0
- data/lib/slop-2.3.1/.gitignore +6 -0
- data/lib/slop-2.3.1/.yardopts +6 -0
- data/lib/slop-2.3.1/CHANGES.md +137 -0
- data/lib/slop-2.3.1/LICENSE +20 -0
- data/lib/slop-2.3.1/README.md +293 -0
- data/lib/slop-2.3.1/Rakefile +6 -0
- data/lib/slop-2.3.1/lib/slop.rb +1022 -0
- data/lib/slop-2.3.1/slop.gemspec +11 -0
- data/lib/slop-2.3.1/test/commands_test.rb +151 -0
- data/lib/slop-2.3.1/test/helper.rb +13 -0
- data/lib/slop-2.3.1/test/option_test.rb +198 -0
- data/lib/slop-2.3.1/test/slop_test.rb +574 -0
- data/lib/smartcloud.rb +186 -116
- data/lib/terminal-table-1.4.4/History.rdoc +53 -0
- data/lib/terminal-table-1.4.4/Manifest +24 -0
- data/lib/terminal-table-1.4.4/README.rdoc +240 -0
- data/lib/terminal-table-1.4.4/Rakefile +15 -0
- data/lib/terminal-table-1.4.4/Todo.rdoc +14 -0
- data/lib/terminal-table-1.4.4/examples/examples.rb +80 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/cell.rb +88 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/core_ext.rb +8 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/import.rb +4 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/row.rb +48 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/separator.rb +14 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/style.rb +61 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/table.rb +217 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/table_helper.rb +9 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/version.rb +6 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table.rb +27 -0
- data/lib/terminal-table-1.4.4/spec/cell_spec.rb +54 -0
- data/lib/terminal-table-1.4.4/spec/core_ext_spec.rb +18 -0
- data/lib/terminal-table-1.4.4/spec/import_spec.rb +11 -0
- data/lib/terminal-table-1.4.4/spec/spec.opts +1 -0
- data/lib/terminal-table-1.4.4/spec/spec_helper.rb +8 -0
- data/lib/terminal-table-1.4.4/spec/table_spec.rb +525 -0
- data/lib/terminal-table-1.4.4/tasks/docs.rake +13 -0
- data/lib/terminal-table-1.4.4/tasks/gemspec.rake +3 -0
- data/lib/terminal-table-1.4.4/tasks/spec.rake +25 -0
- data/lib/terminal-table-1.4.4/terminal-table.gemspec +30 -0
- data/responses/addresses +26 -0
- data/responses/addresses.blank +2 -0
- data/responses/instances +74 -0
- data/responses/keys +33 -0
- data/responses/locations +142 -0
- data/responses/offerings_image +3780 -0
- data/responses/storage +379 -0
- metadata +86 -22
- data/README.rdoc +0 -75
- data/lib/rest-client-1.6.3/VERSION +0 -1
- data/lib/rest-client-1.6.3/lib/restclient/net_http_ext.rb +0 -21
|
@@ -20,7 +20,7 @@ module RestClient
|
|
|
20
20
|
# * :raw_response return a low-level RawResponse instead of a Response
|
|
21
21
|
# * :max_redirects maximum number of redirections (default to 10)
|
|
22
22
|
# * :verify_ssl enable ssl verification, possible values are constants from OpenSSL::SSL
|
|
23
|
-
# * :timeout and :open_timeout
|
|
23
|
+
# * :timeout and :open_timeout passing in -1 will disable the timeout by setting the corresponding net timeout values to nil
|
|
24
24
|
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file
|
|
25
25
|
class Request
|
|
26
26
|
|
|
@@ -37,7 +37,7 @@ module RestClient
|
|
|
37
37
|
@method = args[:method] or raise ArgumentError, "must pass :method"
|
|
38
38
|
@headers = args[:headers] || {}
|
|
39
39
|
if args[:url]
|
|
40
|
-
@url =
|
|
40
|
+
@url = process_url_params(args[:url], headers)
|
|
41
41
|
else
|
|
42
42
|
raise ArgumentError, "must pass :url"
|
|
43
43
|
end
|
|
@@ -62,26 +62,24 @@ module RestClient
|
|
|
62
62
|
def execute & block
|
|
63
63
|
uri = parse_url_with_auth(url)
|
|
64
64
|
transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
|
|
65
|
+
ensure
|
|
66
|
+
payload.close if payload
|
|
65
67
|
end
|
|
66
68
|
|
|
67
|
-
# Extract the query parameters
|
|
68
|
-
def
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
true
|
|
75
|
-
else
|
|
76
|
-
false
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
unless get_params.empty?
|
|
80
|
-
query_string = get_params.collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
|
81
|
-
url + "?#{query_string}"
|
|
69
|
+
# Extract the query parameters and append them to the url
|
|
70
|
+
def process_url_params url, headers
|
|
71
|
+
url_params = {}
|
|
72
|
+
headers.delete_if do |key, value|
|
|
73
|
+
if 'params' == key.to_s.downcase && value.is_a?(Hash)
|
|
74
|
+
url_params.merge! value
|
|
75
|
+
true
|
|
82
76
|
else
|
|
83
|
-
|
|
77
|
+
false
|
|
84
78
|
end
|
|
79
|
+
end
|
|
80
|
+
unless url_params.empty?
|
|
81
|
+
query_string = url_params.collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
|
82
|
+
url + "?#{query_string}"
|
|
85
83
|
else
|
|
86
84
|
url
|
|
87
85
|
end
|
|
@@ -89,7 +87,7 @@ module RestClient
|
|
|
89
87
|
|
|
90
88
|
def make_headers user_headers
|
|
91
89
|
unless @cookies.empty?
|
|
92
|
-
user_headers[:cookie] = @cookies.map { |(key, val)| "#{key.to_s}=#{CGI::unescape(val)}" }.sort.join(';')
|
|
90
|
+
user_headers[:cookie] = @cookies.map { |(key, val)| "#{key.to_s}=#{CGI::unescape(val.to_s)}" }.sort.join('; ')
|
|
93
91
|
end
|
|
94
92
|
headers = stringify_headers(default_headers).merge(stringify_headers(user_headers))
|
|
95
93
|
headers.merge!(@payload.headers) if @payload
|
|
@@ -161,6 +159,10 @@ module RestClient
|
|
|
161
159
|
net.read_timeout = @timeout if @timeout
|
|
162
160
|
net.open_timeout = @open_timeout if @open_timeout
|
|
163
161
|
|
|
162
|
+
# disable the timeout if the timeout value is -1
|
|
163
|
+
net.read_timeout = nil if @timeout == -1
|
|
164
|
+
net.out_timeout = nil if @open_timeout == -1
|
|
165
|
+
|
|
164
166
|
RestClient.before_execution_procs.each do |before_proc|
|
|
165
167
|
before_proc.call(req, args)
|
|
166
168
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{rest-client}
|
|
8
|
+
s.version = "1.6.7"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = [%q{Adam Wiggins}, %q{Julien Kirch}]
|
|
12
|
+
s.date = %q{2011-08-24}
|
|
13
|
+
s.description = %q{A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete.}
|
|
14
|
+
s.email = %q{rest.client@librelist.com}
|
|
15
|
+
s.executables = [%q{restclient}]
|
|
16
|
+
s.extra_rdoc_files = [
|
|
17
|
+
"README.rdoc",
|
|
18
|
+
"history.md"
|
|
19
|
+
]
|
|
20
|
+
s.files = [
|
|
21
|
+
"README.rdoc",
|
|
22
|
+
"Rakefile",
|
|
23
|
+
"VERSION",
|
|
24
|
+
"bin/restclient",
|
|
25
|
+
"lib/rest-client.rb",
|
|
26
|
+
"lib/rest_client.rb",
|
|
27
|
+
"lib/restclient.rb",
|
|
28
|
+
"lib/restclient/abstract_response.rb",
|
|
29
|
+
"lib/restclient/exceptions.rb",
|
|
30
|
+
"lib/restclient/net_http_ext.rb",
|
|
31
|
+
"lib/restclient/payload.rb",
|
|
32
|
+
"lib/restclient/raw_response.rb",
|
|
33
|
+
"lib/restclient/request.rb",
|
|
34
|
+
"lib/restclient/resource.rb",
|
|
35
|
+
"lib/restclient/response.rb",
|
|
36
|
+
"spec/abstract_response_spec.rb",
|
|
37
|
+
"spec/base.rb",
|
|
38
|
+
"spec/exceptions_spec.rb",
|
|
39
|
+
"spec/integration/certs/equifax.crt",
|
|
40
|
+
"spec/integration/certs/verisign.crt",
|
|
41
|
+
"spec/integration/request_spec.rb",
|
|
42
|
+
"spec/integration_spec.rb",
|
|
43
|
+
"spec/master_shake.jpg",
|
|
44
|
+
"spec/payload_spec.rb",
|
|
45
|
+
"spec/raw_response_spec.rb",
|
|
46
|
+
"spec/request2_spec.rb",
|
|
47
|
+
"spec/request_spec.rb",
|
|
48
|
+
"spec/resource_spec.rb",
|
|
49
|
+
"spec/response_spec.rb",
|
|
50
|
+
"spec/restclient_spec.rb"
|
|
51
|
+
]
|
|
52
|
+
s.homepage = %q{http://github.com/archiloque/rest-client}
|
|
53
|
+
s.require_paths = [%q{lib}]
|
|
54
|
+
s.rubygems_version = %q{1.8.5}
|
|
55
|
+
s.summary = %q{Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.}
|
|
56
|
+
s.test_files = [%q{spec/abstract_response_spec.rb}, %q{spec/base.rb}, %q{spec/exceptions_spec.rb}, %q{spec/integration}, %q{spec/integration/certs}, %q{spec/integration/certs/equifax.crt}, %q{spec/integration/certs/verisign.crt}, %q{spec/integration/request_spec.rb}, %q{spec/integration_spec.rb}, %q{spec/master_shake.jpg}, %q{spec/payload_spec.rb}, %q{spec/raw_response_spec.rb}, %q{spec/request2_spec.rb}, %q{spec/request_spec.rb}, %q{spec/resource_spec.rb}, %q{spec/response_spec.rb}, %q{spec/restclient_spec.rb}]
|
|
57
|
+
|
|
58
|
+
if s.respond_to? :specification_version then
|
|
59
|
+
s.specification_version = 3
|
|
60
|
+
|
|
61
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
62
|
+
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
|
|
63
|
+
s.add_development_dependency(%q<webmock>, [">= 0.9.1"])
|
|
64
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
|
65
|
+
else
|
|
66
|
+
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
|
67
|
+
s.add_dependency(%q<webmock>, [">= 0.9.1"])
|
|
68
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
69
|
+
end
|
|
70
|
+
else
|
|
71
|
+
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
|
72
|
+
s.add_dependency(%q<webmock>, [">= 0.9.1"])
|
|
73
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
|
2
|
+
|
|
3
|
+
describe RestClient::AbstractResponse do
|
|
4
|
+
|
|
5
|
+
class MyAbstractResponse
|
|
6
|
+
|
|
7
|
+
include RestClient::AbstractResponse
|
|
8
|
+
|
|
9
|
+
attr_accessor :size
|
|
10
|
+
|
|
11
|
+
def initialize net_http_res, args
|
|
12
|
+
@net_http_res = net_http_res
|
|
13
|
+
@args = args
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
@net_http_res = mock('net http response')
|
|
20
|
+
@response = MyAbstractResponse.new(@net_http_res, {})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "fetches the numeric response code" do
|
|
24
|
+
@net_http_res.should_receive(:code).and_return('200')
|
|
25
|
+
@response.code.should == 200
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "has a nice description" do
|
|
29
|
+
@net_http_res.should_receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
|
|
30
|
+
@net_http_res.should_receive(:code).and_return('200')
|
|
31
|
+
@response.description == '200 OK | application/pdf bytes\n'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "beautifies the headers by turning the keys to symbols" do
|
|
35
|
+
h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
|
|
36
|
+
h.keys.first.should == :content_type
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
|
|
40
|
+
h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
|
|
41
|
+
h.values.first.should == 'text/html'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "fetches the headers" do
|
|
45
|
+
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
|
|
46
|
+
@response.headers.should == { :content_type => 'text/html' }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "extracts cookies from response headers" do
|
|
50
|
+
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
|
51
|
+
@response.cookies.should == { 'session_id' => '1' }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "extract strange cookies" do
|
|
55
|
+
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
|
|
56
|
+
@response.cookies.should == { 'session_id' => 'ZJ%2FHQVH6YE+rVkTpn0zvTQ%3D%3D' }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "doesn't escape cookies" do
|
|
60
|
+
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
|
|
61
|
+
@response.cookies.should == { 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "can access the net http result directly" do
|
|
65
|
+
@response.net_http_res.should == @net_http_res
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "#return!" do
|
|
69
|
+
it "should return the response itself on 200-codes" do
|
|
70
|
+
@net_http_res.should_receive(:code).and_return('200')
|
|
71
|
+
@response.return!.should be_equal(@response)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should raise RequestFailed on unknown codes" do
|
|
75
|
+
@net_http_res.should_receive(:code).and_return('1000')
|
|
76
|
+
lambda { @response.return! }.should raise_error RestClient::RequestFailed
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should raise an error on a redirection after non-GET/HEAD requests" do
|
|
80
|
+
@net_http_res.should_receive(:code).and_return('301')
|
|
81
|
+
@response.args.merge(:method => :put)
|
|
82
|
+
lambda { @response.return! }.should raise_error RestClient::RequestFailed
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
def is_ruby_19?
|
|
2
|
+
RUBY_VERSION == '1.9.1' or RUBY_VERSION == '1.9.2'
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
Encoding.default_internal = Encoding.default_external = "ASCII-8BIT" if is_ruby_19?
|
|
6
|
+
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'spec'
|
|
9
|
+
|
|
10
|
+
begin
|
|
11
|
+
require "ruby-debug"
|
|
12
|
+
rescue LoadError
|
|
13
|
+
# NOP, ignore
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
require File.dirname(__FILE__) + '/../lib/restclient'
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
|
2
|
+
|
|
3
|
+
require 'webmock/rspec'
|
|
4
|
+
include WebMock
|
|
5
|
+
|
|
6
|
+
describe RestClient::Exception do
|
|
7
|
+
it "returns a 'message' equal to the class name if the message is not set, because 'message' should not be nil" do
|
|
8
|
+
e = RestClient::Exception.new
|
|
9
|
+
e.message.should == "RestClient::Exception"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "returns the 'message' that was set" do
|
|
13
|
+
e = RestClient::Exception.new
|
|
14
|
+
message = "An explicitly set message"
|
|
15
|
+
e.message = message
|
|
16
|
+
e.message.should == message
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "sets the exception message to ErrorMessage" do
|
|
20
|
+
RestClient::ResourceNotFound.new.message.should == 'Resource Not Found'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "contains exceptions in RestClient" do
|
|
24
|
+
RestClient::Unauthorized.new.should be_a_kind_of(RestClient::Exception)
|
|
25
|
+
RestClient::ServerBrokeConnection.new.should be_a_kind_of(RestClient::Exception)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe RestClient::ServerBrokeConnection do
|
|
30
|
+
it "should have a default message of 'Server broke connection'" do
|
|
31
|
+
e = RestClient::ServerBrokeConnection.new
|
|
32
|
+
e.message.should == 'Server broke connection'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe RestClient::RequestFailed do
|
|
37
|
+
before do
|
|
38
|
+
@response = mock('HTTP Response', :code => '502')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "stores the http response on the exception" do
|
|
42
|
+
response = "response"
|
|
43
|
+
begin
|
|
44
|
+
raise RestClient::RequestFailed, response
|
|
45
|
+
rescue RestClient::RequestFailed => e
|
|
46
|
+
e.response.should == response
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "http_code convenience method for fetching the code as an integer" do
|
|
51
|
+
RestClient::RequestFailed.new(@response).http_code.should == 502
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "http_body convenience method for fetching the body (decoding when necessary)" do
|
|
55
|
+
RestClient::RequestFailed.new(@response).http_code.should == 502
|
|
56
|
+
RestClient::RequestFailed.new(@response).message.should == 'HTTP status code 502'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "shows the status code in the message" do
|
|
60
|
+
RestClient::RequestFailed.new(@response).to_s.should match(/502/)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe RestClient::ResourceNotFound do
|
|
65
|
+
it "also has the http response attached" do
|
|
66
|
+
response = "response"
|
|
67
|
+
begin
|
|
68
|
+
raise RestClient::ResourceNotFound, response
|
|
69
|
+
rescue RestClient::ResourceNotFound => e
|
|
70
|
+
e.response.should == response
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "backwards compatibility" do
|
|
76
|
+
it "alias RestClient::Request::Redirect to RestClient::Redirect" do
|
|
77
|
+
RestClient::Request::Redirect.should == RestClient::Redirect
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "alias RestClient::Request::Unauthorized to RestClient::Unauthorized" do
|
|
81
|
+
RestClient::Request::Unauthorized.should == RestClient::Unauthorized
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
|
|
85
|
+
RestClient::Request::RequestFailed.should == RestClient::RequestFailed
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "make the exception's response act like an Net::HTTPResponse" do
|
|
89
|
+
body = "body"
|
|
90
|
+
stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
|
|
91
|
+
begin
|
|
92
|
+
RestClient.get "www.example.com"
|
|
93
|
+
raise
|
|
94
|
+
rescue RestClient::ResourceNotFound => e
|
|
95
|
+
e.response.body.should == body
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJV
|
|
3
|
+
UzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2Vy
|
|
4
|
+
dGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1
|
|
5
|
+
MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgxLTArBgNVBAsTJEVx
|
|
6
|
+
dWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B
|
|
7
|
+
AQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f
|
|
8
|
+
BeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A
|
|
9
|
+
cJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC
|
|
10
|
+
AwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ
|
|
11
|
+
MA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm
|
|
12
|
+
aWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw
|
|
13
|
+
ODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvSspXXR9gj
|
|
14
|
+
IBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF
|
|
15
|
+
MAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA
|
|
16
|
+
A4GBAFjOKer89961zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y
|
|
17
|
+
7qj/WsjTVbJmcVfewCHrPSqnI0kBBIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh
|
|
18
|
+
1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4
|
|
19
|
+
-----END CERTIFICATE-----
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG
|
|
3
|
+
A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
|
|
4
|
+
cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
|
|
5
|
+
MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
|
|
6
|
+
BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
|
|
7
|
+
YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
|
|
8
|
+
ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
|
|
9
|
+
BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
|
|
10
|
+
I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
|
|
11
|
+
CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
|
|
12
|
+
lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
|
|
13
|
+
AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
|
|
14
|
+
-----END CERTIFICATE-----
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require File.join( File.dirname(File.expand_path(__FILE__)), '../base')
|
|
2
|
+
|
|
3
|
+
describe RestClient::Request do
|
|
4
|
+
describe "ssl verification" do
|
|
5
|
+
it "is successful with the correct ca_file" do
|
|
6
|
+
request = RestClient::Request.new(
|
|
7
|
+
:method => :get,
|
|
8
|
+
:url => 'https://www.mozilla.com',
|
|
9
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
|
10
|
+
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "equifax.crt")
|
|
11
|
+
)
|
|
12
|
+
expect { request.execute }.to_not raise_error
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "is unsuccessful with an incorrect ca_file" do
|
|
16
|
+
request = RestClient::Request.new(
|
|
17
|
+
:method => :get,
|
|
18
|
+
:url => 'https://www.mozilla.com',
|
|
19
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
|
20
|
+
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt")
|
|
21
|
+
)
|
|
22
|
+
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
|
2
|
+
|
|
3
|
+
require 'webmock/rspec'
|
|
4
|
+
include WebMock
|
|
5
|
+
|
|
6
|
+
describe RestClient do
|
|
7
|
+
|
|
8
|
+
it "a simple request" do
|
|
9
|
+
body = 'abc'
|
|
10
|
+
stub_request(:get, "www.example.com").to_return(:body => body, :status => 200)
|
|
11
|
+
response = RestClient.get "www.example.com"
|
|
12
|
+
response.code.should == 200
|
|
13
|
+
response.body.should == body
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "a simple request with gzipped content" do
|
|
17
|
+
stub_request(:get, "www.example.com").with(:headers => { 'Accept-Encoding' => 'gzip, deflate' }).to_return(:body => "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000", :status => 200, :headers => { 'Content-Encoding' => 'gzip' } )
|
|
18
|
+
response = RestClient.get "www.example.com"
|
|
19
|
+
response.code.should == 200
|
|
20
|
+
response.body.should == "i'm gziped\n"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "a 404" do
|
|
24
|
+
body = "Ho hai ! I'm not here !"
|
|
25
|
+
stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
|
|
26
|
+
begin
|
|
27
|
+
RestClient.get "www.example.com"
|
|
28
|
+
raise
|
|
29
|
+
rescue RestClient::ResourceNotFound => e
|
|
30
|
+
e.http_code.should == 404
|
|
31
|
+
e.response.code.should == 404
|
|
32
|
+
e.response.body.should == body
|
|
33
|
+
e.http_body.should == body
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
end
|
|
Binary file
|