apiphobic-middleware 1.2.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5fc848c052df27e6f94826ab6401718c276e1d24f1055b3eda185591cee5362
4
- data.tar.gz: 9a20b4f0002aa360ec928e7cc501721b85b75afd28463c629e6f78be4c942b89
3
+ metadata.gz: 38f3144a28a7e5930de852652b7c9a41687dbc2fb2fd92b85e46c1eaa3bd68e5
4
+ data.tar.gz: 0d936500afb0ef3efd63978fbcf7bfc00bccfcfd7f6a2228cddcfa83e7dc3a7a
5
5
  SHA512:
6
- metadata.gz: 9a079597f41bebd6ada817d9470b974f86f3e66678bc2a342bfe6e3bd1adcf8333cc9e635456aa6a6f54637bcb7a7e8582bd8e39f5f34517854a18bcc1b4a713
7
- data.tar.gz: 78bcf6c812b9017d35172a3dc0e494311227b0f8df6321bbc3e9b6afa7fdfdf8ea561f8a8f6d4b46014be9c249095cdd342c9e128549a486fda07a9f6b542d57
6
+ metadata.gz: efcb56a6173466a943720ae94eb095ece3f6c9aab8dffca330601976f95d820427d162ff6ffcdf7a840ca667ea2d25b5584c9561107665b1b8f74f32f2fec6dd
7
+ data.tar.gz: b817f214a07895839909625b838d6007d67a8bbf2f01537b9ccdf9359d4ac131cecf0459311d316aea865dd4a187914082db3574db0142d4cf0a4c5b259be330
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -22,8 +22,8 @@ class Version
22
22
  self.version_constraint = version_constraint
23
23
  end
24
24
 
25
- def matches?(request)
26
- self.request = request
25
+ def matches?(raw_request)
26
+ self.request = ::Apiphobic::Requests::AcceptHeader.resolve(raw_request)
27
27
  self.accept_header = ::Apiphobic::AcceptHeader.new(request.accept_header,
28
28
  application_name: application_name)
29
29
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apiphobic
4
4
  module Middleware
5
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
@@ -13,6 +13,12 @@ class AcceptHeader
13
13
  self.request = request
14
14
  end
15
15
 
16
+ def self.resolve(request)
17
+ return request if request.class == self
18
+
19
+ new(request)
20
+ end
21
+
16
22
  def accept_header
17
23
  if accept_header_from_header.valid? || accept_header_from_params.invalid?
18
24
  raw_accept_header_from_header
@@ -21,7 +21,7 @@ class TransformJsonApi
21
21
 
22
22
  if has_content? && json?
23
23
  request[content_parameter] = request_body_with_underscored_json_keys
24
- request['CONTENT_LENGTH'] = content_length
24
+ request['CONTENT_LENGTH'] = content_length.to_s
25
25
  end
26
26
 
27
27
  request
@@ -67,7 +67,7 @@ class TransformJsonApi
67
67
  end
68
68
 
69
69
  def underscored_request_json
70
- JSON.dump(underscored_request_hash)
70
+ @underscored_request_json ||= JSON.dump(underscored_request_hash)
71
71
  end
72
72
 
73
73
  def underscored_request_hash
@@ -30,6 +30,14 @@ class TransformJsonApi
30
30
  end
31
31
 
32
32
  def transformed_body
33
+ if content_parameter == 'rack.input'
34
+ StringIO.new(transformed_json_body)
35
+ else
36
+ transformed_json_body
37
+ end
38
+ end
39
+
40
+ def transformed_json_body
33
41
  return request_body if request_body == '' || request_body.nil?
34
42
 
35
43
  relationships = request_hash.dig('data', 'relationships') || {}
@@ -51,11 +59,13 @@ class TransformJsonApi
51
59
  end
52
60
 
53
61
  def request_body
54
- if headers['rack.input']
55
- headers['rack.input'].read
56
- else
57
- headers['RACK_INPUT'].to_s
58
- end
62
+ @request_body ||= if headers['rack.input']
63
+ headers['rack.input'].read
64
+ else
65
+ headers['RACK_INPUT'].to_s
66
+ end
67
+ ensure
68
+ headers['rack.input']&.rewind
59
69
  end
60
70
  end
61
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiphobic-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,7 +31,7 @@ cert_chain:
31
31
  Y2GAoHKstmfIVhc4XHOPpmTd2o/C29O9oaRgjrkfQEhF/KvJ/PhoV5hvokzsCyI5
32
32
  iUeXPfvrGD/itYIBCgk+fnzyQQ4QtE5hTQaWQ3o2
33
33
  -----END CERTIFICATE-----
34
- date: 2018-05-04 00:00:00.000000000 Z
34
+ date: 2018-05-21 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: apple_core
metadata.gz.sig CHANGED
Binary file