esod-client 0.1.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.
Files changed (83) hide show
  1. data/EXAMPLES +140 -0
  2. data/GEM_RELEASE +19 -0
  3. data/README +10 -0
  4. data/Rakefile +14 -0
  5. data/VERSION +1 -0
  6. data/esod-client.gemspec +118 -0
  7. data/esod-client.rb +35 -0
  8. data/lib/activesupport-2.2.2/CHANGELOG +1257 -0
  9. data/lib/activesupport-2.2.2/README +43 -0
  10. data/lib/activesupport-2.2.2/README.CFT +2 -0
  11. data/lib/activesupport-2.2.2/lib/active_support.rb +26 -0
  12. data/lib/activesupport-2.2.2/lib/active_support/base64.rb +33 -0
  13. data/lib/activesupport-2.2.2/lib/active_support/basic_object.rb +24 -0
  14. data/lib/activesupport-2.2.2/lib/active_support/buffered_logger.rb +122 -0
  15. data/lib/activesupport-2.2.2/lib/active_support/cache.rb +223 -0
  16. data/lib/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
  17. data/lib/activesupport-2.2.2/lib/active_support/cache/drb_store.rb +15 -0
  18. data/lib/activesupport-2.2.2/lib/active_support/cache/file_store.rb +72 -0
  19. data/lib/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb +127 -0
  20. data/lib/activesupport-2.2.2/lib/active_support/cache/memory_store.rb +52 -0
  21. data/lib/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb +47 -0
  22. data/lib/activesupport-2.2.2/lib/active_support/callbacks.rb +280 -0
  23. data/lib/activesupport-2.2.2/lib/active_support/core_ext.rb +6 -0
  24. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash.rb +14 -0
  25. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/conversions.rb +259 -0
  26. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
  27. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/diff.rb +19 -0
  28. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/except.rb +25 -0
  29. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
  30. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/keys.rb +52 -0
  31. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
  32. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/slice.rb +33 -0
  33. data/lib/activesupport-2.2.2/lib/active_support/vendor.rb +14 -0
  34. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  35. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  36. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  37. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  38. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  39. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  40. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  41. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  42. data/lib/activesupport-2.2.2/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  43. data/lib/activesupport-2.2.2/lib/activesupport.rb +1 -0
  44. data/lib/esodclient/esodclient.rb +22 -0
  45. data/lib/hash.rb +22 -0
  46. data/lib/mime-types-1.16/History.txt +107 -0
  47. data/lib/mime-types-1.16/Install.txt +17 -0
  48. data/lib/mime-types-1.16/Licence.txt +15 -0
  49. data/lib/mime-types-1.16/Manifest.txt +12 -0
  50. data/lib/mime-types-1.16/README.txt +28 -0
  51. data/lib/mime-types-1.16/Rakefile +316 -0
  52. data/lib/mime-types-1.16/lib/mime/types.rb +751 -0
  53. data/lib/mime-types-1.16/lib/mime/types.rb.data +1324 -0
  54. data/lib/mime-types-1.16/mime-types.gemspec +43 -0
  55. data/lib/mime-types-1.16/setup.rb +1585 -0
  56. data/lib/mime-types-1.16/test/test_mime_type.rb +356 -0
  57. data/lib/mime-types-1.16/test/test_mime_types.rb +122 -0
  58. data/lib/rest-client-1.2.0/README.rdoc +102 -0
  59. data/lib/rest-client-1.2.0/Rakefile +57 -0
  60. data/lib/rest-client-1.2.0/VERSION +1 -0
  61. data/lib/rest-client-1.2.0/bin/restclient +87 -0
  62. data/lib/rest-client-1.2.0/lib/rest_client.rb +2 -0
  63. data/lib/rest-client-1.2.0/lib/restclient.rb +108 -0
  64. data/lib/rest-client-1.2.0/lib/restclient/exceptions.rb +89 -0
  65. data/lib/rest-client-1.2.0/lib/restclient/mixin/response.rb +48 -0
  66. data/lib/rest-client-1.2.0/lib/restclient/net_http_ext.rb +21 -0
  67. data/lib/rest-client-1.2.0/lib/restclient/payload.rb +178 -0
  68. data/lib/rest-client-1.2.0/lib/restclient/raw_response.rb +30 -0
  69. data/lib/rest-client-1.2.0/lib/restclient/request.rb +287 -0
  70. data/lib/rest-client-1.2.0/lib/restclient/resource.rb +146 -0
  71. data/lib/rest-client-1.2.0/lib/restclient/response.rb +20 -0
  72. data/lib/rest-client-1.2.0/spec/base.rb +10 -0
  73. data/lib/rest-client-1.2.0/spec/exceptions_spec.rb +65 -0
  74. data/lib/rest-client-1.2.0/spec/master_shake.jpg +0 -0
  75. data/lib/rest-client-1.2.0/spec/mixin/response_spec.rb +46 -0
  76. data/lib/rest-client-1.2.0/spec/payload_spec.rb +131 -0
  77. data/lib/rest-client-1.2.0/spec/raw_response_spec.rb +17 -0
  78. data/lib/rest-client-1.2.0/spec/request_spec.rb +521 -0
  79. data/lib/rest-client-1.2.0/spec/resource_spec.rb +75 -0
  80. data/lib/rest-client-1.2.0/spec/response_spec.rb +21 -0
  81. data/lib/rest-client-1.2.0/spec/restclient_spec.rb +53 -0
  82. data/lib/trollop/trollop.rb +735 -0
  83. metadata +137 -0
