salestation 5.1.0 → 5.3.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
  SHA256:
3
- metadata.gz: 43663c5f6d78d7238e66e9ac88a06a49facfcaf45a329534e44e20891ea1baa9
4
- data.tar.gz: 97661dd29a53ab956cbe0c78522b382d052bd4c6f339208fe126f7d3c51f8526
3
+ metadata.gz: 3978171d3a2b78287dd0f3b86049f8253d1f66199545002701b1f4bd46295a64
4
+ data.tar.gz: 469b3e6ddfe9c1b399eda6f63827b7b674142f6a67ac16b03ad0f8ddb5e5e88a
5
5
  SHA512:
6
- metadata.gz: ee4cf2f592d41548e187277789ec6d3484748dc7cc152f3a9b4e4b63b438314e5fe96ab3aeb92dbd4729a485b4d9e73b518904459309b19f3da7a507595100ce
7
- data.tar.gz: 22a1c5415ded67ebc22c5f67ef6332706571a156000aac7e5195101c73be14dc950b5f208fb24b19e27c94b70c3c854dc8a5da485a01b030d578e9ccaac92c57
6
+ metadata.gz: 9a5140a9348d79cfde31b44dd7c8d24bbea0135d2d8371272a1ed86db6690be64f3248be27f1a845d3d6f64ab5b8c59809534cae6d68af6223c3d6f0edafcf11
7
+ data.tar.gz: 14ad1ff09a48d7d6c7be4c7bf5781cf922990dd43dac6f6df46aaa78939ed94875bcdeb9544ec85cac82252453975cc1ad5457bf644aa5ef6fc54e484fc39dec
data/README.md CHANGED
@@ -104,6 +104,14 @@ Multiple extractors can be merged together. If two or more extractors use the sa
104
104
 
105
105
  `coercions` can optionally be provided to `BodyParamExtractor` and `QueryParamExtractor`. These can be used to transform the values of the extracted parameters.
106
106
 
107
+ #### ParamExtractor
108
+
109
+ ParamExtractor, which is also used by `BodyParamExtractor` and `QueryParamExtractor`,
110
+ extracts only the content of such root level keys that are specified when creating the
111
+ extractor instance. All other root level keys are discarded. Everything inside the
112
+ whitelisted root level keys is automatically whitelisted.
113
+
114
+
107
115
  Define a route
108
116
 
109
117
  ```ruby
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require "symbolizer"
2
3
 
3
4
  module Salestation
4
5
  class Web < Module
@@ -192,35 +193,18 @@ module Salestation
192
193
  end
193
194
 
194
195
  def self.extract(filters, request_hash)
195
- filters.each_with_object({}) do |filter, extracted_data|
196
- case filter
197
- when Symbol
198
- stringified_key = filter.to_s
199
- extracted_data[filter] = request_hash[stringified_key] if request_hash.key?(stringified_key)
200
- if extracted_data[filter].is_a?(Array)
201
- extracted_data[filter] = extracted_data[filter].map{ |hash|
202
- if hash.is_a?(Hash)
203
- hash.transform_keys(&:to_sym) if hash.is_a?(Hash)
204
- else
205
- hash
206
- end
207
- }
208
- end
209
- when Hash
210
- filter.each do |key, nested_filters|
211
- stringified_key = key.to_s
212
- if request_hash.key?(stringified_key)
213
- value = request_hash.fetch(stringified_key)
214
- extracted_data[key] =
215
- if !value.is_a?(Hash)
216
- value
217
- else
218
- extract(nested_filters, value)
219
- end
220
- end
221
- end
222
- end
223
- end
196
+ # Filter as a hash is used in some existing implementations that did not expect full
197
+ # recursive symbolizing of keys. In this case hash objects at the highest level of object
198
+ # are represented as hash of filter keys. This is no longer needed, but we support it
199
+ # to avoid a breaking change.
200
+
201
+ filters_flat = filters
202
+ .flat_map {|filter| filter.is_a?(Hash) ? filter.keys : filter}
203
+ .map(&:to_s)
204
+
205
+ request_hash = request_hash.select {|k,v| filters_flat.include?(k)}
206
+
207
+ Symbolizer.symbolize(request_hash)
224
208
  end
225
209
  end
226
210
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Salestation
4
+ class Web < Module
5
+ module IPAddress
6
+ def self.extract(request)
7
+ if request['HTTP_X_FORWARDED_FOR'].nil?
8
+ request['REMOTE_ADDR']
9
+ else
10
+ request['HTTP_X_FORWARDED_FOR'].split(',').first
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -44,6 +44,7 @@ module Salestation
44
44
  end
45
45
 
46
46
  require_relative './web/extractors'
47
+ require_relative './web/ip_address'
47
48
  require_relative './web/responses'
48
49
  require_relative './web/error_mapper'
49
50
  require_relative './result_helper'
data/salestation.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "salestation"
7
- spec.version = "5.1.0"
7
+ spec.version = "5.3.0"
8
8
  spec.authors = ["Glia TechMovers"]
9
9
  spec.email = ["techmovers@glia.com"]
10
10
 
@@ -24,10 +24,11 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency "pry", "~> 0.10.4"
26
26
  spec.add_development_dependency "glia-errors", "~> 0.11.4"
27
- spec.add_development_dependency "dry-validation", "~> 1.7.0"
27
+ spec.add_development_dependency "dry-validation", "~> 1.7"
28
28
 
29
29
  spec.add_dependency 'deterministic'
30
30
  spec.add_dependency 'dry-struct'
31
31
  spec.add_dependency 'dry-types'
32
32
  spec.add_dependency 'http-accept', '~> 2.1'
33
+ spec.add_dependency 'symbolizer'
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salestation
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-04 00:00:00.000000000 Z
11
+ date: 2022-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.7.0
89
+ version: '1.7'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.7.0
96
+ version: '1.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: deterministic
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2.1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: symbolizer
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: ''
154
168
  email:
155
169
  - techmovers@glia.com
@@ -181,6 +195,7 @@ files:
181
195
  - lib/salestation/web/input_validator.rb
182
196
  - lib/salestation/web/input_validators/accept_header.rb
183
197
  - lib/salestation/web/input_validators/content_type_header.rb
198
+ - lib/salestation/web/ip_address.rb
184
199
  - lib/salestation/web/request_logger.rb
185
200
  - lib/salestation/web/responses.rb
186
201
  - lib/salestation/web/statsd_middleware.rb