rest-core 3.5.92 → 3.6.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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/CHANGES.md +17 -0
- data/README.md +2 -1
- data/Rakefile +2 -3
- data/lib/rest-core/builder.rb +14 -6
- data/lib/rest-core/event_source.rb +11 -2
- data/lib/rest-core/promise.rb +2 -2
- data/lib/rest-core/test.rb +5 -0
- data/lib/rest-core/version.rb +1 -1
- data/rest-core.gemspec +3 -3
- data/test/test_event_source.rb +2 -0
- data/test/test_promise.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2e3b27d9cdd63bf53ffecbe03691cd958f57da
|
4
|
+
data.tar.gz: 1c9a5d20dd052ee3ab3888d6a495ce13cfbc94ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc573e74f35f9f8baacc09ce81f76111ad91b35b8bccd2f344203efee0a27e589e9c67322252287d55f768b0465fadd0146256dec3a92213f1b951a621f0c8c
|
7
|
+
data.tar.gz: 12741fd1e4bff91d66226c86867be01ae0d9004cf85142fd28a38da12245bcb9a29840943c54b3d06c221e688c2ddd990574ecc92f28372fc2040a9e40718177
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## rest-core 3.6.0 -- 2016-01-27
|
4
|
+
|
5
|
+
### Incompatible changes
|
6
|
+
|
7
|
+
* Client.defer would now raise an error if the block would raise an error.
|
8
|
+
|
9
|
+
### Enhancements
|
10
|
+
|
11
|
+
* EventSource would now try to close the socket (actually, pipe from
|
12
|
+
httpclient) if there's no data coming in in 35 seconds,
|
13
|
+
(RC::EventSource::READ_WAIT) therefore we could reconnect in this case.
|
14
|
+
This is mostly for rest-firebase, reference:
|
15
|
+
<https://github.com/CodementorIO/rest-firebase/issues/8>
|
16
|
+
We would surely need a way to configure this timeout rather than
|
17
|
+
hard coding it for 35 seconds as different services could use different
|
18
|
+
timeout. Thanks @volksport for investigating this.
|
19
|
+
|
3
20
|
## rest-core 3.5.92 -- 2015-12-28
|
4
21
|
|
5
22
|
### Enhancements
|
data/README.md
CHANGED
@@ -796,13 +796,14 @@ the priority here is:
|
|
796
796
|
* Mariusz Pruszynski (@snicky)
|
797
797
|
* Mr. Big Cat (@miaout17)
|
798
798
|
* Nicolas Fouché (@nfo)
|
799
|
+
* Robert Balousek (@volksport)
|
799
800
|
* Szu-Kai Hsu (@brucehsu)
|
800
801
|
|
801
802
|
## LICENSE:
|
802
803
|
|
803
804
|
Apache License 2.0
|
804
805
|
|
805
|
-
Copyright (c) 2011-
|
806
|
+
Copyright (c) 2011-2016, Lin Jen-Shin (godfat)
|
806
807
|
|
807
808
|
Licensed under the Apache License, Version 2.0 (the "License");
|
808
809
|
you may not use this file except in compliance with the License.
|
data/Rakefile
CHANGED
@@ -8,9 +8,8 @@ end
|
|
8
8
|
|
9
9
|
Gemgem.init(dir) do |s|
|
10
10
|
require 'rest-core/version'
|
11
|
-
s.name
|
12
|
-
s.version
|
13
|
-
s.homepage = 'https://github.com/godfat/rest-core'
|
11
|
+
s.name = 'rest-core'
|
12
|
+
s.version = RestCore::VERSION
|
14
13
|
%w[httpclient mime-types].each{ |g| s.add_runtime_dependency(g) }
|
15
14
|
s.add_runtime_dependency('timers', '>=4.0.1')
|
16
15
|
end
|
data/lib/rest-core/builder.rb
CHANGED
@@ -105,18 +105,26 @@ class RestCore::Builder
|
|
105
105
|
|
106
106
|
def thread_pool; RestCore::ThreadPool[self]; end
|
107
107
|
|
108
|
-
def defer
|
108
|
+
def defer returns=:future_body
|
109
109
|
raise ArgumentError.new('no block given') unless block_given?
|
110
|
-
promise = RestCore::Promise.new(RestCore::CLIENT => self
|
110
|
+
promise = RestCore::Promise.new({RestCore::CLIENT => self},
|
111
|
+
lambda{ |res|
|
112
|
+
if err = res[FAIL].find{ |f| f.kind_of?(Exception) }
|
113
|
+
Promise.set_backtrace(err) unless err.backtrace
|
114
|
+
raise err
|
115
|
+
else
|
116
|
+
res
|
117
|
+
end
|
118
|
+
})
|
111
119
|
give_promise(WeakRef.new(promise))
|
112
120
|
promise.defer do
|
113
121
|
begin
|
114
|
-
yield
|
115
|
-
|
116
|
-
promise.
|
122
|
+
promise.done(yield)
|
123
|
+
rescue => e
|
124
|
+
promise.reject(e)
|
117
125
|
end
|
118
126
|
end
|
119
|
-
promise
|
127
|
+
promise.send(returns)
|
120
128
|
end
|
121
129
|
|
122
130
|
def give_promise weak_promise, ps=promises, m=mutex
|
@@ -5,6 +5,8 @@ require 'rest-core'
|
|
5
5
|
class RestCore::EventSource < Struct.new(:client, :path, :query, :opts,
|
6
6
|
:socket)
|
7
7
|
include RestCore
|
8
|
+
READ_WAIT = 35
|
9
|
+
|
8
10
|
def start
|
9
11
|
self.mutex = Mutex.new
|
10
12
|
self.condv = ConditionVariable.new
|
@@ -100,7 +102,7 @@ class RestCore::EventSource < Struct.new(:client, :path, :query, :opts,
|
|
100
102
|
private
|
101
103
|
# called in requesting thread after the request is done
|
102
104
|
def onmessage_for sock
|
103
|
-
|
105
|
+
while IO.select([sock], [], [], READ_WAIT)
|
104
106
|
event = sock.readline("\n\n").split("\n").inject({}) do |r, i|
|
105
107
|
k, v = i.split(': ', 2)
|
106
108
|
r[k] = v
|
@@ -108,9 +110,16 @@ class RestCore::EventSource < Struct.new(:client, :path, :query, :opts,
|
|
108
110
|
end
|
109
111
|
onmessage(event['event'], event['data'], sock)
|
110
112
|
end
|
111
|
-
sock
|
113
|
+
close_sock(sock)
|
112
114
|
onerror(EOFError.new, sock)
|
113
115
|
rescue IOError, SystemCallError => e
|
116
|
+
close_sock(sock)
|
117
|
+
onerror(e, sock)
|
118
|
+
end
|
119
|
+
|
120
|
+
def close_sock sock
|
121
|
+
sock.close
|
122
|
+
rescue IOError => e
|
114
123
|
onerror(e, sock)
|
115
124
|
end
|
116
125
|
|
data/lib/rest-core/promise.rb
CHANGED
@@ -119,8 +119,8 @@ class RestCore::Promise
|
|
119
119
|
end
|
120
120
|
|
121
121
|
# called in Client.defer to mark this promise as done
|
122
|
-
def done
|
123
|
-
fulfill(
|
122
|
+
def done body=''
|
123
|
+
fulfill(body, 0, {})
|
124
124
|
end
|
125
125
|
|
126
126
|
# It's considered done only if the HTTP request is done, and we're not
|
data/lib/rest-core/test.rb
CHANGED
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.
|
2
|
+
# stub: rest-core 3.6.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rest-core"
|
6
|
-
s.version = "3.
|
6
|
+
s.version = "3.6.0"
|
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 = "
|
11
|
+
s.date = "2016-01-27"
|
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 = [
|
data/test/test_event_source.rb
CHANGED
@@ -76,6 +76,7 @@ SSE
|
|
76
76
|
end
|
77
77
|
|
78
78
|
would 'reconnect' do
|
79
|
+
stub_select_for_stringio
|
79
80
|
stub_request(:get, 'https://a?b=c').to_return(:body => <<-SSE)
|
80
81
|
event: put
|
81
82
|
data: 0
|
@@ -109,6 +110,7 @@ SSE
|
|
109
110
|
end
|
110
111
|
|
111
112
|
would 'not cache' do
|
113
|
+
stub_select_for_stringio
|
112
114
|
stub_request(:get, 'https://a?b=c').to_return(:body => <<-SSE)
|
113
115
|
event: put
|
114
116
|
data: 0
|
data/test/test_promise.rb
CHANGED
@@ -48,13 +48,24 @@ describe RC::Promise do
|
|
48
48
|
would 'work, wait, done' do
|
49
49
|
@client.pool_size = 3
|
50
50
|
flag = 0
|
51
|
-
promise = @client.defer do
|
51
|
+
promise = @client.defer(:itself) do
|
52
52
|
flag.should.eq 0
|
53
53
|
flag += 1
|
54
54
|
end
|
55
55
|
@client.wait
|
56
56
|
flag.should.eq 1
|
57
57
|
promise.should.done?
|
58
|
+
end if Object.respond_to?(:itself)
|
59
|
+
|
60
|
+
would 'work, check body' do
|
61
|
+
@client.pool_size = 3
|
62
|
+
flag = 0
|
63
|
+
result = @client.defer do
|
64
|
+
flag.should.eq 0
|
65
|
+
flag += 1
|
66
|
+
end
|
67
|
+
result.should.eq 1
|
68
|
+
flag.should.eq 1
|
58
69
|
end
|
59
70
|
|
60
71
|
would 'warn on callback error' do
|
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.
|
4
|
+
version: 3.6.0
|
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:
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|