wrest 1.5.3 → 1.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af75d10ad96bd8e0539620594008b533d1d19a1a
4
- data.tar.gz: 5760c9925189879d52eb6a83c599fcac4788f700
3
+ metadata.gz: c2ef12f85a25ae1566e9dc1b687a364d765f6a08
4
+ data.tar.gz: fb83d920f115473b271d16cad06195fb73524d00
5
5
  SHA512:
6
- metadata.gz: e566458f7d00c59cda57695f0d8b55bc16d06d27e10d6980837584dbf184a7a74167e10644ba3b4c444d1073d0eaf8a9686cd51cda89a6825e2e13d4997a3edd
7
- data.tar.gz: d1571b4cb17d98827dc391e616755d5e55d07c47da244fa09e5690c0dff1ac85a3f4480da7d46b856deecf598830363fbb48619bd3310fcdd6a952dfec45616e
6
+ metadata.gz: a88c38044cafcad5a161e4fd974b8023600c830865f1734451a5e948720d647b828f73caeca7b89ef008b6f8c472c44e2a05cc8b4602458939280427dd7121ab
7
+ data.tar.gz: baff6d4f993a61763836866bd838b0517c802aaa1547593aeb07b92c5a599defa77a70db5616e2e3bdacec48b343c4c78f1513990e4bb1727d537d69f5a17688
data/CHANGELOG CHANGED
@@ -2,6 +2,9 @@ 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.5.4
6
+ * Make thread pool configurable
7
+
5
8
  == 1.5.3
6
9
  * Implemented a thread pool for async requests using ThreadBackend
7
10
  * Updated request/response logging to include current thread id
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/c42/wrest.svg?branch=master)](https://travis-ci.org/c42/wrest)
2
2
 
3
- # Wrest 1.5.3
3
+ # Wrest 1.5.4
4
4
 
5
5
  (c) Copyright 2009-2015 [Sidu Ponnappa](http://twitter.com/ponnappa). All Rights Reserved.
6
6
 
@@ -9,10 +9,7 @@ Wrest is a ruby REST/HTTP client library which
9
9
  * Allows you to use Net::HTTP or libCurl
10
10
  * Allows you to pick your Ruby: use 2.x.x, JRuby 1.7.6 (and higher), JRuby 9.0.0.0.pre2
11
11
  * Supports RFC 2616 based [caching](https://github.com/kaiwren/wrest/blob/caching/Caching.markdown)
12
- * **_Alpha_**
13
-
14
- Allows you to go async: use Threads or EventMachine
15
-
12
+ * Async http calls using Threads (reliable only on JRuby) or EventMachine
16
13
  * Allows you to quickly build object oriented wrappers around any web service
17
14
  * Is designed to be used as a library, not just a command line REST client (fewer class/static methods, more object oriented)
18
15
  * 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
@@ -31,15 +28,16 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
31
28
  * Basic API calls
32
29
 
33
30
  ```
34
- 'http://twitter.com/statuses/public_timeline.json'.to_uri.get.deserialise # works with json and xml out of the box
35
-
36
- 'http://twitter.com/statuses/public_timeline.xml'.to_uri.get.deserialise # see lib/wrest/components/translators to add other formats
31
+ # Works with json and xml out of the box
32
+ # See lib/wrest/components/translators to add other formats
33
+
34
+ 'https://api.github.com/repos/c42/wrest/issues'.to_uri.get.deserialize
37
35
  ```
38
36
 
39
37
  * Timeout support
40
38
 
41
39
  ```
42
- 'http://twitter.com/statuses/public_timeline.json'.to_uri.get(:timeout => 5).body
40
+ 'https://api.github.com/repos/c42/wrest/issues'.to_uri.get(:timeout => 5).body
43
41
  ```
44
42
 
45
43
  * Redirect support
@@ -217,11 +215,15 @@ Asynchronous requests support pluggable backends. The default backend used for a
217
215
  Wrest::AsyncRequest.wait_for_thread_pool!
218
216
  ```
219
217
 
220
- You can change the default to eventmachine.
218
+ You can change the default to eventmachine or to threads.
221
219
 
222
220
  ```
223
221
  Wrest::AsyncRequest.default_to_em!
224
222
  ```
223
+ or
224
+ ```
225
+ Wrest::AsyncRequest.default_to_threads!
226
+ ```
225
227
 
226
228
  You can also override the default on Uri objects.
227
229
 
@@ -233,7 +235,16 @@ You can also override the default on Uri objects.
233
235
  end
234
236
  ```
235
237
 
236
- Note: The current implementation of asynchronous requests is currently in alpha and should not be used in production.
238
+ You can decide which AsyncBackend to use at runtime through to `to_uri`'s options hash.
239
+
240
+ ```
241
+ "http://c42.in".to_uri(asynchronous_backend: ThreadBackend.new(number_of_threads)).get_async do |callback|
242
+ callback.on_ok do |response|
243
+ Wrest.logger.info "Ok."
244
+ end
245
+ end
246
+ ```
247
+
237
248
 
238
249
  ### Other useful stuff
239
250
 
@@ -27,8 +27,8 @@ module Wrest
27
27
  end
28
28
 
29
29
  # Assign default backend for asynchronous request to using threads.
30
- def self.default_to_threads!
31
- self.default_backend = Wrest::AsyncRequest::ThreadBackend.new
30
+ def self.default_to_threads!(number_of_threads = 5)
31
+ self.default_backend = Wrest::AsyncRequest::ThreadBackend.new(number_of_threads)
32
32
  end
33
33
 
34
34
  # Returns the default backend, which is the ThreadBackend
@@ -14,12 +14,10 @@ module Wrest
14
14
  @threads = []
15
15
  @number_of_threads = number_of_threads
16
16
  @queue = Queue.new
17
- halt_on_sigint
18
- halt_on_int
19
- initialize_thread_pool
20
17
  end
21
18
 
22
19
  def execute_eventually(request)
20
+ initialize_thread_pool if @threads.empty?
23
21
  @queue.push(request)
24
22
  nil
25
23
  end
@@ -32,6 +30,8 @@ module Wrest
32
30
 
33
31
  private
34
32
  def initialize_thread_pool
33
+ halt_on_sigint
34
+ halt_on_int
35
35
  main_thread = Thread.current
36
36
  @threads = @number_of_threads.times.map do |i|
37
37
  Thread.new do |thread|
@@ -55,9 +55,11 @@ module Wrest
55
55
  end
56
56
 
57
57
  def halt
58
- Wrest.logger.debug "Shutting down ThreadPool..."
59
- @threads.each(&:terminate)
60
- Wrest.logger.debug "Halted ThreadPool, continuing with shutdown..."
58
+ unless @threads.empty?
59
+ Wrest.logger.debug "Wrest: Shutting down ThreadPool..."
60
+ @threads.each(&:terminate)
61
+ Wrest.logger.debug "Wrest: Halted ThreadPool, continuing with shutdown."
62
+ end
61
63
  Process.exit
62
64
  end
63
65
  end
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.5.3"
11
+ VERSION = "1.5.4"
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidu Ponnappa
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-04 00:00:00.000000000 Z
12
+ date: 2015-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec