rest-core 3.5.7 → 3.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -4
- data/CHANGES.md +6 -0
- data/README.md +16 -0
- data/lib/rest-core/builder.rb +15 -0
- data/lib/rest-core/client.rb +1 -1
- data/lib/rest-core/promise.rb +5 -0
- data/lib/rest-core/version.rb +1 -1
- data/rest-core.gemspec +4 -4
- data/test/test_promise.rb +12 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23c11f1f962e09fd0bbb320ca71d7f74618dd79a
|
4
|
+
data.tar.gz: c9a39501f38e887d9a8ce115bd3280ac4151d253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 889495dc4261d1ae0dea20a0d821e5320053083c12c830508a17574dbf8a42fd1413ed5a7d83f3f396ed70c04df050b143e8c48f9f2d6e76982f1ac79382ffa1
|
7
|
+
data.tar.gz: e90f5213c0a9a4e0517b5ced5bf970c31793334c4224e47ab684c4a9ed29f06bb29699f55743dd7d689d8e22838a48e567b291cbcbfc7d6bed7299f0b6bdbd70
|
data/.travis.yml
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
-
|
1
|
+
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
4
|
- 2.0
|
5
5
|
- 2.1
|
6
6
|
- 2.2
|
7
|
-
- rbx
|
8
|
-
- jruby
|
7
|
+
- rbx
|
8
|
+
- jruby-9
|
9
9
|
|
10
|
+
before_install:
|
11
|
+
- rvm get head
|
12
|
+
- rvm reload
|
13
|
+
- rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
|
10
14
|
install: 'bundle install --retry=3'
|
11
|
-
script: 'ruby -
|
15
|
+
script: 'ruby -vr bundler/setup -S rake test'
|
16
|
+
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: rbx
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -246,6 +246,22 @@ end
|
|
246
246
|
|
247
247
|
If you're using unicorn, you probably want to put that in the config.
|
248
248
|
|
249
|
+
### Random Asynchronous Tasks
|
250
|
+
|
251
|
+
Occasionally we might want to do some asynchronous tasks which could take
|
252
|
+
the advantage of the concurrency facilities inside rest-core, for example,
|
253
|
+
using `wait` and `shutdown`. You could do this with `defer` for a particular
|
254
|
+
client. Still take `RC::Universal` as an example:
|
255
|
+
|
256
|
+
``` ruby
|
257
|
+
RC::Universal.defer do
|
258
|
+
sleep(1)
|
259
|
+
puts "Slow task done"
|
260
|
+
end
|
261
|
+
|
262
|
+
RC::Universal.wait
|
263
|
+
```
|
264
|
+
|
249
265
|
### Persistent connections (keep-alive connections)
|
250
266
|
|
251
267
|
Since we're using [httpclient][] by default now, we would reuse connections,
|
data/lib/rest-core/builder.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'thread'
|
3
|
+
require 'weakref'
|
3
4
|
require 'rest-core/client'
|
4
5
|
|
5
6
|
class RestCore::Builder
|
@@ -104,6 +105,20 @@ class RestCore::Builder
|
|
104
105
|
|
105
106
|
def thread_pool; RestCore::ThreadPool[self]; end
|
106
107
|
|
108
|
+
def defer
|
109
|
+
raise ArgumentError.new('no block given') unless block_given?
|
110
|
+
promise = RestCore::Promise.new(RestCore::CLIENT => self)
|
111
|
+
give_promise(WeakRef.new(promise))
|
112
|
+
promise.defer do
|
113
|
+
begin
|
114
|
+
yield
|
115
|
+
ensure
|
116
|
+
promise.done
|
117
|
+
end
|
118
|
+
end
|
119
|
+
promise
|
120
|
+
end
|
121
|
+
|
107
122
|
def give_promise weak_promise, ps=promises, m=mutex
|
108
123
|
m.synchronize do
|
109
124
|
ps << weak_promise
|
data/lib/rest-core/client.rb
CHANGED
@@ -211,7 +211,7 @@ module RestCore::Client
|
|
211
211
|
private
|
212
212
|
def request_complete res
|
213
213
|
if err = res[FAIL].find{ |f| f.kind_of?(Exception) }
|
214
|
-
|
214
|
+
Promise.set_backtrace(err) unless err.backtrace
|
215
215
|
error_callback.call(err) if error_callback
|
216
216
|
if res[ASYNC]
|
217
217
|
res.merge(response_key(res) => err)
|
data/lib/rest-core/promise.rb
CHANGED
@@ -118,6 +118,11 @@ class RestCore::Promise
|
|
118
118
|
self
|
119
119
|
end
|
120
120
|
|
121
|
+
# called in Client.defer to mark this promise as done
|
122
|
+
def done
|
123
|
+
fulfill('', 0, {})
|
124
|
+
end
|
125
|
+
|
121
126
|
# It's considered done only if the HTTP request is done, and we're not
|
122
127
|
# in asynchronous mode otherwise the callback should be called first.
|
123
128
|
# For synchronous mode, since we're waiting for the callback anyway,
|
data/lib/rest-core/version.rb
CHANGED
data/rest-core.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: rest-core 3.5.
|
2
|
+
# stub: rest-core 3.5.8 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rest-core"
|
6
|
-
s.version = "3.5.
|
6
|
+
s.version = "3.5.8"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2015-
|
11
|
+
s.date = "2015-12-07"
|
12
12
|
s.description = "Modular Ruby clients interface for REST APIs.\n\nThere has been an explosion in the number of REST APIs available today.\nTo address the need for a way to access these APIs easily and elegantly,\nwe have developed rest-core, which consists of composable middleware\nthat allows you to build a REST client for any REST API. Or in the case of\ncommon APIs such as Facebook, Github, and Twitter, you can simply use the\ndedicated clients provided by [rest-more][].\n\n[rest-more]: https://github.com/godfat/rest-more"
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.files = [
|
@@ -113,7 +113,7 @@ Gem::Specification.new do |s|
|
|
113
113
|
"test/test_universal.rb"]
|
114
114
|
s.homepage = "https://github.com/godfat/rest-core"
|
115
115
|
s.licenses = ["Apache License 2.0"]
|
116
|
-
s.rubygems_version = "2.
|
116
|
+
s.rubygems_version = "2.5.0"
|
117
117
|
s.summary = "Modular Ruby clients interface for REST APIs."
|
118
118
|
s.test_files = [
|
119
119
|
"test/test_auth_basic.rb",
|
data/test/test_promise.rb
CHANGED
@@ -45,6 +45,18 @@ describe RC::Promise do
|
|
45
45
|
@promise.send(:headers).should.eq('K' => 'V')
|
46
46
|
end
|
47
47
|
|
48
|
+
would 'work, wait, done' do
|
49
|
+
@client.pool_size = 3
|
50
|
+
flag = 0
|
51
|
+
promise = @client.defer do
|
52
|
+
flag.should.eq 0
|
53
|
+
flag += 1
|
54
|
+
end
|
55
|
+
@client.wait
|
56
|
+
flag.should.eq 1
|
57
|
+
promise.should.done?
|
58
|
+
end
|
59
|
+
|
48
60
|
would 'warn on callback error' do
|
49
61
|
mock(any_instance_of(RC::Promise)).warn(is_a(String)) do |msg|
|
50
62
|
msg.should.eq 'boom'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
191
|
+
rubygems_version: 2.5.0
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Modular Ruby clients interface for REST APIs.
|