routemaster-client 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d1a05ac44338e1e87ec3ca7b4bd4f21ab2cb10e
4
+ data.tar.gz: 4a200ec16ebe99a1e635df0430ec0cc16077ff09
5
+ SHA512:
6
+ metadata.gz: 3c2260a21412c4c56059c36493a30d49b07cbf79173fec5fe1fff1482678d625720367017679be4b59e1106a1361a951d1273738ec580bd01e33bfee9b97dcf5
7
+ data.tar.gz: dd3bf21be43c6730938c1757859dcd387543821058de43ddd45b13fe5efec8867f022f9509d09ff2a910c763a717d493755affcf012f8847a4a460f790ab19d6
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 1.9.3-p545
1
+ 2.2.0
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.0
6
6
  - 2.1.1
7
+ - 2.2.0
7
8
  script:
8
9
  - bundle exec rspec
9
10
  install:
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- routemaster-client (1.0.0)
4
+ routemaster-client (1.1.0)
5
5
  faraday (>= 0.9.0)
6
6
  net-http-persistent
7
7
  wisper (>= 1.4.0)
8
8
 
9
9
  GEM
10
- remote: http://eu.yarp.io/
10
+ remote: https://rubygems.org/
11
11
  specs:
12
12
  addressable (2.3.6)
13
13
  celluloid (0.15.2)
@@ -16,7 +16,7 @@ GEM
16
16
  crack (0.4.2)
17
17
  safe_yaml (~> 1.0.0)
18
18
  diff-lcs (1.2.5)
19
- faraday (0.9.0)
19
+ faraday (0.9.1)
20
20
  multipart-post (>= 1.2, < 3)
21
21
  ffi (1.9.3)
22
22
  formatador (0.2.5)
@@ -63,14 +63,14 @@ GEM
63
63
  rspec-mocks (3.0.3)
64
64
  rspec-support (~> 3.0.0)
65
65
  rspec-support (3.0.3)
66
- safe_yaml (1.0.3)
66
+ safe_yaml (1.0.4)
67
67
  slop (3.6.0)
68
68
  thor (0.19.1)
69
69
  timers (1.1.0)
70
70
  webmock (1.18.0)
71
71
  addressable (>= 2.3.6)
72
72
  crack (>= 0.3.2)
73
- wisper (1.4.0)
73
+ wisper (1.6.0)
74
74
 
75
75
  PLATFORMS
76
76
  ruby
data/README.md CHANGED
@@ -30,13 +30,13 @@ Or install it yourself as:
30
30
 
31
31
  ```ruby
32
32
  require 'routemaster/client'
33
- client = Routemaster::Client.new(url: 'https://bus.example.com', uuid: 'john-doe')
33
+ client = Routemaster::Client.new(url: 'https://bus.example.com', uuid: 'demo')
34
34
  ```
35
35
 
36
36
  You can also specify a timeout value in seconds if you like with the ```timeout``` option.
37
37
 
38
38
  ```ruby
39
- Routemaster::Client.new(url: 'https://bus.example.com', uuid: 'john-doe', timeout: 2)
39
+ Routemaster::Client.new(url: 'https://bus.example.com', uuid: 'demo', timeout: 2)
40
40
  ```
41
41
 
42
42
 
@@ -63,7 +63,7 @@ events, in batches of at most 500 events, to a given callback URL:
63
63
  client.subscribe(
64
64
  topics: ['widgets', 'kitten'],
65
65
  callback: 'https://app.example.com/events',
66
- uuid: 'john-doe',
66
+ uuid: 'demo',
67
67
  timeout: 60_000,
68
68
  max: 500)
