hyperion_http 0.1.4 → 0.1.5

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: d9d372cf4d4619f6f072bc380c17063ecb5fe855
4
- data.tar.gz: 26f3f857b2e7c95172957dbaed57c63daa4528a7
3
+ metadata.gz: c24c3452a5f16a5347b6d0ab930e01744a27e9fc
4
+ data.tar.gz: 80d605302f41e1872f745cab3563657e183cdfb8
5
5
  SHA512:
6
- metadata.gz: f38a45cf7bf55934c47dfd23bb1516fbd489751f32a74ed78bc3171e1e68b7ee7fa38eb0d856ee0809a816aed593538ebb1c092c79367e4251a3423e18730145
7
- data.tar.gz: a80a5552f4a2419ab751806a4f6b3aeb4f26790ee2390bcbbb52906442c00019f639b86d8bcdc74505162225e91aa2edec1bb8e96651ca04817cc82364741951
6
+ metadata.gz: b83b365370c05091223d03c430aa2d998b629313644ece52dec7f95d0fa7e6c13e32e2299bb97b2dadf3f8499aa8cbe80d59c64225301b094a4cde5bb735922a
7
+ data.tar.gz: 66b8e4a08fbd601368020ecc199d7be76616316cb0b36dbc38aa7839ea5ba2be7f65ccad2673b7818c4ae06ae1856f22a103cbc13aa00abbe13927dbc3b1e0c9
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hyperion.gemspec
4
4
  gemspec
5
-
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency 'oj', '~> 2.12'
32
32
  spec.add_runtime_dependency 'typhoeus', '~> 0.7'
33
33
  spec.add_runtime_dependency 'mimic', '~> 0.4.3'
34
+ spec.add_runtime_dependency 'logatron'
34
35
  end
@@ -1,54 +1,29 @@
1
+ require 'logatron/logatron'
2
+
1
3
  class Hyperion
2
4
  module Logger
3
- class << self
4
- attr_accessor :level
5
- end
6
5
 
7
6
  def logger
8
- rails_logger_available? ? Rails.logger : default_logger
7
+ Logatron
9
8
  end
10
9
 
11
10
  def with_request_logging(route, uri, headers)
12
- log_request_start(route, uri, headers)
13
- start = Time.now
14
- begin
11
+ Logatron.log(msg: "Hyperion #{route.method.to_s.upcase} #{uri}") do |logger|
12
+ log_headers(headers, logger)
15
13
  yield
16
- ensure
17
- stop = Time.now
18
- log_request_end(((stop - start) * 1000).round)
19
14
  end
20
15
  end
21
16
 
22
17
  def log_stub(rule)
23
18
  mr = rule.mimic_route
24
19
  logger.debug "Stubbed #{mr.method.to_s.upcase} #{mr.path}"
25
- log_headers(rule.headers)
20
+ log_headers(rule.headers, logger)
26
21
  end
27
22
 
28
23
  private
29
24
 
30
- def log_request_start(route, uri, headers)
31
- logger.debug "Requesting #{route.method.to_s.upcase} #{uri}"
32
- log_headers(headers)
33
- end
34
-
35
- def log_request_end(ms)
36
- logger.debug "Completed in #{ms}ms"
37
- logger.debug ''
38
- end
39
-
40
- def rails_logger_available?
41
- Kernel.const_defined?(:Rails) && !Rails.logger.nil?
42
- end
43
-
44
- def default_logger
45
- logger = ::Logger.new($stdout)
46
- logger.level = Hyperion::Logger.level || ::Logger::DEBUG
47
- logger
48
- end
49
-
50
- def log_headers(headers)
51
- headers.each_pair { |k, v| logger.debug " #{k}: #{v}" unless k == 'Expect' }
25
+ def log_headers(headers, logger)
26
+ headers.each_pair { |k, v| logger.info " #{k}: #{v}" unless k == 'Expect' }
52
27
  end
53
28
  end
54
29
  end
@@ -1,3 +1,3 @@
1
1
  class Hyperion
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -57,7 +57,8 @@ class Hyperion
57
57
  mode: :compat,
58
58
  time_format: :xmlschema, # xmlschema == iso8601
59
59
  use_to_json: false,
60
- second_precision: 3
60
+ second_precision: 3,
61
+ bigdecimal_load: :float
61
62
  }
62
63
  end
63
64
 
@@ -1,11 +1,12 @@
1
1
  require 'hyperion/formats'
2
+ require 'logatron/logatron'
2
3
 
3
4
  class Hyperion