@@ -0,0 +1,146 @@
1
+ module RestClient
2
+ # A class that can be instantiated for access to a RESTful resource,
3
+ # including authentication.
4
+ #
5
+ # Example:
6
+ #
7
+ # resource = RestClient::Resource.new('http://some/resource')
8
+ # jpg = resource.get(:accept => 'image/jpg')
9
+ #
10
+ # With HTTP basic authentication:
11
+ #
12
+ # resource = RestClient::Resource.new('http://protected/resource', :user => 'user', :password => 'password')
13
+ # resource.delete
14
+ #
15
+ # With a timeout (seconds):
16
+ #
17
+ # RestClient::Resource.new('http://slow', :timeout => 10)
18
+ #
19
+ # With an open timeout (seconds):
20
+ #
21
+ # RestClient::Resource.new('http://behindfirewall', :open_timeout => 10)
22
+ #
23
+ # You can also use resources to share common headers. For headers keys,
24
+ # symbols are converted to strings. Example:
25
+ #
26
+ # resource = RestClient::Resource.new('http://some/resource', :headers => { :client_version => 1 })
27
+ #
28
+ # This header will be transported as X-Client-Version (notice the X prefix,
29
+ # capitalization and hyphens)
30
+ #
31
+ # Use the [] syntax to allocate subresources:
32
+ #
33
+ # site = RestClient::Resource.new('http://example.com', :user => 'adam', :password => 'mypasswd')
34
+ # site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
35
+ #
36
+ class Resource
37
+ attr_reader :url, :options
38
+
39
+ def initialize(url, options={}, backwards_compatibility=nil)
40
+ @url = url
41
+ if options.class == Hash
42
+ @options = options
43
+ else # compatibility with previous versions
44
+ @options = { :user => options, :password => backwards_compatibility }
45
+ end
46
+ end
47
+
48
+ def get(additional_headers={}, &b)
49
+ headers = (options[:headers] || {}).merge(additional_headers)
50
+ Request.execute(options.merge(
51
+ :method => :get,
52
+ :url => url,
53
+ :headers => headers), &b)
54
+ end
55
+
56
+ def post(payload, additional_headers={}, &b)
57
+ headers = (options[:headers] || {}).merge(additional_headers)
58
+ Request.execute(options.merge(
59
+ :method => :post,
60
+ :url => url,
61
+ :payload => payload,
62
+ :headers => headers), &b)
63
+ end
64
+
65
+ def put(payload, additional_headers={}, &b)
66
+ headers = (options[:headers] || {}).merge(additional_headers)
67
+ Request.execute(options.merge(
68
+ :method => :put,
69
+ :url => url,
70
+ :payload => payload,
71
+ :headers => headers), &b)
72
+ end
73
+
74
+ def delete(additional_headers={}, &b)
75
+ headers = (options[:headers] || {}).merge(additional_headers)
76
+ Request.execute(options.merge(
77
+ :method => :delete,
78
+ :url => url,
79
+ :headers => headers), &b)
80
+ end
81
+
82
+ def to_s
83
+ url
84
+ end
85
+
86
+ def user
87
+ options[:user]
88
+ end
89
+
90
+ def password
91
+ options[:password]
92
+ end
93
+
94
+ def headers
95
+ options[:headers] || {}
96
+ end
97
+
98
+ def timeout
99
+ options[:timeout]
100
+ end
101
+
102
+ def open_timeout
103
+ options[:open_timeout]
104
+ end
105
+
106
+ # Construct a subresource, preserving authentication.
107
+ #
108
+ # Example:
109
+ #
110
+ # site = RestClient::Resource.new('http://example.com', 'adam', 'mypasswd')
111
+ # site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'
112
+ #
113
+ # This is especially useful if you wish to define your site in one place and
114
+ # call it in multiple locations:
115
+ #
116
+ # def orders
117
+ # RestClient::Resource.new('http://example.com/orders', 'admin', 'mypasswd')
118
+ # end
119
+ #
120
+ # orders.get # GET http://example.com/orders
121
+ # orders['1'].get # GET http://example.com/orders/1
122
+ # orders['1/items'].delete # DELETE http://example.com/orders/1/items
123
+ #
124
+ # Nest resources as far as you want:
125
+ #
126
+ # site = RestClient::Resource.new('http://example.com')
127
+ # posts = site['posts']
128
+ # first_post = posts['1']
129
+ # comments = first_post['comments']
130
+ # comments.post 'Hello', :content_type => 'text/plain'
131
+ #
132
+ def [](suburl)
133
+ self.class.new(concat_urls(url, suburl), options)
134
+ end
135
+
136
+ def concat_urls(url, suburl) # :nodoc:
137
+ url = url.to_s
138
+ suburl = suburl.to_s
139
+ if url.slice(-1, 1) == '/' or suburl.slice(0, 1) == '/'
140
+ url + suburl
141
+ else
142
+ "#{url}/#{suburl}"
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/mixin/response'
2
+
3
+ module RestClient
4
+ # The response from RestClient looks like a string, but is actually one of
5
+ # these. 99% of the time you're making a rest call all you care about is
6
+ # the body, but on the occassion you want to fetch the headers you can:
7
+ #
8
+ # RestClient.get('http://example.com').headers[:content_type]
9
+ #
10
+ class Response < String
11
+
12
+ include RestClient::Mixin::Response
13
+
14
+ def initialize(string, net_http_res)
15
+ @net_http_res = net_http_res
16
+ super(string || "")
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ begin
5
+ require "ruby-debug"
6
+ rescue LoadError
7
+ # NOP, ignore
8
+ end
9
+
10
+ require File.dirname(__FILE__) + '/../lib/restclient'
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe RestClient::Exception do
4
+ it "sets the exception message to ErrorMessage" do
5
+ RestClient::ResourceNotFound.new.message.should == 'Resource not found'
6
+ end
7
+
8
+ it "contains exceptions in RestClient" do
9
+ RestClient::Unauthorized.new.should be_a_kind_of(RestClient::Exception)
10
+ RestClient::ServerBrokeConnection.new.should be_a_kind_of(RestClient::Exception)
11
+ end
12
+ end
13
+
14
+ describe RestClient::RequestFailed do
15
+ before do
16
+ @response = mock('HTTP Response', :code => '502')
17
+ end
18
+
19
+ it "stores the http response on the exception" do
20
+ begin
21
+ raise RestClient::RequestFailed, :response
22
+ rescue RestClient::RequestFailed => e
23
+ e.response.should == :response
24
+ end
25
+ end
26
+
27
+ it "http_code convenience method for fetching the code as an integer" do
28
+ RestClient::RequestFailed.new(@response).http_code.should == 502
29
+ end
30
+
31
+ it "http_body convenience method for fetching the body (decoding when necessary)" do
32
+ @response.stub!(:[]).with('content-encoding').and_return('gzip')
33
+ @response.stub!(:body).and_return('compressed body')
34
+ RestClient::Request.should_receive(:decode).with('gzip', 'compressed body').and_return('plain body')
35
+ RestClient::RequestFailed.new(@response).http_body.should == 'plain body'
36
+ end
37
+
38
+ it "shows the status code in the message" do
39
+ RestClient::RequestFailed.new(@response).to_s.should match(/502/)
40
+ end
41
+ end
42
+
43
+ describe RestClient::ResourceNotFound do
44
+ it "also has the http response attached" do
45
+ begin
46
+ raise RestClient::ResourceNotFound, :response
47
+ rescue RestClient::ResourceNotFound => e
48
+ e.response.should == :response
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "backwards compatibility" do
54
+ it "alias RestClient::Request::Redirect to RestClient::Redirect" do
55
+ RestClient::Request::Redirect.should == RestClient::Redirect
56
+ end
57
+
58
+ it "alias RestClient::Request::Unauthorized to RestClient::Unauthorized" do
59
+ RestClient::Request::Unauthorized.should == RestClient::Unauthorized
60
+ end
61
+
62
+ it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
63
+ RestClient::Request::RequestFailed.should == RestClient::RequestFailed
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../base'
2
+
3
+ class MockResponse
4
+ include RestClient::Mixin::Response
5
+
6
+ def initialize(body, res)
7
+ @net_http_res = res
8
+ @body = @body
9
+ end
10
+ end
11
+
12
+ describe RestClient::Mixin::Response do
13
+ before do
14
+ @net_http_res = mock('net http response')
15
+ @response = MockResponse.new('abc', @net_http_res)
16
+ end
17
+
18
+ it "fetches the numeric response code" do
19
+ @net_http_res.should_receive(:code).and_return('200')
20
+ @response.code.should == 200
21
+ end
22
+
23
+ it "beautifies the headers by turning the keys to symbols" do
24
+ h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
25
+ h.keys.first.should == :content_type
26
+ end
27
+
28
+ it "beautifies the headers by turning the values to strings instead of one-element arrays" do
29
+ h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
30
+ h.values.first.should == 'text/html'
31
+ end
32
+
33
+ it "fetches the headers" do
34
+ @net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
35
+ @response.headers.should == { :content_type => 'text/html' }
36
+ end
37
+
38
+ it "extracts cookies from response headers" do
39
+ @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
40
+ @response.cookies.should == { 'session_id' => '1' }
41
+ end
42
+
43
+ it "can access the net http result directly" do
44
+ @response.net_http_res.should == @net_http_res
45
+ end
46
+ end
@@ -0,0 +1,131 @@
1
+ require File.dirname(__FILE__) + "/base"
2
+
3
+ describe RestClient::Payload do
4
+ context "A regular Payload" do
5
+ it "should use standard enctype as default content-type" do
6
+ RestClient::Payload::UrlEncoded.new({}).headers['Content-Type'].
7
+ should == 'application/x-www-form-urlencoded'
8
+ end
9
+
10
+ it "should form properly encoded params" do
11
+ RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s.
12
+ should == "foo=bar"
13
+ end
14
+
15
+ it "should properly handle hashes as parameter" do
16
+ RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz' }}).to_s.
17
+ should == "foo[bar]=baz"
18
+ RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux' }}}).to_s.
19
+ should == "foo[bar][baz]=qux"
20
+ end
21
+
22
+ it "should form properly use symbols as parameters" do
23
+ RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
24
+ should == "foo=bar"
25
+ RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz }}).to_s.
26
+ should == "foo[bar]=baz"
27
+ end
28
+
29
+ end
30
+
31
+ context "A multipart Payload" do
32
+ it "should use standard enctype as default content-type" do
33
+ m = RestClient::Payload::Multipart.new({})
34
+ m.stub!(:boundary).and_return(123)
35
+ m.headers['Content-Type'].should == 'multipart/form-data; boundary="123"'
36
+ end
37
+
38
+ it "should form properly separated multipart data" do
39
+ m = RestClient::Payload::Multipart.new([[:bar, "baz"], [:foo, "bar"]])
40
+ m.to_s.should == <<-EOS
41
+ --#{m.boundary}\r
42
+ Content-Disposition: multipart/form-data; name="bar"\r
43
+ \r
44
+ baz\r
45
+ --#{m.boundary}\r
46
+ Content-Disposition: multipart/form-data; name="foo"\r
47
+ \r
48
+ bar\r
49
+ --#{m.boundary}--\r
50
+ EOS
51
+ end
52
+
53
+ it "should form properly separated multipart data" do
54
+ f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
55
+ m = RestClient::Payload::Multipart.new({:foo => f})
56
+ m.to_s.should == <<-EOS
57
+ --#{m.boundary}\r
58
+ Content-Disposition: multipart/form-data; name="foo"; filename="master_shake.jpg"\r
59
+ Content-Type: image/jpeg\r
60
+ \r
61
+ #{IO.read(f.path)}\r
62
+ --#{m.boundary}--\r
63
+ EOS
64
+ end
65
+
66
+ it "should detect optional (original) content type and filename" do
67
+ f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
68
+ f.instance_eval "def content_type; 'text/plain'; end"
69
+ f.instance_eval "def original_filename; 'foo.txt'; end"
70
+ m = RestClient::Payload::Multipart.new({:foo => f})
71
+ m.to_s.should == <<-EOS
72
+ --#{m.boundary}\r
73
+ Content-Disposition: multipart/form-data; name="foo"; filename="foo.txt"\r
74
+ Content-Type: text/plain\r
75
+ \r
76
+ #{IO.read(f.path)}\r
77
+ --#{m.boundary}--\r
78
+ EOS
79
+ end
80
+
81
+ it "should handle hash in hash parameters" do
82
+ m = RestClient::Payload::Multipart.new({:bar => {:baz => "foo"}})
83
+ m.to_s.should == <<-EOS
84
+ --#{m.boundary}\r
85
+ Content-Disposition: multipart/form-data; name="bar[baz]"\r
86
+ \r
87
+ foo\r
88
+ --#{m.boundary}--\r
89
+ EOS
90
+
91
+ f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
92
+ f.instance_eval "def content_type; 'text/plain'; end"
93
+ f.instance_eval "def original_filename; 'foo.txt'; end"
94
+ m = RestClient::Payload::Multipart.new({:foo => {:bar => f}})
95
+ m.to_s.should == <<-EOS
96
+ --#{m.boundary}\r
97
+ Content-Disposition: multipart/form-data; name="foo[bar]"; filename="foo.txt"\r
98
+ Content-Type: text/plain\r
99
+ \r
100
+ #{IO.read(f.path)}\r
101
+ --#{m.boundary}--\r
102
+ EOS
103
+ end
104
+
105
+ end
106
+
107
+ context "Payload generation" do
108
+ it "should recognize standard urlencoded params" do
109
+ RestClient::Payload.generate({"foo" => 'bar'}).should be_kind_of(RestClient::Payload::UrlEncoded)
110
+ end
111
+
112
+ it "should recognize multipart params" do
113
+ f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
114
+ RestClient::Payload.generate({"foo" => f}).should be_kind_of(RestClient::Payload::Multipart)
115
+ end
116
+
117
+ it "should be multipart if forced" do
118
+ RestClient::Payload.generate({"foo" => "bar", :multipart => true}).should be_kind_of(RestClient::Payload::Multipart)
119
+ end
120
+
121
+ it "should return data if no of the above" do
122
+ RestClient::Payload.generate("data").should be_kind_of(RestClient::Payload::Base)
123
+ end
124
+
125
+ it "should recognize nested multipart payloads" do
126
+ f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
127
+ RestClient::Payload.generate({"foo" => {"file" => f}}).should be_kind_of(RestClient::Payload::Multipart)
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe RestClient::RawResponse do
4
+ before do
5
+ @tf = mock("Tempfile", :read => "the answer is 42", :open => true)
6
+ @net_http_res = mock('net http response')
7
+ @response = RestClient::RawResponse.new(@tf, @net_http_res)
8
+ end
9
+
10
+ it "behaves like string" do
11
+ @response.to_s.should == 'the answer is 42'
12
+ end
13
+
14
+ it "exposes a Tempfile" do
15
+ @response.file.should == @tf
16
+ end
17
+ end