apill 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
  SHA1:
3
- metadata.gz: fc3893065627f21a38207df0f237ef67613d0fbe
4
- data.tar.gz: 9246e5feaba682181c5ad90e6f694351eabdf044
3
+ metadata.gz: 64584404ef059886afa2b62c3f93cec935403b70
4
+ data.tar.gz: 013020e5633701dad588d2ecfc560710e6c63052
5
5
  SHA512:
6
- metadata.gz: 053e326bc6fd650e546df55c939d50b8198de7d1589e66bd5dd0c755cc7ba7752e37cd792b6ff56f1730241a1da3efeeaa5f161d903140ab71081be0ec3b17ca
7
- data.tar.gz: 7ec2d27fc0da846a8c538fea7570cb63b2ddacc29da26d2e0acf65ae64595b7b5e12d06c42a1a179264d3183e416b27e461c0f1ca06720d29a62911b7634bd2b
6
+ metadata.gz: 1a221f3a0f1cf27bb149a08652107cfe1f0d4780d9fbcdae8dd357f4e54498822a7fb54b271e8d528ef1e888a8e6ad7710f770e78d5f750d3810d53093238344
7
+ data.tar.gz: 9984076eef45d1ede48945647204bda066214edf7dda7196906c8f07a7ef88cb8acc81601978be65ff8f875961273e0bba879726f2d13666315c25eecbc462c0
@@ -5,7 +5,7 @@ class AcceptHeader
5
5
 
6
6
  def initialize(application:, header:)
7
7
  self.application = application
8
- self.raw_accept_header = header
8
+ self.raw_accept_header = header || ''
9
9
  end
10
10
 
11
11
  def version
@@ -13,10 +13,26 @@ module GenericMatcher
13
13
  end
14
14
 
15
15
  def matches?(request)
16
- raw_accept_header = request.headers['Accept'] || request.params['accept']
16
+ self.accept_header = get_accept_header(raw_header_from_headers: request.headers['Accept'],
17
+ raw_header_from_params: request.params['accept'])
18
+ end
19
+
20
+ private
21
+
22
+ def get_accept_header(raw_header_from_headers:, raw_header_from_params:)
23
+ return accept_header_from_header if accept_header_from_header(raw_header_from_headers).valid? || raw_header_from_params.nil?
24
+
25
+ accept_header_from_params(raw_header_from_params)
26
+ end
27
+
28
+ def accept_header_from_header(raw_header_from_headers='')
29
+ @accept_header_from_header ||= Apill::AcceptHeader.new(application: application,
30
+ header: raw_header_from_headers)
31
+ end
17
32
 
18
- self.accept_header = Apill::AcceptHeader.new(application: application,
19
- header: raw_accept_header)
33
+ def accept_header_from_params(raw_header_from_params='')
34
+ @accept_header_from_params ||= Apill::AcceptHeader.new(application: application,
35
+ header: raw_header_from_params)
20
36
  end
21
37
  end
22
38
  end
data/lib/apill/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apill
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -17,6 +17,18 @@ describe AcceptHeader do
17
17
  expect(header).not_to be_valid
18
18
  end
19
19
 
20
+ it 'does not validate an accept header if it is not passed in' do
21
+ header = AcceptHeader.new(application: '',
22
+ header: '')
23
+
24
+ expect(header).not_to be_valid
25
+
26
+ header = AcceptHeader.new(application: '',
27
+ header: nil)
28
+
29
+ expect(header).not_to be_valid
30
+ end
31
+
20
32
  it 'does not validate an accept header without an application in the header' do
21
33
  header = AcceptHeader.new(application: 'matrix',
22
34
  header: 'application/vnd.+zion;version=1.0.0')
@@ -7,6 +7,7 @@ module Matchers
7
7
  describe AcceptHeaderMatcher do
8
8
  it 'matches if the subdomain is API and the accept header is valid' do
9
9
  request = OpenStruct.new(headers: { 'Accept' => 'application/vnd.matrix+zion;version=1.0.0' },
10
+ params: {},
10
11
  subdomains: [ 'api' ])
11
12
 
12
13
  matcher = AcceptHeaderMatcher.new(application: 'matrix')
@@ -24,8 +25,42 @@ describe AcceptHeaderMatcher do
24
25
  expect(matcher.matches?(request)).to be_truthy
25
26
  end
26
27
 
28
+ it 'matches the header accept header if the subdomain is API and the accept header is passed both as a valid header and as a parameter' do
29
+ request = OpenStruct.new(headers: { 'Accept' => 'application/vnd.matrix+zion;version=1.0.0' },
30
+ params: { 'accept' => 'application/vnd.matrix+zion;version=2.0.0' },
31
+ subdomains: [ 'api' ])
32
+
33
+ matcher = AcceptHeaderMatcher.new(application: 'matrix')
34
+ matcher.matches?(request)
35
+
36
+ expect(matcher.accept_header.version).to eql '1.0.0'
37
+ end
38
+
39
+ it "matches the parameter's accept header if the subdomain is API and the accept header is passed both as an invalid header as well as as a parameter" do
40
+ request = OpenStruct.new(headers: { 'Accept' => 'application/vndmatrix+zion;version=1.0.0' },
41
+ params: { 'accept' => 'application/vnd.matrix+zion;version=2.0.0' },
42
+ subdomains: [ 'api' ])
43
+
44
+ matcher = AcceptHeaderMatcher.new(application: 'matrix')
45
+ matcher.matches?(request)
46
+
47
+ expect(matcher.accept_header.version).to eql '2.0.0'
48
+ end
49
+
50
+ it "matches the parameter's accept header if the subdomain is API and the accept header is passed both as an invalid header as well as as a parameter" do
51
+ request = OpenStruct.new(headers: { 'Accept' => 'application/vndmatrix+zion;version=1.0.0' },
52
+ params: {},
53
+ subdomains: [ 'api' ])
54
+
55
+ matcher = AcceptHeaderMatcher.new(application: 'matrix')
56
+ matcher.matches?(request)
57
+
58
+ expect(matcher.accept_header.raw_accept_header).to eql 'application/vndmatrix+zion;version=1.0.0'
59
+ end
60
+
27
61
  it 'does not match if the subdomain is not API but the accept header is valid' do
28
62
  request = OpenStruct.new(headers: { 'Accept' => 'application/vnd.matrix+zion' },
63
+ params: {},
29
64
  subdomains: [ 'not-api' ])
30
65
 
31
66
  matcher = AcceptHeaderMatcher.new(application: 'matrix')
@@ -35,6 +70,7 @@ describe AcceptHeaderMatcher do
35
70
 
36
71
  it 'does not match if the subdomain is API but the accept header is invalid' do
37
72
  request = OpenStruct.new(headers: { 'Accept' => 'application/vnd.' },
73
+ params: {},
38
74
  subdomains: [ 'api' ])
39
75
 
40
76
  matcher = AcceptHeaderMatcher.new(application: 'matrix')
@@ -44,6 +80,7 @@ describe AcceptHeaderMatcher do
44
80
 
45
81
  it 'does not match if neither the subdomain is API nor the accept header is valid' do
46
82
  request = OpenStruct.new(headers: { 'Accept' => 'application/vnd.' },
83
+ params: {},
47
84
  subdomains: [ 'not-api' ])
48
85
 
49
86
  matcher = AcceptHeaderMatcher.new(application: 'matrix')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apill
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
  - jfelchner