apill 2.7.1 → 2.8.0

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: 19fd91487d72b0958cf639a9eaa44435a0519f20
4
- data.tar.gz: fbd7296da9eee162e7eade29bcdb39fd91521546
3
+ metadata.gz: ac63789c44dc822312c6aebd4c12726fcd4d4810
4
+ data.tar.gz: eb5660a665df63b8e1149685cdd6e2d92f455298
5
5
  SHA512:
6
- metadata.gz: 892892befdf4a720ca7fedbb59b1934607eb0aa2408d577d68eb60f2eead7bf32554852d66074b2a40e5056c965db1910bc34f826e85c0b29c7a4605b9402261
7
- data.tar.gz: 8aff948b17818e441c8163bef2d4d3eeb9116b8041099a9e538a6465817bc71cf8d0062d431a6fba23ba539a788bb1e2d1e5a07fd508fa9872c6a3e41f514ad7
6
+ metadata.gz: 9e8f788f49733b4ac51f389c2041dd6bd7ec2013c000e05fffe721e76de87723aaac8af26485c106bdfa8fdb03eb13258461fc13a93cedf5a26b1015ac785947
7
+ data.tar.gz: 15c818f83a0e729bb28b4b809cc135a17de8a21ce88f280bbfaaad09e4000ad4d1a7f339737af7aaca4dfdf17f5d67e1466119105c8577bde6325a3b04b73aa8
@@ -1,4 +1,5 @@
1
1
  require 'apill/configuration'
2
+ require 'apill/parameters'
2
3
  require 'apill/matchers/subdomain_matcher'
3
4
  require 'apill/matchers/accept_header_matcher'
4
5
  require 'apill/responses/invalid_api_request_response'
@@ -20,6 +21,8 @@ class ApiRequest
20
21
  if !subdomain_matcher.matches_api_subdomain? ||
21
22
  Matchers::AcceptHeaderMatcher.new.matches?(env)
22
23
 
24
+ env['QUERY_STRING'] = Parameters.process(env['QUERY_STRING'])
25
+
23
26
  @app.call(env)
24
27
  else
25
28
  Responses::InvalidApiRequestResponse.call(env)
@@ -40,10 +40,10 @@ module Pageable
40
40
 
41
41
  def pagination_data
42
42
  {
43
- total_pages: @paginated_resource.total_pages,
44
- current_page: @paginated_resource.current_page,
45
- previous_page: @paginated_resource.prev_page,
46
- next_page: @paginated_resource.next_page,
43
+ 'total-pages' => @paginated_resource.total_pages,
44
+ 'current-page' => @paginated_resource.current_page,
45
+ 'previous-page' => @paginated_resource.prev_page,
46
+ 'next-page' => @paginated_resource.next_page,
47
47
  }
48
48
  end
49
49
  end
@@ -0,0 +1,21 @@
1
+ module Apill
2
+ class Parameters
3
+ attr_accessor :query_string
4
+
5
+ def initialize(query_string)
6
+ self.query_string = query_string
7
+ end
8
+
9
+ def self.process(query_string)
10
+ new(query_string).process
11
+ end
12
+
13
+ def process
14
+ return query_string unless query_string.respond_to? :gsub
15
+
16
+ query_string.gsub(/(?<=\A|&|\?)[^=&]+/) do |match|
17
+ match.gsub!('-', '_')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Apill
2
+ module Serializers
3
+ module JsonApi
4
+ def type
5
+ object.class.name.demodulize.tableize.dasherize
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/apill/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apill
2
- VERSION = '2.7.1'
2
+ VERSION = '2.8.0'
3
3
  end
data/lib/apill.rb CHANGED
@@ -10,6 +10,7 @@ require 'apill/mixins/indexable'
10
10
  require 'apill/mixins/sortable'
11
11
  require 'apill/mixins/queryable'
12
12
  require 'apill/mixins/pageable'
13
+ require 'apill/serializers/json_api'
13
14
 
14
15
  require 'apill/middleware/api_request'
15
16
 
@@ -131,6 +131,25 @@ describe ApiRequest do
131
131
  expect(headers).to eql({})
132
132
  expect(response).to eql 'response'
133
133
  end
