routemaster-client 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .bundle/
2
+ pkg/
2
3
  tmp
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- routemaster-client (0.0.3)
5
- faraday
4
+ routemaster-client (1.0.0)
5
+ faraday (>= 0.9.0)
6
6
  net-http-persistent
7
7
  wisper (>= 1.4.0)
8
8
 
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 = RoutemasterClient.new(url: 'https://bus.example.com', uuid: 'john-doe')
33
+ client = Routemaster::Client.new(url: 'https://bus.example.com', uuid: 'john-doe')
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
- RoutemasterClient.new(url: 'https://bus.example.com', uuid: 'john-doe', timeout: 2)
39
+ Routemaster::Client.new(url: 'https://bus.example.com', uuid: 'john-doe', timeout: 2)
40
40
  ```
41
41
 
42
42
 
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  class Client
3
- VERSION = '0.0.3'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -14,8 +14,10 @@ module Routemaster
14
14
  _assert (options[:uuid] =~ /^[a-z0-9_-]{1,64}$/), 'uuid should be alpha'
15
15
  _assert_valid_timeout(@_timeout)
16
16
 
17
- _conn.get('/pulse').tap do |response|
18
- raise 'cannot connect to bus' unless response.success?
17
+ unless options[:lazy]
18
+ _conn.get('/pulse').tap do |response|
19
+ raise 'cannot connect to bus' unless response.success?
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -47,10 +49,9 @@ module Routemaster
47
49
  options[:topics].each { |t| _assert_valid_topic(t) }
48
50
  _assert_valid_url(options[:callback])
49
51
 
50
- data = options.to_json
51
52
  response = _post('/subscription') do |r|
52
53
  r.headers['Content-Type'] = 'application/json'
53
- r.body = data
54
+ r.body = options.to_json
54
55
  end
55
56
  # $stderr.puts response.status
56
57
  unless response.success?
@@ -82,10 +83,10 @@ module Routemaster
82
83
  def _send_event(event, topic, callback)
83
84
  _assert_valid_url(callback)
84
85
  _assert_valid_topic(topic)
85
- data = { type: event, url: callback }.to_json
86
+ data = { type: event, url: callback }
86
87
  response = _post("/topics/#{topic}") do |r|
87
88
  r.headers['Content-Type'] = 'application/json'
88
- r.body = data
89
+ r.body = data.to_json
89
90
  end
90
91
  fail "event rejected (#{response.status})" unless response.success?
91
92
  end
@@ -107,9 +108,12 @@ module Routemaster
107
108
 
108
109
  def _conn
109
110
  @_conn ||= Faraday.new(@_url) do |f|
110
- f.use Faraday::Request::BasicAuthentication, @_uuid, 'x'
111
+ f.request :retry, max: 2, interval: 100e-3, backoff_factor: 2
112
+ f.request :basic_auth, @_uuid, 'x'
111
113
  f.adapter :net_http_persistent
112
- f.options[:timeout] = @_timeout
114
+
115
+ f.options.timeout = @_timeout
116
+ f.options.open_timeout = @_timeout
113
117
  end
114
118
  end
115
119
  end
@@ -16,7 +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_runtime_dependency 'faraday'
19
+ spec.add_runtime_dependency 'faraday', '>= 0.9.0'
20
20
  spec.add_runtime_dependency 'net-http-persistent'
21
21
  spec.add_runtime_dependency 'wisper', '>= 1.4.0'
22
22
  end
@@ -33,9 +33,20 @@ describe Routemaster::Client do
33
33
  expect { subject }.to raise_error(ArgumentError)
34
34
  end
35
35
 
36
- it 'fails it it cannot connect' do
37
- stub_request(:any, %r{^https://#{options[:uuid]}:x@bus.example.com}).to_raise(Faraday::ConnectionFailed)
38
- expect { subject }.to raise_error
36
+ context 'when connection fails' do
37
+ before do
38
+ stub_request(:any, %r{^https://#{options[:uuid]}:x@bus.example.com}).
39
+ to_raise(Faraday::ConnectionFailed)
40
+ end
41
+
42
+ it 'fails' do
43
+ expect { subject }.to raise_error
44
+ end
45
+
46
+ it 'passes if :lazy' do
47
+ options[:lazy] = true
48
+ expect { subject }.not_to raise_error
49
+ end
39
50
  end
40
51
 
41
52
  it 'fails if it does not get a successful heartbeat from the app' do
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.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-17 00:00:00.000000000 Z
12
+ date: 2014-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 0.9.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: net-http-persistent
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -83,8 +83,8 @@ files:
83
83
  - routemaster/client/openssl.rb
84
84
  - routemaster/client/version.rb
85
85
  - routemaster/receiver.rb
86
+ - spec/client_spec.rb
86
87
  - spec/receiver_spec.rb
87
- - spec/routemaster/client_spec.rb
88
88
  - spec/spec_helper.rb
89
89
  - spec/support/rack_test.rb
90
90
  homepage: http://github.com/HouseTrip/routemaster_client
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: -2540830957177487143
105
+ hash: -2844023106456295461
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  segments:
113
113
  - 0
114
- hash: -2540830957177487143
114
+ hash: -2844023106456295461
115
115
  requirements: []
116
116
  rubyforge_project:
117
117
  rubygems_version: 1.8.23.2
@@ -119,7 +119,7 @@ signing_key:
119
119
  specification_version: 3
120
120
  summary: Client API for the Routemaster event bus
121
121
  test_files:
122
+ - spec/client_spec.rb
122
123
  - spec/receiver_spec.rb
123
- - spec/routemaster/client_spec.rb
124
124
  - spec/spec_helper.rb
125
125
  - spec/support/rack_test.rb