opinionated_http 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70883413762ba2277b74061e20f9fd5faa73fccee8a762595a40793a93ed2689
4
- data.tar.gz: 45bf3291006a3577a29f5fd603ad27c34b1d6948c54e67f71efb20862c0af613
3
+ metadata.gz: cbd58bf8946567e33344521051ead26e88ad8d6d083f820c1528ac644c6ac7ae
4
+ data.tar.gz: 4dd8282607215174ef3b261f262e9bbbd99396a0f5992df1a6dc652bc58b4008
5
5
  SHA512:
6
- metadata.gz: eec7f0a191186d29a970284e04dc571a2c8329587a414fa41576852e59d08503928594e14fc8e65f9ebea1570f90e15ad5e878a7b26259eae4adc605e7e9063f
7
- data.tar.gz: ac1ce6b6f65d720cf7ddac4d93621c608f609ad1e113ead056e710e0cfe37df70792459940cdd3ca9effe0d8a123e60df11e89cf2a713ab7855c1148ea29e86d
6
+ metadata.gz: 37c91ccf2069493d1cea1243d5673d3fbbd7e7caed6542eb3b61678e1f4f2f34fd964b5521b17042f297482f42921983a5019c788b5b3de10d6739a1d9569239
7
+ data.tar.gz: fd93c9925f575faabc06809cd0ed665469cd8e2531c91b9a96446e00b64fb1be1b50c3a065378ea73697a0c42f563a352c234dc42f9b8ac309e5413e2accc253
@@ -147,14 +147,8 @@ module OpinionatedHTTP
147
147
  http_method = request.method.upcase
148
148
  response =
149
149
  begin
150
- payload = {}
151
- if logger.trace?
152
- # payload[:parameters] = parameters
153
- payload[:path] = request.path
154
- end
155
- message = "HTTP #{http_method}: #{action}" if logger.debug?
156
-
157
- logger.benchmark_info(message: message, metric: "#{metric_prefix}/#{action}", payload: payload) do
150
+ message = "HTTP #{http_method}: #{action} #{request.path}"
151
+ logger.benchmark_info(message: message, metric: "#{metric_prefix}/#{action}") do
158
152
  driver.request(request)
159
153
  end
160
154
  rescue StandardError => e
@@ -51,12 +51,11 @@ module OpinionatedHTTP
51
51
  private
52
52
 
53
53
  def format_body
54
- return if body.nil?
55
-
56
54
  case format
57
55
  when :json
58
56
  headers["Content-Type"] = "application/json"
59
- body.to_json unless body.is_a?(String) || body.nil?
57
+ headers["Accept"] = "application/json"
58
+ body.is_a?(String) || body.nil? ? body : body.to_json
60
59
  when nil
61
60
  body
62
61
  else
@@ -25,6 +25,10 @@ module OpinionatedHTTP
25
25
  def body!
26
26
  return body if success?
27
27
 
28
+ exception!
29
+ end
30
+
31
+ def exception!
28
32
  error_message = "HTTP #{verb.upcase}: #{action} Failure: (#{code}) #{message}"
29
33
  logger.error(message: error_message, metric: "#{metric_prefix}/exception", payload: {body: body})
30
34
  raise(error_class, error_message)
@@ -1,3 +1,3 @@
1
1
  module OpinionatedHTTP
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
data/test/request_test.rb CHANGED
@@ -25,7 +25,8 @@ class RequestTest < Minitest::Test
25
25
  req = OpinionatedHTTP::Request.new(action: action, path: path, verb: post_verb, format: :json, body: json_request).http_request
26
26
 
27
27
  assert_equal json_request.to_json, req.body
28
- assert_equal "application/json", req["Content-Type"]
28
+ assert_equal "application/json", req["content-type"], -> { req.to_hash.ai }
29
+ assert_equal "application/json", req["accept"], -> { req.to_hash.ai }
29
30
  end
30
31
 
31
32
  it "returns a request with supplied headers" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opinionated_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: persistent_http