wrest 1.3.0-universal-java-1.6 → 1.4.0-universal-java-1.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -2,7 +2,11 @@ Features under the section marked 'Current' are completed but pending release as
2
2
 
3
3
  Features under a numbered section are complete and available in the Wrest gem.
4
4
 
5
- === 1.3.0
5
+ == 1.4.0
6
+ * GH#96 Naive implementation of asynchronous requests using Eventmachine
7
+ * GH#93 Since Wrest::Response is immutable, the results of Response#deserialise are cached
8
+
9
+ == 1.3.0
6
10
  * GH#95 Asynchronous requests on Wrest::Uri.
7
11
 
8
12
  == 1.2.1
data/README.rdoc CHANGED
@@ -1,15 +1,17 @@
1
- = Wrest 1.3.0
1
+ = Wrest 1.4.0
2
2
 
3
3
  (c) Copyright 2009-2011 {Sidu Ponnappa}[http://blog.sidu.in]. All Rights Reserved.
4
4
 
5
5
  Wrest is a ruby REST/HTTP client library which
6
6
 
7
+ * Allows you to use Net::HTTP or libCurl
8
+ * Allows you to pick your Ruby: use 1.8.7, 1.9.2, JRuby and Rubinius ({Continuous Integration server}[http://ci.c42.in])
9
+ * Supports RFC 2616 based {caching}[https://github.com/kaiwren/wrest/blob/caching/Caching.markdown]
10
+ * [Alpha] Allows you to go async: use Threads or EventMachine
7
11
  * Allows you to quickly build object oriented wrappers around any web service
8
- * Designed to be used as a library, not just a command line REST client (fewer class/static methods, more object oriented)
12
+ * Is designed to be used as a library, not just a command line REST client (fewer class/static methods, more object oriented)
9
13
  * Is spec driven, strongly favours immutable objects and avoids class methods and setters making it better suited for use as a library, especially in multi-threaded environments
10
- * Runs on Ruby 1.8, Ruby 1.9.2, JRuby and Rubinius with MacRuby and IronRuby support on the way ({Continuous Integration server}[http://ci.c42.in])
11
- * Provides convenient HTTP wrappers, redirect handling, serialisation, deserialisation and response {caching}[https://github.com/kaiwren/wrest/blob/caching/Caching.markdown]
12
- * Supports using either Net::HTTP or libcurl as the underlying HTTP library
14
+ * Provides convenient HTTP wrappers, redirect handling, serialisation, deserialisation and xpath based lookup
13
15
 
14
16
  To receive notifications whenever new features are added to Wrest, please subscribe to my {twitter feed}[http://twitter.com/ponnappa].
15
17
 
@@ -26,9 +28,11 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
26
28
  'http://twitter.com/statuses/public_timeline.json'.to_uri.get.deserialise # works with json and xml out of the box
27
29
 
28
30
  'http://twitter.com/statuses/public_timeline.xml'.to_uri.get.deserialise # see lib/wrest/components/translators to add other formats
31
+
29
32
  * Timeout support
30
33
 
31
34
  'http://twitter.com/statuses/public_timeline.json'.to_uri.get(:timeout => 5).body
35
+
32
36
  * Redirect support
33
37
 
34
38
  'http://google.com'.to_uri(:follow_redirects => false).get
@@ -98,7 +102,7 @@ To delete a resource:
98
102
 
99
103
  Wrest supports caching with pluggable back-ends.
100
104
 
101
- Wrest.always_cache_using_hash! # Hash should NEVER be used in a production environment. It is unbounded and will keep increasing in size.
105
+ Wrest::Caching.default_to_hash! # Hash should NEVER be used in a production environment. It is unbounded and will keep increasing in size.
102
106
  c42 = "http://c42.in".to_uri.get
103
107
 
104
108
  A Memcached based caching back-end is available in Wrest. You can get instructions on how to install Memcached on your system {here}[http://code.google.com/p/memcached/wiki/NewInstallFromPackage].
@@ -106,15 +110,12 @@ The Dalli gem is used by Wrest to interface with Memcached. Install dalli using
106
110
 
107
111
  Use the following method to enable caching for all requests, and set Memcached as the default back-end.
108
112
 
109
- Wrest.always_cache_using_memcached!
113
+ Wrest::Caching.default_to_memcached!
110
114
 
111
115
  For fine-grained control over the cache store (or to use multiple cache stores in the same codebase), you can use this API:
112
116
 
113
- memcache_store = Wrest::Components::CacheStore::Memcached.new("localhost:11211")
114
- hash_store = {}
115
-
116
- r1 = "http://c42.in".to_uri(:cache_store => memcache_store).get
117
- r2 = "http://c42.in".to_uri(:cache_store => hash_store).get
117
+ r1 = "http://c42.in".to_uri.using_memcached.get
118
+ r2 = "http://c42.in".to_uri.using_hash.get
118
119
 
119
120
  A detailed writeup regarding caching as defined by RFC 2616, and how Wrest implements caching is at {Wrest Caching Doc}[https://github.com/kaiwren/wrest/blob/master/Caching.markdown]
120
121
 
@@ -122,7 +123,7 @@ You can create your own back-ends for Wrest caching by implementing the interfac
122
123
 
123
124
  To explicitly disable caching for specific requests:
124
125
 
125
- "http://c42.in".to_uri(:disable_cache => true).get
126
+ "http://c42.in".to_uri.disable_cache.get
126
127
 
127
128
  === Callbacks
128
129
 
@@ -161,12 +162,30 @@ Please note that Wrest is a synchronous library. All requests are blocking, and
161
162
  Asynchronous requests are non-blocking. They do not return a response and the request is executed on a separate thread. The only way to access the response
162
163
  while using asynchronous request is through callbacks.
163
164
 
164
- "http://www.google.com".to_uri.get_async do |callback|
165
+ Asynchronous requests support pluggable backends. The default backend used for asynchronous requests is ruby threads.
166
+
167
+ "http://c42.in".to_uri.get_async do |callback|
168
+ callback.on_ok do |response|
169
+ Wrest.logger.info "Ok."
170
+ end
171
+ end
172
+
173
+ sleep 1 # Causes thread created by get_async to execute
174
+
175
+ You can change the default to eventmachine.
176
+
177
+ Wrest::AsyncRequest.default_to_em!
178
+
179
+ You can also override the default on Uri objects.
180
+
181
+ "http://c42.in".to_uri.using_em.get_async do |callback|
165
182
  callback.on_ok do |response|
166
183
  Wrest.logger.info "Ok."
167
184
  end
168
185
  end
169
186
 
187
+ Note: The current implementation of asynchronous requests is currently in alpha and should not be used in production.
188
+
170
189
  === Other useful stuff
171
190
 
172
191
  Allows any class to hold an attributes hash, somewhat like ActiveResource. It also supports several extensions to this base fuctionality such as support for typecasting attribute values. See examples/twitter.rb and examples/wow_realm_status.rb for more samples.
@@ -0,0 +1,30 @@
1
+ # Copyright 2009 Sidu Ponnappa
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at native://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
7
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ begin
11
+ gem 'eventmachine', '~> 0.12.10'
12
+ rescue Gem::LoadError => e
13
+ Wrest.logger.debug "Eventmachine ~> 0.12.10 not found. Wrest uses Eventmachine to perform evented asynchronous requests"
14
+ raise e
15
+ end
16
+
17
+ require 'eventmachine'
18
+
19
+ module Wrest
20
+ module AsyncRequest
21
+ class EventMachineBackend
22
+ def execute(block)
23
+ EventMachine.run do
24
+ block.invoke
25
+ EventMachine.stop
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright 2009 Sidu Ponnappa
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at native://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
7
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module Wrest
11
+ module AsyncRequest
12
+ class ThreadBackend
13
+ def execute(block)
14
+ Thread.new do
15
+ block.invoke
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright 2009 Sidu Ponnappa
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at native://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
7
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+
11
+ module Wrest
12
+ module AsyncRequest
13
+ # Loads Wrest eventmachine backend alongwith eventmachine gem
14
+ def self.enable_em
15
+ require "#{Wrest::Root}/wrest/async_request/event_machine_backend"
16
+ end
17
+
18
+ # Assign default backend to be used for asynchronous request. Default is to use threads
19
+ def self.default_backend=(backend)
20
+ @default_backend = backend
21
+ end
22
+
23
+ # Assign default backend for asynchronous request to using eventmachine.
24
+ def self.default_to_em!
25
+ self.enable_em
26
+ self.default_backend = Wrest::AsyncRequest::EventMachineBackend.new
27
+ end
28
+
29
+ # Assign default backend for asynchronous request to using threads.
30
+ def self.default_to_threads!
31
+ self.default_backend = Wrest::AsyncRequest::ThreadBackend.new
32
+ end
33
+
34
+ # Returns the default backend
35
+ def self.default_backend
36
+ @default_backend
37
+ end
38
+ end
39
+ end
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  require 'dalli'
9
9
 
10
- module Wrest::Components::CacheStore
10
+ module Wrest::Caching
11
11
  class Memcached
12
12
 
13
13
  def initialize(server_urls=nil, options={})
@@ -0,0 +1,42 @@
1
+ # Copyright 2009 Sidu Ponnappa
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at native://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
7
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module Wrest
11
+ module Caching
12
+ # Loads the Memcached caching back-end and the Dalli gem
13
+ def self.enable_memcached
14
+ require "#{Wrest::Root}/wrest/caching/memcached"
15
+ end
16
+
17
+ # Configures Wrest to cache all requests. This will use a Ruby Hash.
18
+ # WARNING: This should NEVER be used in a real environment. The Hash will keep on growing since Wrest does not limit the size of a cache store.
19
+ #
20
+ # Use the Memcached caching back-end for production since the Memcached process uses an LRU based cache removal policy
21
+ # that keeps the number of entries stored within bounds.
22
+ def self.default_to_hash!
23
+ self.default_store = Hash.new
24
+ end
25
+
26
+ # Default Wrest to using memcached for caching requests.
27
+ def self.default_to_memcached!
28
+ self.enable_memcached
29
+ self.default_store = Wrest::Caching::Memcached.new
30
+ end
31
+
32
+ # Assign the default cache store to be used. Default is none.
33
+ def self.default_store=(store)
34
+ @default_store = store
35
+ end
36
+
37
+ # Returns the default store for caching, if any is set.
38
+ def self.default_store
39
+ @default_store
40
+ end
41
+ end
42
+ end
@@ -16,6 +16,7 @@ module Wrest #:nodoc:
16
16
  # See HttpCodes for a list of all such response checkers.
17
17
  class Response
18
18
  attr_reader :http_response
19
+ attr_accessor :deserialised_body
19
20
  include HttpShared::Headers
20
21
  include HttpCodes
21
22
 
@@ -36,7 +37,7 @@ module Wrest #:nodoc:
36
37
  end
37
38
 
38
39
  def deserialise(options = {})
39
- deserialise_using(Wrest::Components::Translators.lookup(content_type),options)
40
+ @deserialised_body ||= deserialise_using(Wrest::Components::Translators.lookup(content_type),options)
40
41
  end
41
42
 
42
43
  def deserialise_using(translator,options={})
@@ -46,13 +46,11 @@ module Wrest
46
46
  # 'http://localhost:3000/uploads'.to_uri.post_multipart_async('file' => UploadIO.new(file, "image/jpg", '/path/to/image.jpg'))
47
47
  # end
48
48
  #
49
- # Note: post_multipart_async does not return a response and the response should be accessed through callbacks
50
- # This implementation of asynchronous post_multipart is very naive and should not be used in production.
51
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
49
+ # Note: post_multipart_async does not return a response and the response should be accessed through callbacks.
50
+ # This implementation of asynchronous post_multipart is currently in alpha. Hence, it should not be used in production.
52
51
  def post_multipart_async(parameters = {}, headers = {}, &block)
53
- Thread.new do
54
- post_multipart(parameters, headers, &block)
55
- end
52
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PostMultipart.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
53
+ nil
56
54
  end
57
55
 
58
56
  # Makes a multipart/form-data encoded PUT request to this URI. This is a convenience API
@@ -65,12 +63,10 @@ module Wrest
65
63
  # that mimics a multipart form being put. I sincerely hope you never need to use this.
66
64
  #
67
65
  # Note: put_multipart_async does not return a response and the response should be accessed through callbacks
68
- # This implementation of asynchronous put_multipart is very naive and should not be used in production.
69
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
66
+ # This implementation of asynchronous put_multipart is currently in alpha. Hence, it should not be used in production.
70
67
  def put_multipart_async(parameters = {}, headers = {}, &block)
71
- Thread.new do
72
- put_multipart(parameters, headers, &block)
73
- end
68
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PutMultipart.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
69
+ nil
74
70
  end
75
71
  end
76
72
 
@@ -15,7 +15,7 @@ module Wrest::Native
15
15
  follow_redirects = options[:follow_redirects]
16
16
  options[:follow_redirects] = (follow_redirects == nil ? true : follow_redirects)
17
17
 
18
- cache_store = (options[:cache_store] || Wrest.default_cachestore) unless options[:disable_cache]
18
+ cache_store = (options[:cache_store] || Wrest::Caching.default_store) unless options[:disable_cache]
19
19
  @cache_proxy = Wrest::CacheProxy::new(self, cache_store)
20
20
 
21
21
  super(
@@ -57,8 +57,8 @@ module Wrest::Native
57
57
  @cache_store = options[:cache_store]
58
58
  @verify_mode = @options[:verify_mode]
59
59
  @detailed_http_logging = options[:detailed_http_logging]
60
- @uri_callback = Wrest::Callback.new(@options[:callback] || {})
61
- @request_callback = Wrest::Callback.new(@options[:callback_block] || {})
60
+ @callback = @options[:callback] || Wrest::Callback.new({})
61
+ @callback = @callback.merge(Wrest::Callback.new(@options[:callback_block] || {}))
62
62
  end
63
63
 
64
64
  # Makes a request, runs the appropriate callback if any and
@@ -115,7 +115,7 @@ module Wrest::Native
115
115
 
116
116
  #:nodoc:
117
117
  def execute_callback_if_any(actual_response)
118
- @uri_callback.merge(@request_callback).execute(actual_response)
118
+ @callback.execute(actual_response)
119
119
  end
120
120
  end
121
121
  end
@@ -24,6 +24,7 @@ module Wrest #:nodoc:
24
24
  # See HttpCodes for a list of all such response checkers.
25
25
  class Response
26
26
  attr_reader :http_response
27
+ attr_accessor :deserialised_body
27
28
  include HttpCodes
28
29
 
29
30
  extend Forwardable
@@ -73,7 +74,7 @@ module Wrest #:nodoc:
73
74
 
74
75
 
75
76
  def deserialise(options = {})
76
- deserialise_using(Wrest::Components::Translators.lookup(@http_response.content_type),options)
77
+ @deserialised_body ||= deserialise_using(Wrest::Components::Translators.lookup(@http_response.content_type),options)
77
78
  end
78
79
 
79
80
  def deserialise_using(translator,options = {})
data/lib/wrest/uri.rb CHANGED
@@ -26,7 +26,7 @@ module Wrest #:nodoc:
26
26
 
27
27
  # See Wrest::Native::Request for the available options and their default values.
28
28
  def initialize(uri_string, options = {})
29
- @options = options
29
+ @options = options.clone
30
30
  @uri_string = uri_string.to_s
31
31
  @uri = URI.parse(@uri_string)
32
32
  uri_scheme = URI.split(@uri_string)
@@ -35,6 +35,7 @@ module Wrest #:nodoc:
35
35
  @query = uri_scheme[-2] || ''
36
36
  @username = (@options[:username] ||= @uri.user)
37
37
  @password = (@options[:password] ||= @uri.password)
38
+ @options[:callback] = Callback.new(@options[:callback]) if @options[:callback]
38
39
  end
39
40
 
40
41
  def to_template(pattern)
@@ -95,18 +96,53 @@ module Wrest #:nodoc:
95
96
  Http::Get.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options).invoke
96
97
  end
97
98
 
99
+ # Returns a Uri object that uses threads to perform asynchronous requests.
100
+ def using_threads
101
+ options = @options.clone
102
+ options[:asynchronous_backend] = Wrest::AsyncRequest::ThreadBackend.new
103
+ Uri.new(uri_string, options)
104
+ end
105
+
106
+ # Returns a Uri object that uses eventmachine to perform asynchronous requests.
107
+ def using_em
108
+ options = @options.clone
109
+ Wrest::AsyncRequest.enable_em
110
+ options[:asynchronous_backend] = Wrest::AsyncRequest::EventMachineBackend.new
111
+ Uri.new(uri_string, options)
112
+ end
113
+
114
+ # Returns a Uri object that uses hash for caching responses.
115
+ def using_hash
116
+ options = @options.clone
117
+ options[:cache_store] = Hash.new
118
+ Uri.new(uri_string, options)
119
+ end
120
+
121
+ # Returns a Uri object that uses memcached for caching responses.
122
+ def using_memcached
123
+ options = @options.clone
124
+ Wrest::Caching.enable_memcached
125
+ options[:cache_store] = Wrest::Caching::Memcached.new
126
+ Uri.new(uri_string, options)
127
+ end
128
+
129
+ def disable_cache
130
+ options = @options.clone
131
+ Wrest::Caching.enable_memcached
132
+ options[:disable_cache] = true
133
+ Uri.new(uri_string, options)
134
+ end
135
+
98
136
  # Make a GET request to this URI. This is a convenience API
99
137
  # that creates a Wrest::Native::Get.
100
138
  #
101
139
  # Remember to escape all parameter strings if necessary, using URI.escape
102
140
  #
103
141
  # Note: get_async does not return a response and the response should be accessed through callbacks.
104
- # This implementation of asynchronous get is very naive and should not be used in production.
105
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
142
+ # This implementation of asynchronous get is currently in alpha. Hence, it should not be used in production.
106
143
  def get_async(parameters = {}, headers = {}, &block)
107
- Thread.new do
108
- get(parameters, headers, &block)
109
- end
144
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::Get.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
145
+ nil
110
146
  end
111
147
 
112
148
  # Make a PUT request to this URI. This is a convenience API
@@ -123,12 +159,10 @@ module Wrest #:nodoc:
123
159
  # Remember to escape all parameter strings if necessary, using URI.escape
124
160
  #
125
161
  # Note: put_async does not return a response and the response should be accessed through callbacks.
126
- # This implementation of asynchronous put is very naive and should not be used in production.
127
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
162
+ # This implementation of asynchronous put is currently in alpha. Hence, it should not be used in production.
128
163
  def put_async(body = '', headers = {}, parameters = {}, &block)
129
- Thread.new do
130
- put(body, headers, parameters, &block)
131
- end
164
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::Put.new(self, body.to_s, headers, parameters, block ? @options.merge(:callback_block => block) : @options))
165
+ nil
132
166
  end
133
167
 
134
168
  # Makes a POST request to this URI. This is a convenience API
@@ -147,12 +181,10 @@ module Wrest #:nodoc:
147
181
  # Remember to escape all parameter strings if necessary, using URI.escape
148
182
  #
149
183
  # Note: post_async does not return a response and the response should be accessed through callbacks.
150
- # This implementation of asynchronous post is very naive and should not be used in production.
151
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
184
+ # This implementation of asynchronous post is currently in alpha. Hence, it should not be used in production.
152
185
  def post_async(body = '', headers = {}, parameters = {}, &block)
153
- Thread.new do
154
- post(body, headers, parameters, &block)
155
- end
186
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::Post.new(self, body.to_s, headers, parameters, block ? @options.merge(:callback_block => block) : @options))
187
+ nil
156
188
  end
157
189
 
158
190
  # Makes a POST request to this URI. This is a convenience API
@@ -177,12 +209,12 @@ module Wrest #:nodoc:
177
209
  # application/x-www-form-urlencoded
178
210
  #
179
211
  # Note: post_form_async does not return a response and the response should be accessed through callbacks.
180
- # This implementation of asynchronous post_form is very naive and should not be used in production.
181
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
212
+ # This implementation of asynchronous post_form is currently in alpha. Hence, it should not be used in production.
182
213
  def post_form_async(parameters = {}, headers = {}, &block)
183
- Thread.new do
184
- post_form(parameters, headers, &block)
185
- end
214
+ headers = headers.merge(Wrest::H::ContentType => Wrest::T::FormEncoded)
215
+ body = parameters.to_query
216
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::Post.new(self, body, headers, {}, block ? @options.merge(:callback_block => block) : @options))
217
+ nil
186
218
  end
187
219
 
188
220
  # Makes a DELETE request to this URI. This is a convenience API
@@ -199,12 +231,10 @@ module Wrest #:nodoc:
199
231
  # Remember to escape all parameter strings if necessary, using URI.escape
200
232
  #
201
233
  # Note: delete_async does not return a response and the response should be accessed through callbacks.
202
- # This implementation of asynchronous delete is very naive and should not be used in production.
203
- # Stable implementation of asynchronous requests involving thread pools would be out soon.
234
+ # This implementation of asynchronous delete is currently in alpha. Hence, it should not be used in production.
204
235
  def delete_async(parameters = {}, headers = {}, &block)
205
- Thread.new do
206
- delete(parameters, headers, &block)
207
- end
236
+ (@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::Delete.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
237
+ nil
208
238
  end
209
239
 
210
240
  # Makes an OPTIONS request to this URI. This is a convenience API
data/lib/wrest/version.rb CHANGED
@@ -8,5 +8,5 @@
8
8
  # See the License for the specific language governing permissions and limitations under the License.
9
9
 
10
10
  module Wrest
11
- VERSION = "1.3.0"
11
+ VERSION = "1.4.0"
12
12
  end
data/lib/wrest.rb CHANGED
@@ -36,6 +36,10 @@ module Wrest
36
36
  @logger
37
37
  end
38
38
 
39
+ def self.enable_evented_requests!
40
+ require "#{Wrest::Root}/wrest/event_machine_backend"
41
+ end
42
+
39
43
  # Switch Wrest to using Net::HTTP.
40
44
  def self.use_native!
41
45
  silence_warnings{ Wrest.const_set('Http', Wrest::Native) }
@@ -46,37 +50,6 @@ module Wrest
46
50
  require "#{Wrest::Root}/wrest/curl"
47
51
  silence_warnings{ Wrest.const_set('Http', Wrest::Curl) }
48
52
  end
49
-
50
- # Loads the Memcached caching back-end and the Dalli gem
51
- def self.enable_memcached_caching!
52
- require "#{Wrest::Root}/wrest/components/cache_store/memcached"
53
- end
54
-
55
- # Assign the default cache store to be used. Default is none.
56
- def self.default_cachestore=(cachestore)
57
- @default_cachestore = cachestore
58
- end
59
-
60
- # Returns the default cache store, if any is set.
61
- def self.default_cachestore
62
- @default_cachestore
63
- end
64
-
65
- # Configures Wrest to cache all requests. This will use the Memcached backend.
66
- def self.always_cache_using_memcached!
67
- self.enable_memcached_caching!
68
- self.default_cachestore=Wrest::Components::CacheStore::Memcached.new
69
- end
70
-
71
- # Configures Wrest to cache all requests. This will use a Ruby Hash.
72
- # WARNING: This should NEVER be used in a real environment. The Hash will keep on growing since Wrest does not limit the size of a cache store.
73
- #
74
- # Use the Memcached caching back-end for production since the Memcached process uses an LRU based cache removal policy
75
- # that keeps the number of entries stored within bounds.
76
- def self.always_cache_using_hash!
77
- Wrest.logger.warn "Using an in-memory Hash as a cache store. This is dangerous if used in a production environment."
78
- self.default_cachestore=Hash.new
79
- end
80
53
  end
81
54
 
82
55
  Wrest.logger = ActiveSupport::BufferedLogger.new(STDOUT)
@@ -99,6 +72,11 @@ require "#{Wrest::Root}/wrest/http_codes"
99
72
  require "#{Wrest::Root}/wrest/callback"
100
73
  require "#{Wrest::Root}/wrest/native"
101
74
 
75
+ require "#{Wrest::Root}/wrest/async_request"
76
+ require "#{Wrest::Root}/wrest/async_request/thread_backend"
77
+ Wrest::AsyncRequest.default_to_threads!
78
+
79
+ require "#{Wrest::Root}/wrest/caching"
102
80
 
103
81
  # Load Wrest Wrappers
104
82
  require "#{Wrest::Root}/wrest/uri"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: wrest
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.0
5
+ version: 1.4.0
6
6
  platform: universal-java-1.6
7
7
  authors:
8
8
  - Sidu Ponnappa
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-02-08 00:00:00 +05:30
14
+ date: 2011-02-15 00:00:00 +05:30
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -135,7 +135,7 @@ dependencies:
135
135
  version: 1.4.3.1
136
136
  type: :runtime
137
137
  version_requirements: *id011
138
- description: Wrest is a HTTP and REST client library which allows you to quickly build well encapsulated, object oriented wrappers around any web service.
138
+ description: Wrest is a fluent, easy-to-use, object oriented Ruby HTTP/REST client library with support for RFC2616 HTTP caching, multiple HTTP backends and async calls using EventMachine. It runs on CRuby, JRuby and Rubinius.
139
139
  email:
140
140
  - sidu@c42.in
141
141
  executables:
@@ -149,7 +149,9 @@ files:
149
149
  - bin/wrest_shell.rb
150
150
  - lib/wrest.rb
151
151
  - lib/wrest_no_ext.rb
152
+ - lib/wrest/async_request.rb
152
153
  - lib/wrest/cache_proxy.rb
154
+ - lib/wrest/caching.rb
153
155
  - lib/wrest/callback.rb
154
156
  - lib/wrest/components.rb
155
157
  - lib/wrest/curl.rb
@@ -164,10 +166,12 @@ files:
164
166
  - lib/wrest/uri_template.rb
165
167
  - lib/wrest/version.rb
166
168
  - lib/wrest/xml_mini.rb
169
+ - lib/wrest/async_request/event_machine_backend.rb
170
+ - lib/wrest/async_request/thread_backend.rb
171
+ - lib/wrest/caching/memcached.rb
167
172
  - lib/wrest/components/container.rb
168
173
  - lib/wrest/components/mutators.rb
169
174
  - lib/wrest/components/translators.rb
170
- - lib/wrest/components/cache_store/memcached.rb
171
175
  - lib/wrest/components/container/alias_accessors.rb
172
176
  - lib/wrest/components/container/typecaster.rb
173
177
  - lib/wrest/components/mutators/base.rb
@@ -243,10 +247,11 @@ requirements:
243
247
  - To use Memcached as caching back-end, install the 'dalli' gem.
244
248
  - To use multipart post, install the 'multipart-post' gem.
245
249
  - To use curl as the http engine, install the 'patron' gem. This feature is not available (and should be unneccessary) on jruby.
250
+ - To use eventmachine as a parallel backend, install the 'eventmachine' gem.
246
251
  rubyforge_project: wrest
247
252
  rubygems_version: 1.5.0
248
253
  signing_key:
249
254
  specification_version: 3
250
- summary: Wrest is an elegant, object oriented HTTP client library for 1.8, 1.9, JRuby and Rubinius.
255
+ summary: Wrest is a fluent, object oriented HTTP client library for 1.8, 1.9, JRuby and Rubinius.
251
256
  test_files: []
252
257