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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71fc71379386c45f55e01051b376bf514a1075c7
4
- data.tar.gz: f928e5b82c9a3f1363b63f26ab44ced207bb9eed
3
+ metadata.gz: 5e2e3b27d9cdd63bf53ffecbe03691cd958f57da
4
+ data.tar.gz: 1c9a5d20dd052ee3ab3888d6a495ce13cfbc94ed
5
5
  SHA512:
6
- metadata.gz: 5d381aac49625af92235bd160607220756cd596f8ffdcabc9a90512185564e65e3a4356a0650227e9b6aa5edacedd6b0b3cf4cfdf0883adca4fb48be38f00d6a
7
- data.tar.gz: bfa47194947c204e83e027d3311ec950ec35a5a7417f727317120844908ebab2c3f32bfc1caa212d7f483aa5682ace607c0e580159fde3020c32cd7c889a5ddb
6
+ metadata.gz: fcc573e74f35f9f8baacc09ce81f76111ad91b35b8bccd2f344203efee0a27e589e9c67322252287d55f768b0465fadd0146256dec3a92213f1b951a621f0c8c
7
+ data.tar.gz: 12741fd1e4bff91d66226c86867be01ae0d9004cf85142fd28a38da12245bcb9a29840943c54b3d06c221e688c2ddd990574ecc92f28372fc2040a9e40718177
@@ -13,7 +13,3 @@ before_install:
13
13
  - rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
14
14
  install: 'bundle install --retry=3'
15
15
  script: 'ruby -vr bundler/setup -S rake test'
16
-
17
- matrix:
18
- allow_failures:
19
- - rvm: rbx
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-2015, Lin Jen-Shin (godfat)
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 = 'rest-core'
12
- s.version = RestCore::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
@@ -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
- ensure
116
- promise.done
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
- until sock.eof?
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.close
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
 
@@ -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('', 0, {})
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
@@ -21,4 +21,9 @@ class Pork::Executor
21
21
  ensure
22
22
  f.close!
23
23
  end
24
+
25
+ def stub_select_for_stringio
26
+ stub(IO).select(where([is_a(StringIO)]), [], [],
27
+ RestCore::EventSource::READ_WAIT){ |rd, *| rd }
28
+ end
24
29
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RestCore
3
- VERSION = '3.5.92'
3
+ VERSION = '3.6.0'
4
4
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rest-core 3.5.92 ruby lib
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.5.92"
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 = "2015-12-28"
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 = [
@@ -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
@@ -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.5.92
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: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient