chillout 0.3.0 → 0.4.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.
- data/lib/chillout/check_result.rb +13 -0
- data/lib/chillout/client.rb +2 -1
- data/lib/chillout/config.rb +9 -1
- data/lib/chillout/dispatcher.rb +7 -0
- data/lib/chillout/http_client.rb +21 -0
- data/lib/chillout/railtie.rb +4 -0
- data/lib/chillout/server_side.rb +4 -0
- data/lib/chillout/tasks.rb +18 -0
- data/lib/chillout/version.rb +1 -1
- data/test/check_result_test.rb +45 -0
- data/test/integration/client_test.rb +33 -0
- data/test/integration/creations_monitor_rack_test.rb +0 -1
- data/test/test_helper.rb +1 -1
- metadata +10 -4
@@ -0,0 +1,13 @@
|
|
1
|
+
class CheckResult
|
2
|
+
def initialize(response)
|
3
|
+
@response = response
|
4
|
+
end
|
5
|
+
|
6
|
+
def successful?
|
7
|
+
@response.respond_to?(:code) && @response.code == "200"
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_problem_with_authorization?
|
11
|
+
@response.respond_to?(:code) && @response.code == "401"
|
12
|
+
end
|
13
|
+
end
|
data/lib/chillout/client.rb
CHANGED
@@ -6,13 +6,14 @@ require 'chillout/config'
|
|
6
6
|
require 'chillout/event_data_builder'
|
7
7
|
require 'chillout/prefixed_logger'
|
8
8
|
require 'chillout/worker'
|
9
|
+
require 'chillout/check_result'
|
9
10
|
require 'thread'
|
10
11
|
|
11
12
|
module Chillout
|
12
13
|
class Client
|
13
14
|
extend Forwardable
|
14
15
|
|
15
|
-
def_delegators :@dispatcher, :send_creations
|
16
|
+
def_delegators :@dispatcher, :send_creations, :check_api_connection
|
16
17
|
|
17
18
|
attr_reader :config
|
18
19
|
attr_reader :logger
|
data/lib/chillout/config.rb
CHANGED
@@ -6,7 +6,7 @@ module Chillout
|
|
6
6
|
class Config
|
7
7
|
|
8
8
|
DEFAULT_HOSTNAME = "api.chillout.io"
|
9
|
-
DEFAULT_PORT =
|
9
|
+
DEFAULT_PORT = 443
|
10
10
|
DEFAULT_NOTIFIER_NAME = "Chillout"
|
11
11
|
DEFAULT_NOTIFIER_URL = "http://github.com/chilloutio/chillout"
|
12
12
|
|
@@ -48,5 +48,13 @@ module Chillout
|
|
48
48
|
@authentication_password || api_key
|
49
49
|
end
|
50
50
|
|
51
|
+
def to_s
|
52
|
+
<<-eos
|
53
|
+
* hostname: #{hostname}
|
54
|
+
* port: #{port}
|
55
|
+
* ssl: #{ssl}
|
56
|
+
eos
|
57
|
+
end
|
58
|
+
|
51
59
|
end
|
52
60
|
end
|
data/lib/chillout/dispatcher.rb
CHANGED
@@ -13,5 +13,12 @@ module Chillout
|
|
13
13
|
rescue HttpClient::NotSent
|
14
14
|
raise SendCreationsFailed.new
|
15
15
|
end
|
16
|
+
|
17
|
+
def check_api_connection
|
18
|
+
response = @server_side.send_check
|
19
|
+
CheckResult.new(response)
|
20
|
+
rescue HttpClient::NotReceived => e
|
21
|
+
CheckResult.new(e)
|
22
|
+
end
|
16
23
|
end
|
17
24
|
end
|
data/lib/chillout/http_client.rb
CHANGED
@@ -10,6 +10,14 @@ module Chillout
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
class NotReceived < StandardError
|
14
|
+
attr_reader :original_exception
|
15
|
+
|
16
|
+
def initialize(original_exception)
|
17
|
+
@original_exception = original_exception
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
MEDIA_TYPE = "application/vnd.chillout.v1+json"
|
14
22
|
|
15
23
|
def initialize(config, logger)
|
@@ -32,5 +40,18 @@ module Chillout
|
|
32
40
|
raise NotSent.new(e)
|
33
41
|
end
|
34
42
|
|
43
|
+
def get(path)
|
44
|
+
http = Net::HTTP.new(@config.hostname, @config.port)
|
45
|
+
http.use_ssl = @config.ssl
|
46
|
+
request_spec = Net::HTTP::Get.new(path)
|
47
|
+
request_spec.content_type = MEDIA_TYPE
|
48
|
+
request_spec.basic_auth @config.authentication_user, @config.authentication_password
|
49
|
+
http.start do
|
50
|
+
http.request(request_spec)
|
51
|
+
end
|
52
|
+
rescue => e
|
53
|
+
raise NotReceived.new(e)
|
54
|
+
end
|
55
|
+
|
35
56
|
end
|
36
57
|
end
|
data/lib/chillout/railtie.rb
CHANGED
data/lib/chillout/server_side.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :chillout do
|
2
|
+
desc "Check chillout integration"
|
3
|
+
task :check do
|
4
|
+
Rails.initialize!
|
5
|
+
config = Rails.configuration.chillout
|
6
|
+
client = Chillout::Client.new(config[:secret], config.reject{|x| x == :secret})
|
7
|
+
check_result = client.check_api_connection
|
8
|
+
|
9
|
+
if check_result.successful?
|
10
|
+
puts "Chillout API available."
|
11
|
+
elsif check_result.has_problem_with_authorization?
|
12
|
+
puts "Chillout API available, but project couldn't authorize."
|
13
|
+
else
|
14
|
+
puts "Chillout API not available for given configuration:"
|
15
|
+
puts client.config.to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/chillout/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CheckResultTest < ChilloutTestCase
|
4
|
+
def test_successful_for_response_with_200_code
|
5
|
+
response = stub(code: "200")
|
6
|
+
check_result = CheckResult.new(response)
|
7
|
+
assert check_result.successful?
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_not_successful_for_response_with_other_code
|
11
|
+
response = stub(code: "304")
|
12
|
+
check_result = CheckResult.new(response)
|
13
|
+
refute check_result.successful?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_not_successful_for_response_that_dont_respond_to_code
|
17
|
+
response = stub
|
18
|
+
check_result = CheckResult.new(response)
|
19
|
+
refute check_result.successful?
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_dont_have_problem_with_authorization_for_response_with_200_code
|
23
|
+
response = stub(code: "200")
|
24
|
+
check_result = CheckResult.new(response)
|
25
|
+
refute check_result.has_problem_with_authorization?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_have_problem_with_authorization_for_response_with_401_code
|
29
|
+
response = stub(code: "401")
|
30
|
+
check_result = CheckResult.new(response)
|
31
|
+
assert check_result.has_problem_with_authorization?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_dont_have_problem_with_authorization_for_response_with_other_code
|
35
|
+
response = stub(code: "501")
|
36
|
+
check_result = CheckResult.new(response)
|
37
|
+
refute check_result.has_problem_with_authorization?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_dont_have_problem_with_authorization_for_response_that_dont_respond_to_code
|
41
|
+
response = stub
|
42
|
+
check_result = CheckResult.new(response)
|
43
|
+
refute check_result.has_problem_with_authorization?
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ClientIntegrationTest < ChilloutTestCase
|
4
|
+
def test_check_api_connection_with_200_ok_response
|
5
|
+
@_api_key = "xyz123"
|
6
|
+
url = api_url("check")
|
7
|
+
stub_request(:get, url).to_return(body: "OK", status: 200)
|
8
|
+
|
9
|
+
client = Chillout::Client.new(@_api_key)
|
10
|
+
check_result = client.check_api_connection
|
11
|
+
assert check_result.successful?, "Check was not successful"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_check_api_connection_with_other_response
|
15
|
+
@_api_key = "xyz123"
|
16
|
+
url = api_url("check")
|
17
|
+
stub_request(:get, url).to_return(body: "Not Found", status: 404)
|
18
|
+
|
19
|
+
client = Chillout::Client.new(@_api_key)
|
20
|
+
check_result = client.check_api_connection
|
21
|
+
refute check_result.successful?, "Check was successful"
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_check_api_connection_with_raised_exception_on_request
|
25
|
+
@_api_key = "xyz123"
|
26
|
+
url = api_url("check")
|
27
|
+
stub_request(:get, url).to_raise(StandardError)
|
28
|
+
|
29
|
+
client = Chillout::Client.new(@_api_key)
|
30
|
+
check_result = client.check_api_connection
|
31
|
+
refute check_result.successful?, "Check was successful"
|
32
|
+
end
|
33
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -38,7 +38,7 @@ class ChilloutTestCase < Test::Unit::TestCase
|
|
38
38
|
|
39
39
|
def api_url(resource_name)
|
40
40
|
raise "API KEY not set" unless @_api_key
|
41
|
-
"
|
41
|
+
"https://#{@_api_key}:#{@_api_key}@api.chillout.io/#{resource_name}"
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chillout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-03-
|
13
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- chillout.gemspec
|
126
126
|
- lib/chillout.rb
|
127
|
+
- lib/chillout/check_result.rb
|
127
128
|
- lib/chillout/client.rb
|
128
129
|
- lib/chillout/config.rb
|
129
130
|
- lib/chillout/creation_listener.rb
|
@@ -135,14 +136,17 @@ files:
|
|
135
136
|
- lib/chillout/prefixed_logger.rb
|
136
137
|
- lib/chillout/railtie.rb
|
137
138
|
- lib/chillout/server_side.rb
|
139
|
+
- lib/chillout/tasks.rb
|
138
140
|
- lib/chillout/version.rb
|
139
141
|
- lib/chillout/worker.rb
|
142
|
+
- test/check_result_test.rb
|
140
143
|
- test/client_test.rb
|
141
144
|
- test/config_test.rb
|
142
145
|
- test/creations_container_test.rb
|
143
146
|
- test/dispatcher_test.rb
|
144
147
|
- test/event_data_builder_test.rb
|
145
148
|
- test/http_client_test.rb
|
149
|
+
- test/integration/client_test.rb
|
146
150
|
- test/integration/creations_monitor_rack_test.rb
|
147
151
|
- test/middleware/creations_monitor_test.rb
|
148
152
|
- test/prefixed_logger_test.rb
|
@@ -163,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
167
|
version: '0'
|
164
168
|
segments:
|
165
169
|
- 0
|
166
|
-
hash:
|
170
|
+
hash: 1830182422873723913
|
167
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
172
|
none: false
|
169
173
|
requirements:
|
@@ -172,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
176
|
version: '0'
|
173
177
|
segments:
|
174
178
|
- 0
|
175
|
-
hash:
|
179
|
+
hash: 1830182422873723913
|
176
180
|
requirements: []
|
177
181
|
rubyforge_project:
|
178
182
|
rubygems_version: 1.8.25
|
@@ -180,12 +184,14 @@ signing_key:
|
|
180
184
|
specification_version: 3
|
181
185
|
summary: Chillout.io Ruby client
|
182
186
|
test_files:
|
187
|
+
- test/check_result_test.rb
|
183
188
|
- test/client_test.rb
|
184
189
|
- test/config_test.rb
|
185
190
|
- test/creations_container_test.rb
|
186
191
|
- test/dispatcher_test.rb
|
187
192
|
- test/event_data_builder_test.rb
|
188
193
|
- test/http_client_test.rb
|
194
|
+
- test/integration/client_test.rb
|
189
195
|
- test/integration/creations_monitor_rack_test.rb
|
190
196
|
- test/middleware/creations_monitor_test.rb
|
191
197
|
- test/prefixed_logger_test.rb
|