esod-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/EXAMPLES +140 -0
- data/GEM_RELEASE +19 -0
- data/README +10 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/esod-client.gemspec +118 -0
- data/esod-client.rb +35 -0
- data/lib/activesupport-2.2.2/CHANGELOG +1257 -0
- data/lib/activesupport-2.2.2/README +43 -0
- data/lib/activesupport-2.2.2/README.CFT +2 -0
- data/lib/activesupport-2.2.2/lib/active_support.rb +26 -0
- data/lib/activesupport-2.2.2/lib/active_support/base64.rb +33 -0
- data/lib/activesupport-2.2.2/lib/active_support/basic_object.rb +24 -0
- data/lib/activesupport-2.2.2/lib/active_support/buffered_logger.rb +122 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache.rb +223 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/drb_store.rb +15 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/file_store.rb +72 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb +127 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/memory_store.rb +52 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb +47 -0
- data/lib/activesupport-2.2.2/lib/active_support/callbacks.rb +280 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext.rb +6 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash.rb +14 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/conversions.rb +259 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/except.rb +25 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/keys.rb +52 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/slice.rb +33 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor.rb +14 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/lib/activesupport-2.2.2/lib/activesupport.rb +1 -0
- data/lib/esodclient/esodclient.rb +22 -0
- data/lib/hash.rb +22 -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/rest-client-1.2.0/README.rdoc +102 -0
- data/lib/rest-client-1.2.0/Rakefile +57 -0
- data/lib/rest-client-1.2.0/VERSION +1 -0
- data/lib/rest-client-1.2.0/bin/restclient +87 -0
- data/lib/rest-client-1.2.0/lib/rest_client.rb +2 -0
- data/lib/rest-client-1.2.0/lib/restclient.rb +108 -0
- data/lib/rest-client-1.2.0/lib/restclient/exceptions.rb +89 -0
- data/lib/rest-client-1.2.0/lib/restclient/mixin/response.rb +48 -0
- data/lib/rest-client-1.2.0/lib/restclient/net_http_ext.rb +21 -0
- data/lib/rest-client-1.2.0/lib/restclient/payload.rb +178 -0
- data/lib/rest-client-1.2.0/lib/restclient/raw_response.rb +30 -0
- data/lib/rest-client-1.2.0/lib/restclient/request.rb +287 -0
- data/lib/rest-client-1.2.0/lib/restclient/resource.rb +146 -0
- data/lib/rest-client-1.2.0/lib/restclient/response.rb +20 -0
- data/lib/rest-client-1.2.0/spec/base.rb +10 -0
- data/lib/rest-client-1.2.0/spec/exceptions_spec.rb +65 -0
- data/lib/rest-client-1.2.0/spec/master_shake.jpg +0 -0
- data/lib/rest-client-1.2.0/spec/mixin/response_spec.rb +46 -0
- data/lib/rest-client-1.2.0/spec/payload_spec.rb +131 -0
- data/lib/rest-client-1.2.0/spec/raw_response_spec.rb +17 -0
- data/lib/rest-client-1.2.0/spec/request_spec.rb +521 -0
- data/lib/rest-client-1.2.0/spec/resource_spec.rb +75 -0
- data/lib/rest-client-1.2.0/spec/response_spec.rb +21 -0
- data/lib/rest-client-1.2.0/spec/restclient_spec.rb +53 -0
- data/lib/trollop/trollop.rb +735 -0
- metadata +137 -0
@@ -0,0 +1,102 @@
|
|
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
|
+
|
12
|
+
RestClient.get 'https://user:password@example.com/private/resource'
|
13
|
+
|
14
|
+
RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
|
15
|
+
|
16
|
+
RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
|
17
|
+
|
18
|
+
RestClient.delete 'http://example.com/resource'
|
19
|
+
|
20
|
+
== Multipart
|
21
|
+
|
22
|
+
Yeah, that's right! This does multipart sends for you!
|
23
|
+
|
24
|
+
RestClient.post '/data', :myfile => File.new("/path/to/image.jpg")
|
25
|
+
|
26
|
+
This does two things for you:
|
27
|
+
|
28
|
+
* Auto-detects that you have a File value sends it as multipart
|
29
|
+
* Auto-detects the mime of the file and sets it in the HEAD of the payload for each entry
|
30
|
+
|
31
|
+
If you are sending params that do not contain a File object but the payload needs to be multipart then:
|
32
|
+
|
33
|
+
RestClient.post '/data', :foo => 'bar', :multipart => true
|
34
|
+
|
35
|
+
== Usage: ActiveResource-Style
|
36
|
+
|
37
|
+
resource = RestClient::Resource.new 'http://example.com/resource'
|
38
|
+
resource.get
|
39
|
+
|
40
|
+
private_resource = RestClient::Resource.new 'https://example.com/private/resource', 'user', 'pass'
|
41
|
+
private_resource.put File.read('pic.jpg'), :content_type => 'image/jpg'
|
42
|
+
|
43
|
+
See RestClient::Resource module docs for details.
|
44
|
+
|
45
|
+
== Usage: Resource Nesting
|
46
|
+
|
47
|
+
site = RestClient::Resource.new('http://example.com')
|
48
|
+
site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
|
49
|
+
|
50
|
+
See RestClient::Resource docs for details.
|
51
|
+
|
52
|
+
== Lower-level access
|
53
|
+
|
54
|
+
For cases not covered by the general API, you can use the RestClient::Resource class which provide a lower-level API, see the class' rdoc for more information.
|
55
|
+
|
56
|
+
== Shell
|
57
|
+
|
58
|
+
The restclient shell command gives an IRB session with RestClient already loaded:
|
59
|
+
|
60
|
+
$ restclient
|
61
|
+
>> RestClient.get 'http://example.com'
|
62
|
+
|
63
|
+
Specify a URL argument for get/post/put/delete on that resource:
|
64
|
+
|
65
|
+
$ restclient http://example.com
|
66
|
+
>> put '/resource', 'data'
|
67
|
+
|
68
|
+
Add a user and password for authenticated resources:
|
69
|
+
|
70
|
+
$ restclient https://example.com user pass
|
71
|
+
>> delete '/private/resource'
|
72
|
+
|
73
|
+
Create ~/.restclient for named sessions:
|
74
|
+
|
75
|
+
sinatra:
|
76
|
+
url: http://localhost:4567
|
77
|
+
rack:
|
78
|
+
url: http://localhost:9292
|
79
|
+
private_site:
|
80
|
+
url: http://example.com
|
81
|
+
username: user
|
82
|
+
password: pass
|
83
|
+
|
84
|
+
Then invoke:
|
85
|
+
|
86
|
+
$ restclient private_site
|
87
|
+
|
88
|
+
== Meta
|
89
|
+
|
90
|
+
Written by Adam Wiggins, major modifications by Blake Mizerany, maintained by Archiloque
|
91
|
+
|
92
|
+
Patches contributed by: Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, François Beausoleil and Nick Plante.
|
93
|
+
|
94
|
+
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
95
|
+
|
96
|
+
Main page: http://github.com/archiloque/rest-client
|
97
|
+
|
98
|
+
Rdoc: http://rdoc.info/projects/archiloque/rest-client
|
99
|
+
|
100
|
+
Mailing list: rest.client@librelist.com (send a mail to subscribe).
|
101
|
+
|
102
|
+
IRC: #rest-client at freenode
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
require 'jeweler'
|
4
|
+
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "rest-client"
|
7
|
+
s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
|
8
|
+
s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
|
9
|
+
s.author = "Adam Wiggins"
|
10
|
+
s.email = "rest.client@librelist.com"
|
11
|
+
s.homepage = "http://github.com/archiloque/rest-client"
|
12
|
+
s.rubyforge_project = "rest-client"
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
|
15
|
+
s.executables = %w(restclient)
|
16
|
+
end
|
17
|
+
|
18
|
+
Jeweler::RubyforgeTasks.new
|
19
|
+
|
20
|
+
############################
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
|
24
|
+
desc "Run all specs"
|
25
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
26
|
+
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
27
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Print specdocs"
|
31
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
32
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
33
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run all examples with RCov"
|
37
|
+
Spec::Rake::SpecTask.new('rcov') do |t|
|
38
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
39
|
+
t.rcov = true
|
40
|
+
t.rcov_opts = ['--exclude', 'examples']
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
############################
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
|
49
|
+
Rake::RDocTask.new do |t|
|
50
|
+
t.rdoc_dir = 'rdoc'
|
51
|
+
t.title = "rest-client, fetch RESTful resources effortlessly"
|
52
|
+
t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
53
|
+
t.options << '--charset' << 'utf-8'
|
54
|
+
t.rdoc_files.include('README.rdoc')
|
55
|
+
t.rdoc_files.include('lib/*.rb')
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
1.2.0
|
@@ -0,0 +1,87 @@
|
|
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!
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'zlib'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'net/https'
|
7
|
+
rescue LoadError => e
|
8
|
+
raise e unless RUBY_PLATFORM =~ /linux/
|
9
|
+
raise LoadError, "no such file to load -- net/https. Try running apt-get install libopenssl-ruby"
|
10
|
+
end
|
11
|
+
|
12
|
+
require File.dirname(__FILE__) + '/restclient/request'
|
13
|
+
require File.dirname(__FILE__) + '/restclient/mixin/response'
|
14
|
+
require File.dirname(__FILE__) + '/restclient/response'
|
15
|
+
require File.dirname(__FILE__) + '/restclient/raw_response'
|
16
|
+
require File.dirname(__FILE__) + '/restclient/resource'
|
17
|
+
require File.dirname(__FILE__) + '/restclient/exceptions'
|
18
|
+
require File.dirname(__FILE__) + '/restclient/payload'
|
19
|
+
require File.dirname(__FILE__) + '/restclient/net_http_ext'
|
20
|
+
|
21
|
+
# This module's static methods are the entry point for using the REST client.
|
22
|
+
#
|
23
|
+
# # GET
|
24
|
+
# xml = RestClient.get 'http://example.com/resource'
|
25
|
+
# jpg = RestClient.get 'http://example.com/resource', :accept => 'image/jpg'
|
26
|
+
#
|
27
|
+
# # authentication and SSL
|
28
|
+
# RestClient.get 'https://user:password@example.com/private/resource'
|
29
|
+
#
|
30
|
+
# # POST or PUT with a hash sends parameters as a urlencoded form body
|
31
|
+
# RestClient.post 'http://example.com/resource', :param1 => 'one'
|
32
|
+
#
|
33
|
+
# # nest hash parameters
|
34
|
+
# RestClient.post 'http://example.com/resource', :nested => { :param1 => 'one' }
|
35
|
+
#
|
36
|
+
# # POST and PUT with raw payloads
|
37
|
+
# RestClient.post 'http://example.com/resource', 'the post body', :content_type => 'text/plain'
|
38
|
+
# RestClient.post 'http://example.com/resource.xml', xml_doc
|
39
|
+
# RestClient.put 'http://example.com/resource.pdf', File.read('my.pdf'), :content_type => 'application/pdf'
|
40
|
+
#
|
41
|
+
# # DELETE
|
42
|
+
# RestClient.delete 'http://example.com/resource'
|
43
|
+
#
|
44
|
+
# # retreive the response http code and headers
|
45
|
+
# res = RestClient.get 'http://example.com/some.jpg'
|
46
|
+
# res.code # => 200
|
47
|
+
# res.headers[:content_type] # => 'image/jpg'
|
48
|
+
#
|
49
|
+
# # HEAD
|
50
|
+
# RestClient.head('http://example.com').headers
|
51
|
+
#
|
52
|
+
# To use with a proxy, just set RestClient.proxy to the proper http proxy:
|
53
|
+
#
|
54
|
+
# RestClient.proxy = "http://proxy.example.com/"
|
55
|
+
#
|
56
|
+
# Or inherit the proxy from the environment:
|
57
|
+
#
|
58
|
+
# RestClient.proxy = ENV['http_proxy']
|
59
|
+
#
|
60
|
+
# For live tests of RestClient, try using http://rest-test.heroku.com, which echoes back information about the rest call:
|
61
|
+
#
|
62
|
+
# >> RestClient.put 'http://rest-test.heroku.com/resource', :foo => 'baz'
|
63
|
+
# => "PUT http://rest-test.heroku.com/resource with a 7 byte payload, content type application/x-www-form-urlencoded {\"foo\"=>\"baz\"}"
|
64
|
+
#
|
65
|
+
module RestClient
|
66
|
+
|
67
|
+
def self.get(url, headers={})
|
68
|
+
Request.execute(:method => :get, :url => url, :headers => headers)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.post(url, payload, headers={})
|
72
|
+
Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.put(url, payload, headers={})
|
76
|
+
Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.delete(url, headers={})
|
80
|
+
Request.execute(:method => :delete, :url => url, :headers => headers)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.head(url, headers={})
|
84
|
+
Request.execute(:method => :head, :url => url, :headers => headers)
|
85
|
+
end
|
86
|
+
|
87
|
+
class << self
|
88
|
+
attr_accessor :proxy
|
89
|
+
end
|
90
|
+
|
91
|
+
# Print log of RestClient calls. Value can be stdout, stderr, or a filename.
|
92
|
+
# You can also configure logging by the environment variable RESTCLIENT_LOG.
|
93
|
+
def self.log=(log)
|
94
|
+
@@log = log
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.log # :nodoc:
|
98
|
+
return ENV['RESTCLIENT_LOG'] if ENV['RESTCLIENT_LOG']
|
99
|
+
return @@log if defined? @@log
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.version
|
104
|
+
version_path = File.dirname(__FILE__) + "/../VERSION"
|
105
|
+
return File.read(version_path).chomp if File.file?(version_path)
|
106
|
+
"0.0.0"
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module RestClient
|
2
|
+
# This is the base RestClient exception class. Rescue it if you want to
|
3
|
+
# catch any exception that your request might raise
|
4
|
+
class Exception < RuntimeError
|
5
|
+
def message(default=nil)
|
6
|
+
self.class::ErrorMessage
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Base RestClient exception when there's a response available
|
11
|
+
class ExceptionWithResponse < Exception
|
12
|
+
attr_accessor :response
|
13
|
+
|
14
|
+
def initialize(response=nil)
|
15
|
+
@response = response
|
16
|
+
end
|
17
|
+
|
18
|
+
def http_code
|
19
|
+
@response.code.to_i if @response
|
20
|
+
end
|
21
|
+
|
22
|
+
def http_body
|
23
|
+
RestClient::Request.decode(@response['content-encoding'], @response.body) if @response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# A redirect was encountered; caught by execute to retry with the new url.
|
28
|
+
class Redirect < Exception
|
29
|
+
ErrorMessage = "Redirect"
|
30
|
+
|
31
|
+
attr_accessor :url
|
32
|
+
|
33
|
+
def initialize(url)
|
34
|
+
@url = url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class NotModified < ExceptionWithResponse
|
39
|
+
ErrorMessage = 'NotModified'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Authorization is required to access the resource specified.
|
43
|
+
class Unauthorized < ExceptionWithResponse
|
44
|
+
ErrorMessage = 'Unauthorized'
|
45
|
+
end
|
46
|
+
|
47
|
+
# No resource was found at the given URL.
|
48
|
+
class ResourceNotFound < ExceptionWithResponse
|
49
|
+
ErrorMessage = 'Resource not found'
|
50
|
+
end
|
51
|
+
|
52
|
+
# The server broke the connection prior to the request completing. Usually
|
53
|
+
# this means it crashed, or sometimes that your network connection was
|
54
|
+
# severed before it could complete.
|
55
|
+
class ServerBrokeConnection < Exception
|
56
|
+
ErrorMessage = 'Server broke connection'
|
57
|
+
end
|
58
|
+
|
59
|
+
# The server took too long to respond.
|
60
|
+
class RequestTimeout < Exception
|
61
|
+
ErrorMessage = 'Request timed out'
|
62
|
+
end
|
63
|
+
|
64
|
+
# The request failed, meaning the remote HTTP server returned a code other
|
65
|
+
# than success, unauthorized, or redirect.
|
66
|
+
#
|
67
|
+
# The exception message attempts to extract the error from the XML, using
|
68
|
+
# format returned by Rails: <errors><error>some message</error></errors>
|
69
|
+
#
|
70
|
+
# You can get the status code by e.http_code, or see anything about the
|
71
|
+
# response via e.response. For example, the entire result body (which is
|
72
|
+
# probably an HTML error page) is e.response.body.
|
73
|
+
class RequestFailed < ExceptionWithResponse
|
74
|
+
def message
|
75
|
+
"HTTP status code #{http_code}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_s
|
79
|
+
message
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# backwards compatibility
|
85
|
+
class RestClient::Request
|
86
|
+
Redirect = RestClient::Redirect
|
87
|
+
Unauthorized = RestClient::Unauthorized
|
88
|
+
RequestFailed = RestClient::RequestFailed
|
89
|
+
end
|