69
69
  ```
@@ -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: 'john-doe', events: 12589 }, ...]
101
+ #=> [ { name: 'widgets', publisher: 'demo', events: 12589 }, ...]
102
102
 
103
103
  client.monitor_subscriptions
104
104
  #=> [ {
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  class Client
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -21,20 +21,20 @@ module Routemaster
21
21
  end
22
22
  end
23
23
 
24
- def created(topic, callback)
25
- _send_event('create', topic, callback)
24
+ def created(topic, callback, timestamp = nil)
25
+ _send_event('create', topic, callback, timestamp)
26
26
  end
27
27
 
28
- def updated(topic, callback)
29
- _send_event('update', topic, callback)
28
+ def updated(topic, callback, timestamp = nil)
29
+ _send_event('update', topic, callback, timestamp)
30
30
  end
31
31
 
32
- def deleted(topic, callback)
33
- _send_event('delete', topic, callback)
32
+ def deleted(topic, callback, timestamp = nil)
33
+ _send_event('delete', topic, callback, timestamp)
34
34
  end
35
35
 
36
- def noop(topic, callback)
37
- _send_event('noop', topic, callback)
36
+ def noop(topic, callback, timestamp = nil)
37
+ _send_event('noop', topic, callback, timestamp)
38
38
  end
39
39
 
40
40
  def subscribe(options = {})
@@ -80,10 +80,17 @@ module Routemaster
80
80
  _assert (topic =~ /^[a-z_]{1,32}$/), 'bad topic name'
81
81
  end
82
82
 
83
- def _send_event(event, topic, callback)
83
+ def _assert_valid_timestamp(timestamp)
84
+ _assert timestamp.is_a?(Numeric), 'not a numeric number'
85
+ end
86
+
87
+ def _send_event(event, topic, callback, timestamp = nil)
84
88
  _assert_valid_url(callback)
85
89
  _assert_valid_topic(topic)
86
- data = { type: event, url: callback }
90
+ _assert_valid_timestamp(timestamp) if timestamp
91
+
92
+ data = { type: event, url: callback, timestamp: timestamp }
93
+
87
94
  response = _post("/topics/#{topic}") do |r|
88
95
  r.headers['Content-Type'] = 'application/json'
89
96
  r.body = data.to_json
data/spec/client_spec.rb CHANGED
@@ -62,8 +62,8 @@ describe Routemaster::Client do
62
62
 
63
63
  shared_examples 'an event sender' do
64
64
  let(:callback) { 'https://app.example.com/widgets/123' }
65
- let(:topic) { 'widgets' }
66
- let(:perform) { subject.send(event, topic, callback) }
65
+ let(:topic) { 'widgets' }
66
+ let(:perform) { subject.send(event, topic, callback) }
67
67
 
68
68
  before do
69
69
  @stub = stub_request(
@@ -107,6 +107,30 @@ describe Routemaster::Client do
107
107
  @stub.to_timeout
108
108
  expect { perform }.to raise_error(Faraday::TimeoutError)
109
109
  end
110
+
111
+ context 'with explicit timestamp' do
112
+ let(:timestamp) { Time.now.to_f }
113
+ let(:perform) { subject.send(event, topic, callback, timestamp) }
114
+
115
+ before do
116
+ @stub = stub_request(
117
+ :post, "https://#{options[:uuid]}:x@bus.example.com/topics/widgets"
118
+ ).with(body: { type: anything, url: callback, timestamp: timestamp }, status: 200)
119
+ end
120
+
121
+ it 'sends the event' do
122
+ perform
123
+ expect(@stub).to have_been_requested
124
+ end
125
+
126
+ context 'with bad timestamp' do
127
+ let(:timestamp) { 'foo' }
128
+
129
+ it 'fails with non-numeric timestamp' do
130
+ expect { perform }.to raise_error
131
+ end
132
+ end
133
+ end
110
134
  end
111
135
 
112
136
  describe '#created' do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routemaster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Julien Letessier
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faraday
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ">="
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: net-http-persistent
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ">="
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ">="
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: wisper
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ">="
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ">="
60
53
  - !ruby/object:Gem::Version
@@ -90,33 +83,26 @@ files:
90
83
  homepage: http://github.com/HouseTrip/routemaster_client
91
84
  licenses:
92
85
  - MIT
86
+ metadata: {}
93
87
  post_install_message:
94
88
  rdoc_options: []
95
89
  require_paths:
96
90
  - "."
97
91
  required_ruby_version: !ruby/object:Gem::Requirement
98
- none: false
99
92
  requirements:
100
93
  - - ">="
101
94
  - !ruby/object:Gem::Version
102
95
  version: '0'
103
- segments:
104
- - 0
105
- hash: -2844023106456295461
106
96
  required_rubygems_version: !ruby/object:Gem::Requirement
107
- none: false
108
97
  requirements:
109
98
  - - ">="
110
99
  - !ruby/object:Gem::Version
111
100
  version: '0'
112
- segments:
113
- - 0
114
- hash: -2844023106456295461
115
101
  requirements: []
116
102
  rubyforge_project:
117
- rubygems_version: 1.8.23.2
103
+ rubygems_version: 2.4.5
118
104
  signing_key:
119
- specification_version: 3
105
+ specification_version: 4
120
106
  summary: Client API for the Routemaster event bus
121
107
  test_files:
122
108
  - spec/client_spec.rb