routemaster-client 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d1a05ac44338e1e87ec3ca7b4bd4f21ab2cb10e
4
- data.tar.gz: 4a200ec16ebe99a1e635df0430ec0cc16077ff09
3
+ metadata.gz: bc445ea14e11c6da2c488693e9f7ed865baf033b
4
+ data.tar.gz: dfdc75c9e2e9e367af2d961635b2e734965f0ef2
5
5
  SHA512:
6
- metadata.gz: 3c2260a21412c4c56059c36493a30d49b07cbf79173fec5fe1fff1482678d625720367017679be4b59e1106a1361a951d1273738ec580bd01e33bfee9b97dcf5
7
- data.tar.gz: dd3bf21be43c6730938c1757859dcd387543821058de43ddd45b13fe5efec8867f022f9509d09ff2a910c763a717d493755affcf012f8847a4a460f790ab19d6
6
+ metadata.gz: 033cba5f52966eca578202264f2f9b18404a2217accd235588c405419a1068cea7e7622cad5c379abc050ba31943399b31adc0feffef04d02a286d76a4f886d5
7
+ data.tar.gz: 69061655159c553e0bb9ef0a4fdaf06f3aab4809663248bb5a306dd6e79c511ba793abd5153cb3e3ba9ec9f18da47402b4057ffdfa5869da1970b4e97605f7a3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- routemaster-client (1.1.0)
4
+ routemaster-client (1.2.0)
5
5
  faraday (>= 0.9.0)
6
6
  net-http-persistent
7
7
  wisper (>= 1.4.0)
data/README.md CHANGED
@@ -98,7 +98,7 @@ gem](https://github.com/krisleech/wisper#wisper).
98
98
 
99
99
  ```ruby
100
100
  client.monitor_topics
101
- #=> [ { name: 'widgets', publisher: 'demo', events: 12589 }, ...]
101
+ #=> [ #<Routemaster::Topic:XXXX @name="widgets", @publisher="demo", @events=12589>, ...]
102
102
 
103
103
  client.monitor_subscriptions
104
104
  #=> [ {
@@ -1,5 +1,6 @@
1
1
  require 'routemaster/client/version'
2
2
  require 'routemaster/client/openssl'
3
+ require 'routemaster/topic'
3
4
  require 'uri'
4
5
  require 'faraday'
5
6
  require 'json'
@@ -59,6 +60,20 @@ module Routemaster
59
60
  end
60
61
  end
61
62
 
63
+ def monitor_topics
64
+ response = _get('/topics') do |r|
65
+ r.headers['Content-Type'] = 'application/json'
66
+ end
67
+
68
+ unless response.success?
69
+ raise 'failed to connect to /topics'
70
+ end
71
+
72
+ JSON(response.body).map do |raw_topic|
73
+ Topic.new raw_topic
74
+ end
75
+ end
76
+
62
77
 
63
78
  private
64
79
 
@@ -112,6 +127,15 @@ module Routemaster
112
127
  retry
113
128
  end
114
129
 
130
+ def _get(path, &block)
131
+ retries ||= 5
132
+ _conn.get(path, &block)
133
+ rescue Net::HTTP::Persistent::Error => e
134
+ raise if (retries -= 1).zero?
135
+ puts "warning: retrying get to #{path} on #{e.class.name}: #{e.message} (#{retries})"
136
+ @_conn = nil
137
+ retry
138
+ end
115
139
 
116
140
  def _conn
117
141
  @_conn ||= Faraday.new(@_url) do |f|
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  class Client
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,17 @@
1
+ module Routemaster
2
+ class Topic
3
+
4
+ attr_reader :name, :publisher, :events
5
+
6
+ def initialize(options)
7
+ @name = options.fetch('name')
8
+ @publisher = options.fetch('publisher')
9
+ @events = options.fetch('events')
10
+ end
11
+
12
+ def attributes
13
+ { name: @name, publisher: @publisher, events: @events }
14
+ end
15
+
16
+ end
17
+ end
data/spec/client_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'routemaster/client'
3
+ require 'routemaster/topic'
3
4
  require 'webmock/rspec'
4
5
 
5
6
  describe Routemaster::Client do
@@ -208,7 +209,31 @@ describe Routemaster::Client do
208
209
  end
209
210
 
210
211
  describe '#monitor_topics' do
211
- it 'passes'
212
+
213
+ let(:perform) { subject.monitor_topics }
214
+ let(:expected_result) do
215
+ [
216
+ {
217
+ name: 'widgets',
218
+ publisher: 'demo',
219
+ events: 12589
220
+ }
221
+ ]
222
+ end
223
+
224
+ before do
225
+ @stub = stub_request(
226
+ :get, %r{^https://#{options[:uuid]}:x@bus.example.com/topics$}
227
+ ).with { |r|
228
+ r.headers['Content-Type'] == 'application/json'
229
+ }.to_return {
230
+ { status: 200, body: expected_result.to_json }
231
+ }
232
+ end
233
+
234
+ it 'expects a collection of topics' do
235
+ expect(perform.map(&:attributes)).to eql(expected_result)
236
+ end
212
237
  end
213
238
 
214
239
  describe '#monitor_subscriptions' do
@@ -0,0 +1,36 @@
1
+ require 'routemaster/topic'
2
+
3
+ describe Routemaster::Topic do
4
+
5
+ let(:name) { 'widgets' }
6
+ let(:publisher) { 'demo' }
7
+ let(:events) { 0 }
8
+
9
+ subject do
10
+ described_class.new({
11
+ "name" => name,
12
+ "publisher" => publisher,
13
+ "events" => events
14
+ })
15
+ end
16
+
17
+ describe '#initialize' do
18
+
19
+ it "creates an instance of #{described_class}" do
20
+ expect(subject).to be_an_instance_of(described_class)
21
+ end
22
+
23
+ end
24
+
25
+ describe '#attributes' do
26
+
27
+ it "returns an hash with all attributes" do
28
+ expect(subject.attributes).to eql({
29
+ name: name,
30
+ publisher: publisher,
31
+ events: events
32
+ })
33
+ end
34
+
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routemaster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-12 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -76,10 +76,12 @@ files:
76
76
  - routemaster/client/openssl.rb
77
77
  - routemaster/client/version.rb
78
78
  - routemaster/receiver.rb
79
+ - routemaster/topic.rb
79
80
  - spec/client_spec.rb
80
81
  - spec/receiver_spec.rb
81
82
  - spec/spec_helper.rb
82
83
  - spec/support/rack_test.rb
84
+ - spec/topic_spec.rb
83
85
  homepage: http://github.com/HouseTrip/routemaster_client
84
86
  licenses:
85
87
  - MIT
@@ -109,3 +111,4 @@ test_files:
109
111
  - spec/receiver_spec.rb
110
112
  - spec/spec_helper.rb
111
113
  - spec/support/rack_test.rb
114
+ - spec/topic_spec.rb