4
5
  module Headers
5
6
  # constructs and destructures HTTP headers
6
7
 
7
8
  def route_headers(route)
8
- headers = {}
9
+ headers = Logatron.http_headers
9
10
  rd = route.response_descriptor
10
11
  pd = route.payload_descriptor
11
12
  headers['Expect'] = nil # this overrides default libcurl behavior.
@@ -1,9 +1,11 @@
1
1
  require 'hyperion'
2
2
  require 'hyperion/headers'
3
+ require 'abstractivator/trees/tree_compare'
3
4
 
4
5
  class Hyperion
5
6
  describe Headers do
6
7
  include Headers
8
+ include Abstractivator::Trees
7
9
 
8
10
  before :each do
9
11
  Hyperion.configure do |config|
@@ -22,6 +24,10 @@ class Hyperion
22
24
  headers = route_headers(RestRoute.new(:get, uri, ResponseDescriptor.new('ttt', 999, :json), PayloadDescriptor.new(:json)))
23
25
  expect(headers['Content-Type']).to eql 'application/json'
24
26
  end
27
+ it 'merges the logatron headers' do
28
+ headers = route_headers(RestRoute.new(:get, uri, ResponseDescriptor.new('ttt', 999, :json)))
29
+ expect(tree_compare(headers, Logatron.http_headers)).to eql []
30
+ end
25
31
  end
26
32
 
27
33
  describe '#content_type_for' do
@@ -29,23 +29,28 @@ describe Hyperion::Logger do
29
29
  it 'respects the log level' do
30
30
  output = StringIO.new
31
31
  with_stdout(output) do
32
- Hyperion::Logger.level = Logger::ERROR
32
+ Logatron.level = Logatron::ERROR
33
33
  logger.debug 'xyzzy'
34
34
  logger.error 'qwerty'
35
- Hyperion::Logger.level = Logger::DEBUG
35
+ Logatron.level = Logatron::DEBUG
36
36
  end
37
37
  output_str = output.string
38
38
  expect(output_str).to include 'qwert'
39
39
  expect(output_str).to_not include 'xyzzy'
40
40
  end
41
41
 
42
- def with_stdout(tmp_stdout)
43
- old = $stdout
44
- $stdout = tmp_stdout
42
+ def with_stdout(io)
43
+ set_log_io(io)
45
44
  begin
46
45
  yield
47
46
  ensure
48
- $stdout = old
47
+ set_log_io($stdout)
48
+ end
49
+ end
50
+
51
+ def set_log_io(io)
52
+ Logatron.configure do |c|
53
+ c.logger = Logger.new(io)
49
54
  end
50
55
  end
51
56
 
@@ -15,16 +15,16 @@ describe Hyperion do
15
15
  body = 'Ventura'
16
16
  additional_headers = {'From' => 'dev@indigobio.com'}
17
17
 
18
- expected_headers = {
19
- 'Accept' => "application/vnd.indigobio-ascent.#{rd.type}-v#{rd.version}+#{rd.format}",
20
- 'Content-Type' => 'application/x-protobuf',
21
- 'From' => 'dev@indigobio.com',
22
- 'Expect' => nil
23
- }
18
+ expected_headers = Logatron.http_headers.merge(
19
+ 'Accept' => "application/vnd.indigobio-ascent.#{rd.type}-v#{rd.version}+#{rd.format}",
20
+ 'Content-Type' => 'application/x-protobuf',
21
+ 'From' => 'dev@indigobio.com',
22
+ 'Expect' => nil
23
+ )
24
24
 
25
25
  expect(Hyperion::Typho).to receive(:request).
26
- with(uri, {method: method, headers: expected_headers, body: 'Ventura'}).
27
- and_return(make_typho_response(200, write({'foo' => 'bar'}, :json)))
26
+ with(uri, {method: method, headers: expected_headers, body: 'Ventura'}).
27
+ and_return(make_typho_response(200, write({'foo' => 'bar'}, :json)))
28
28
 
29
29
  result = Hyperion.request(route, body, additional_headers)
30
30
  expect(result).to be_a HyperionResult
@@ -40,11 +40,12 @@ describe Hyperion do
40
40
  let!(:rd){ResponseDescriptor.new('data_type', 1, :json)}
41
41
  let!(:pd){PayloadDescriptor.new(:json)}
42
42
  let!(:route){RestRoute.new(method, uri, rd, pd)}
