routemaster-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +12 -19
- data/README.md +17 -6
- data/routemaster/client/version.rb +1 -1
- data/routemaster/receiver.rb +10 -3
- data/routemaster-client.gemspec +1 -9
- data/spec/receiver_spec.rb +46 -11
- metadata +7 -119
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
routemaster-client (0.0.
|
4
|
+
routemaster-client (0.0.3)
|
5
5
|
faraday
|
6
6
|
net-http-persistent
|
7
|
-
|
7
|
+
wisper (>= 1.4.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: http://eu.yarp.io/
|
@@ -26,14 +26,14 @@ GEM
|
|
26
26
|
lumberjack (~> 1.0)
|
27
27
|
pry (>= 0.9.12)
|
28
28
|
thor (>= 0.18.1)
|
29
|
-
guard-rspec (4.
|
29
|
+
guard-rspec (4.3.1)
|
30
30
|
guard (~> 2.1)
|
31
31
|
rspec (>= 2.14, < 4.0)
|
32
|
-
listen (2.7.
|
32
|
+
listen (2.7.9)
|
33
33
|
celluloid (>= 0.15.2)
|
34
34
|
rb-fsevent (>= 0.9.3)
|
35
35
|
rb-inotify (>= 0.9)
|
36
|
-
lumberjack (1.0.
|
36
|
+
lumberjack (1.0.9)
|
37
37
|
method_source (0.8.2)
|
38
38
|
multipart-post (2.0.0)
|
39
39
|
net-http-persistent (2.9.4)
|
@@ -45,8 +45,6 @@ GEM
|
|
45
45
|
pry (~> 0.9.10)
|
46
46
|
psych (2.0.5)
|
47
47
|
rack (1.5.2)
|
48
|
-
rack-protection (1.5.3)
|
49
|
-
rack
|
50
48
|
rack-test (0.6.2)
|
51
49
|
rack (>= 1.0)
|
52
50
|
rake (10.3.2)
|
@@ -57,37 +55,32 @@ GEM
|
|
57
55
|
rspec-core (~> 3.0.0)
|
58
56
|
rspec-expectations (~> 3.0.0)
|
59
57
|
rspec-mocks (~> 3.0.0)
|
60
|
-
rspec-core (3.0.
|
58
|
+
rspec-core (3.0.3)
|
61
59
|
rspec-support (~> 3.0.0)
|
62
|
-
rspec-expectations (3.0.
|
60
|
+
rspec-expectations (3.0.3)
|
63
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
62
|
rspec-support (~> 3.0.0)
|
65
|
-
rspec-mocks (3.0.
|
63
|
+
rspec-mocks (3.0.3)
|
66
64
|
rspec-support (~> 3.0.0)
|
67
|
-
rspec-support (3.0.
|
65
|
+
rspec-support (3.0.3)
|
68
66
|
safe_yaml (1.0.3)
|
69
|
-
|
70
|
-
rack (~> 1.4)
|
71
|
-
rack-protection (~> 1.4)
|
72
|
-
tilt (~> 1.3, >= 1.3.4)
|
73
|
-
slop (3.5.0)
|
67
|
+
slop (3.6.0)
|
74
68
|
thor (0.19.1)
|
75
|
-
tilt (1.4.1)
|
76
69
|
timers (1.1.0)
|
77
70
|
webmock (1.18.0)
|
78
71
|
addressable (>= 2.3.6)
|
79
72
|
crack (>= 0.3.2)
|
73
|
+
wisper (1.4.0)
|
80
74
|
|
81
75
|
PLATFORMS
|
82
76
|
ruby
|
83
77
|
|
84
78
|
DEPENDENCIES
|
85
|
-
bundler
|
79
|
+
bundler
|
86
80
|
guard-rspec
|
87
81
|
pry-nav
|
88
82
|
psych
|
89
83
|
rack-test
|
90
84
|
rake
|
91
85
|
routemaster-client!
|
92
|
-
rspec
|
93
86
|
webmock
|
data/README.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# routemaster-client
|
2
2
|
|
3
3
|
A Ruby API for the [Routemaster](https://github.com/HouseTrip/routemaster) event
|
4
4
|
bus.
|
5
5
|
|
6
|
+
[![Version](https://badge.fury.io/rb/routemaster-client.svg)](https://rubygems.org/gems/routemaster-client)
|
7
|
+
|
8
|
+
[![Build](https://travis-ci.org/HouseTrip/routemaster-client.svg?branch=master)](https://travis-ci.org/HouseTrip/routemaster-client)
|
9
|
+
|
10
|
+
[![Docs](http://img.shields.io/badge/API%20docs-rubydoc.info-blue.svg)](http://rubydoc.info/github/HouseTrip/routemaster-client/frames/file/README.md)
|
11
|
+
|
12
|
+
|
6
13
|
## Installation
|
7
14
|
|
8
15
|
Add this line to your application's Gemfile:
|
@@ -67,21 +74,25 @@ client.subscribe(
|
|
67
74
|
```ruby
|
68
75
|
require 'routemaster/receiver'
|
69
76
|
|
70
|
-
class
|
71
|
-
def
|
77
|
+
class Listener
|
78
|
+
def on_events_received(batch)
|
72
79
|
batch.each do |event|
|
73
80
|
puts event['url']
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
85
|
+
Wisper.subscribe(Listener.new, :prefix => true)
|
86
|
+
|
78
87
|
use Routemaster::Receiver, {
|
79
88
|
path: '/events',
|
80
|
-
uuid: 'demo'
|
81
|
-
handler: Handler.new
|
89
|
+
uuid: 'demo'
|
82
90
|
}
|
83
91
|
```
|
84
92
|
|
93
|
+
This relies on the excellent event bus from the [wisper
|
94
|
+
gem](https://github.com/krisleech/wisper#wisper).
|
95
|
+
|
85
96
|
|
86
97
|
**Monitor** the status of topics and subscriptions:
|
87
98
|
|
@@ -100,7 +111,7 @@ client.monitor_subscriptions
|
|
100
111
|
|
101
112
|
## Contributing
|
102
113
|
|
103
|
-
1. Fork it ( http://github.com
|
114
|
+
1. Fork it ( http://github.com/HouseTrip/routemaster-client/fork )
|
104
115
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
116
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
106
117
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/routemaster/receiver.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
-
require 'sinatra'
|
2
1
|
require 'rack/auth/basic'
|
3
2
|
require 'base64'
|
4
3
|
require 'json'
|
4
|
+
require 'wisper'
|
5
5
|
|
6
6
|
module Routemaster
|
7
7
|
class Receiver
|
8
|
+
include Wisper::Publisher
|
9
|
+
|
8
10
|
def initialize(app, options = {})
|
9
11
|
@app = app
|
10
12
|
@path = options[:path]
|
11
13
|
@uuid = options[:uuid]
|
12
|
-
|
14
|
+
|
15
|
+
if options[:handler]
|
16
|
+
warn 'the :handler option is deprecated, listen to the :events_received event instead'
|
17
|
+
@handler = options[:handler]
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
def call(env)
|
@@ -19,7 +25,8 @@ module Routemaster
|
|
19
25
|
return [403, {}, []] unless _valid_auth?(env)
|
20
26
|
return [400, {}, []] unless payload = _extract_payload(env)
|
21
27
|
|
22
|
-
@handler.on_events(payload)
|
28
|
+
@handler.on_events(payload) if @handler
|
29
|
+
publish(:events_received, payload)
|
23
30
|
return [204, {}, []]
|
24
31
|
end
|
25
32
|
@app.call(env)
|
data/routemaster-client.gemspec
CHANGED
@@ -16,15 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^spec/})
|
17
17
|
spec.require_paths = %w(.)
|
18
18
|
|
19
|
-
spec.add_development_dependency 'bundler', '~> 1.5'
|
20
|
-
spec.add_development_dependency 'rake'
|
21
|
-
spec.add_development_dependency 'rspec'
|
22
|
-
spec.add_development_dependency 'guard-rspec'
|
23
|
-
spec.add_development_dependency 'webmock'
|
24
|
-
spec.add_development_dependency 'pry-nav'
|
25
|
-
spec.add_development_dependency 'rack-test'
|
26
|
-
|
27
19
|
spec.add_runtime_dependency 'faraday'
|
28
20
|
spec.add_runtime_dependency 'net-http-persistent'
|
29
|
-
spec.add_runtime_dependency '
|
21
|
+
spec.add_runtime_dependency 'wisper', '>= 1.4.0'
|
30
22
|
end
|
data/spec/receiver_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec/support/rack_test'
|
|
3
3
|
require 'routemaster/receiver'
|
4
4
|
|
5
5
|
describe Routemaster::Receiver do
|
6
|
-
let(:handler) { double 'handler', on_events: nil }
|
6
|
+
let(:handler) { double 'handler', on_events: nil, on_events_received: true }
|
7
7
|
let(:app) { described_class.new(fake_app, options) }
|
8
8
|
|
9
9
|
|
@@ -14,8 +14,7 @@ describe Routemaster::Receiver do
|
|
14
14
|
let(:options) do
|
15
15
|
{
|
16
16
|
path: '/events',
|
17
|
-
uuid: 'demo'
|
18
|
-
handler: handler
|
17
|
+
uuid: 'demo'
|
19
18
|
}
|
20
19
|
end
|
21
20
|
|
@@ -59,15 +58,51 @@ describe Routemaster::Receiver do
|
|
59
58
|
expect(last_response.status).to eq(501)
|
60
59
|
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
context 'with the deprecated :handler option' do
|
62
|
+
let(:options) {{
|
63
|
+
path: '/events',
|
64
|
+
uuid: 'demo',
|
65
|
+
handler: handler
|
66
|
+
}}
|
67
|
+
|
68
|
+
it 'calls the handler when receiving an avent' do
|
69
|
+
authorize 'demo', 'x'
|
70
|
+
expect(handler).to receive(:on_events).exactly(:once)
|
71
|
+
perform
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'calls the handler multiple times' do
|
75
|
+
authorize 'demo', 'x'
|
76
|
+
expect(handler).to receive(:on_events).exactly(3).times
|
77
|
+
3.times { perform }
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'warns about deprecation' do
|
81
|
+
expect_any_instance_of(described_class).to receive(:warn).with(/deprecated/)
|
82
|
+
app
|
83
|
+
end
|
66
84
|
end
|
67
85
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
86
|
+
context 'with a listener' do
|
87
|
+
let(:handler) { double }
|
88
|
+
before { Wisper.subscribe(handler, scope: 'Routemaster::Receiver', prefix: true) }
|
89
|
+
after { Wisper::GlobalListeners.clear }
|
90
|
+
|
91
|
+
it 'broadcasts :events_received' do
|
92
|
+
authorize 'demo', 'x'
|
93
|
+
|
94
|
+
expect(handler).to receive(:on_events_received).exactly(:once)
|
95
|
+
# TODO:
|
96
|
+
# we'll be able to say this with a more recent wisper (and skip the
|
97
|
+
# handler):
|
98
|
+
# expect(app).to publish_event(:events_received)
|
99
|
+
perform
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'can broadcast multiple times' do
|
103
|
+
authorize 'demo', 'x'
|
104
|
+
expect(handler).to receive(:on_events_received).exactly(3).times
|
105
|
+
3.times { perform }
|
106
|
+
end
|
72
107
|
end
|
73
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: routemaster-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,120 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - "~>"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '1.5'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.5'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rake
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ">="
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: guard-rspec
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: webmock
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: pry-nav
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ">="
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ">="
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: rack-test
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ">="
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
14
|
- !ruby/object:Gem::Dependency
|
127
15
|
name: faraday
|
128
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,13 +44,13 @@ dependencies:
|
|
156
44
|
- !ruby/object:Gem::Version
|
157
45
|
version: '0'
|
158
46
|
- !ruby/object:Gem::Dependency
|
159
|
-
name:
|
47
|
+
name: wisper
|
160
48
|
requirement: !ruby/object:Gem::Requirement
|
161
49
|
none: false
|
162
50
|
requirements:
|
163
51
|
- - ">="
|
164
52
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
53
|
+
version: 1.4.0
|
166
54
|
type: :runtime
|
167
55
|
prerelease: false
|
168
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -170,7 +58,7 @@ dependencies:
|
|
170
58
|
requirements:
|
171
59
|
- - ">="
|
172
60
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
61
|
+
version: 1.4.0
|
174
62
|
description:
|
175
63
|
email:
|
176
64
|
- julien.letessier@gmail.com
|
@@ -214,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
102
|
version: '0'
|
215
103
|
segments:
|
216
104
|
- 0
|
217
|
-
hash: -
|
105
|
+
hash: -2540830957177487143
|
218
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
107
|
none: false
|
220
108
|
requirements:
|
@@ -223,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
111
|
version: '0'
|
224
112
|
segments:
|
225
113
|
- 0
|
226
|
-
hash: -
|
114
|
+
hash: -2540830957177487143
|
227
115
|
requirements: []
|
228
116
|
rubyforge_project:
|
229
117
|
rubygems_version: 1.8.23.2
|