134
+
135
+ it 'converts JSON API compliant dasherized query params to underscored' do
136
+ app = ->(env) { [200, env, 'response'] }
137
+ api_request_middleware = ApiRequest.new(app)
138
+
139
+ request = {
140
+ 'HTTP_HOST' => 'api.example.com',
141
+ 'HTTP_ACCEPT' => 'application/vnd.matrix+zion;version=1.0.0',
142
+ 'QUERY_STRING' => 'hello-there=bob-jones&' \
143
+ 'nice-to-meet=you-bob&' \
144
+ 'hows-the-weather=today-bob',
145
+ }
146
+
147
+ _status, headers, _response = api_request_middleware.call(request)
148
+
149
+ expect(headers['QUERY_STRING']).to eql 'hello_there=bob-jones&' \
150
+ 'nice_to_meet=you-bob&' \
151
+ 'hows_the_weather=today-bob'
152
+ end
134
153
  end
135
154
  end
136
155
  end
@@ -0,0 +1,42 @@
1
+ require 'rspectacular'
2
+ require 'apill/parameters'
3
+
4
+ module Apill
5
+ describe Parameters do
6
+ it 'can underscore the first parameter' do
7
+ query_params = 'hello-there=bob-jones'
8
+
9
+ expect(Parameters.process(query_params)).to eql 'hello_there=bob-jones'
10
+ end
11
+
12
+ it 'can underscore a middle parameter and a parameter at the end' do
13
+ query_params = 'hello-there=bob-jones&nice-to-meet=you-bob&hows-the-weather=today-bob'
14
+
15
+ expect(Parameters.process(query_params)).to eql 'hello_there=bob-jones&' \
16
+ 'nice_to_meet=you-bob&' \
17
+ 'hows_the_weather=today-bob'
18
+ end
19
+
20
+ it 'can handle weirdly formatted parameters' do
21
+ query_params = 'hello-there=bob-jones&nice-to-meet=you-bob&='
22
+
23
+ expect(Parameters.process(query_params)).to eql 'hello_there=bob-jones&' \
24
+ 'nice_to_meet=you-bob&='
25
+ end
26
+
27
+ it 'can handle parameters with no values' do
28
+ query_params = 'hello-there&nice-to-meet=you-bob&='
29
+
30
+ expect(Parameters.process(query_params)).to eql 'hello_there&' \
31
+ 'nice_to_meet=you-bob&='
32
+ end
33
+
34
+ it 'can handle values with no parameter name' do
35
+ query_params = 'hello-there=bob-jones&=you-bob&nice-to-meet=you-bob&='
36
+
37
+ expect(Parameters.process(query_params)).to eql 'hello_there=bob-jones&' \
38
+ '=you-bob&' \
39
+ 'nice_to_meet=you-bob&='
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apill
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: human_error
@@ -89,11 +89,13 @@ files:
89
89
  - lib/apill/mixins/pageable.rb
90
90
  - lib/apill/mixins/queryable.rb
91
91
  - lib/apill/mixins/sortable.rb
92
+ - lib/apill/parameters.rb
92
93
  - lib/apill/requests/base.rb
93
94
  - lib/apill/requests/rack_request.rb
94
95
  - lib/apill/requests/rails_request.rb
95
96
  - lib/apill/responses/invalid_api_request_response.rb
96
97
  - lib/apill/responses/invalid_subdomain_response.rb
98
+ - lib/apill/serializers/json_api.rb
97
99
  - lib/apill/version.rb
98
100
  - spec/apill/accept_header_spec.rb
99
101
  - spec/apill/errors/invalid_api_request_error_spec.rb
@@ -103,6 +105,7 @@ files:
103
105
  - spec/apill/matchers/subdomain_matcher_spec.rb
104
106
  - spec/apill/matchers/version_matcher_spec.rb
105
107
  - spec/apill/middleware/api_request_spec.rb
108
+ - spec/apill/parameters_spec.rb
106
109
  - spec/apill/requests/rack_request_spec.rb
107
110
  - spec/apill/requests/rails_request_spec.rb
108
111
  homepage: https://github.com/jfelchner/apill
@@ -125,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
128
  version: '0'
126
129
  requirements: []
127
130
  rubyforge_project:
128
- rubygems_version: 2.4.6
131
+ rubygems_version: 2.4.8
129
132
  signing_key:
130
133
  specification_version: 4
131
134
  summary: Common API functionality
@@ -138,5 +141,6 @@ test_files:
138
141
  - spec/apill/matchers/subdomain_matcher_spec.rb
139
142
  - spec/apill/matchers/version_matcher_spec.rb
140
143
  - spec/apill/middleware/api_request_spec.rb
144
+ - spec/apill/parameters_spec.rb
141
145
  - spec/apill/requests/rack_request_spec.rb
142
146
  - spec/apill/requests/rails_request_spec.rb