43
- let!(:expected_headers){{
43
+ let!(:expected_headers) do
44
+ Logatron.http_headers.merge(
44
45
  'Accept' => "application/vnd.indigobio-ascent.#{rd.type}-v#{rd.version}+#{rd.format}",
45
46
  'Content-Type' => 'application/json',
46
- 'Expect' => nil
47
- }}
47
+ 'Expect' => nil)
48
+ end
48
49
  it 'deserializes the response' do
49
50
  allow(Hyperion::Typho).to receive(:request).and_return(make_typho_response(200, '{"a":"b"}'))
50
51
  result = Hyperion.request(route)
@@ -52,15 +53,15 @@ describe Hyperion do
52
53
  end
53
54
  it 'serializes the payload' do
54
55
  expect(Hyperion::Typho).to receive(:request).
55
- with(uri, {method: method, headers: expected_headers, body: '{"c":"d"}'}).
56
- and_return(make_typho_response(200, write({}, :json)))
56
+ with(uri, {method: method, headers: expected_headers, body: '{"c":"d"}'}).
57
+ and_return(make_typho_response(200, write({}, :json)))
57
58
  Hyperion.request(route, {'c' => 'd'})
58
59
  end
59
60
  it 'deserializes 400-level errors to ClientErrorResponse' do
60
61
  client_error = ClientErrorResponse.new('oops', [], ClientErrorCode::MISSING)
61
62
  allow(Hyperion::Typho).to receive(:request).
62
- with(uri, {method: method, headers: expected_headers, body: '{"c":"d"}'}).
63
- and_return(make_typho_response(400, write(client_error.as_json, :json)))
63
+ with(uri, {method: method, headers: expected_headers, body: '{"c":"d"}'}).
64
+ and_return(make_typho_response(400, write(client_error.as_json, :json)))
64
65
  result = Hyperion.request(route, {'c' => 'd'})
65
66
  expect(result.body).to be_a ClientErrorResponse
66
67
  expect(result.body.message).to eql 'oops'
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'rspec'
2
2
  require 'json_spec'
3
3
  require 'hyperion'
4
+ require 'logatron/logatron'
@@ -1,5 +1,13 @@
1
+ require 'logatron/logatron'
2
+
1
3
  RSpec.configure do |config|
2
4
  config.mock_with :rspec do |mocks|
3
5
  mocks.verify_partial_doubles = true
4
6
  end
5
7
  end
8
+
9
+ Logatron.configure do |c|
10
+ c.logger = Logger.new($stdout)
11
+ c.level = Logatron::DEBUG
12
+ c.transformer = proc {|x| x[:body]}
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperion_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Indigo BioAutomation, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-11 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.4.3
181
+ - !ruby/object:Gem::Dependency
182
+ name: logatron
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  description: Ruby REST client for internal service architecture
182
196
  email:
183
197
  - pwinton@indigobio.com
@@ -230,12 +244,12 @@ files:
230
244
  - spec/lib/hyperion/formats_spec.rb
231
245
  - spec/lib/hyperion/headers_spec.rb
232
246
  - spec/lib/hyperion/logger_spec.rb
247
+ - spec/lib/hyperion/requestor_spec.rb
233
248
  - spec/lib/hyperion/test_spec.rb
234
249
  - spec/lib/hyperion/types/client_error_response_spec.rb
235
250
  - spec/lib/hyperion/types/hyperion_result_spec.rb
236
251
  - spec/lib/hyperion/types/hyperion_uri_spec.rb
237
252
  - spec/lib/hyperion_spec.rb
238
- - spec/lib/superion_spec.rb
239
253
  - spec/lib/types_spec.rb
240
254
  - spec/spec_helper.rb
241
255
  - spec/support/core_helpers.rb
@@ -268,12 +282,12 @@ test_files:
268
282
  - spec/lib/hyperion/formats_spec.rb
269
283
  - spec/lib/hyperion/headers_spec.rb
270
284
  - spec/lib/hyperion/logger_spec.rb
285
+ - spec/lib/hyperion/requestor_spec.rb
271
286
  - spec/lib/hyperion/test_spec.rb
272
287
  - spec/lib/hyperion/types/client_error_response_spec.rb
273
288
  - spec/lib/hyperion/types/hyperion_result_spec.rb
274
289
  - spec/lib/hyperion/types/hyperion_uri_spec.rb
275
290
  - spec/lib/hyperion_spec.rb
276
- - spec/lib/superion_spec.rb
277
291
  - spec/lib/types_spec.rb
278
292
  - spec/spec_helper.rb
279
293
  - spec/support/core_helpers.rb