upfluence-utils 0.9.0 → 0.9.5

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: c3bc57cd1a39618d9375c1e012443d9f5b700ab0f5ae821ccd634bc4d09a8c3f
4
- data.tar.gz: ef52fa325dd39b37d053349e0adabea839cff25ad4cf1a3f24e56f8af79e3ca7
3
+ metadata.gz: a772a1a30ba2d049bcc080e162bd3c7c7a0168210d93e84dfb187c346bc7f559
4
+ data.tar.gz: e2677f4fcf561c494915dee9204150ec93e92600e7a5413bc7af7bed6143ed15
5
5
  SHA512:
6
- metadata.gz: 3148ad418210609e1fadd1303f0a37b6e27865e67b85102d4828891359fcaeb23b2481d0ad1cc6aa4c0a7967ead1c6aec77b56a6f42dc1b66bc5466a0a0bbc9d
7
- data.tar.gz: 3da77ccc075193d01908f5070026ab5b6408b06267bb72c3554704d1f5559316d6b2316f432e6e54de928a155d66227ccca4aaf8b28ddd75ca49e7998b5c3342
6
+ metadata.gz: 3ee9fbf46fa1421d1f3e66a29e701eda7cbdd361dc8b8d2a5e4ec1baa1a412a91502a99c8cd3389eaaffcc2a9d0d600d2fac1814232df659b84e5092176eb61a
7
+ data.tar.gz: 2d5551334b452dfd16d40340665d42e4efb7f4694ccb302b497dbe48f7113d206db8da2a704188a8670ee4209d95430ed5e59bcb69d56116601c3fc82a51a29a
data/lib/test.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'upfluence/http/server'
2
+
3
+ Upfluence::HTTP::Server.new do
4
+ end.serve
data/lib/upfluence.rb CHANGED
@@ -2,5 +2,4 @@ require 'upfluence/utils'
2
2
  require 'upfluence/endpoint/api_endpoint'
3
3
  require 'upfluence/mixin/strong_parameters'
4
4
  require 'upfluence/mixin/pagination'
5
- require 'upfluence/base/exceptions/validation_error'
6
5
  require 'upfluence/resources'
@@ -2,6 +2,7 @@ require 'sinatra'
2
2
  require 'active_record'
3
3
  require 'active_support/hash_with_indifferent_access'
4
4
  require 'upfluence/http/endpoint/validation_error'
5
+ require 'upfluence/mixin/strong_parameters'
5
6
 
6
7
  module Upfluence
7
8
  module HTTP
@@ -99,6 +100,16 @@ module Upfluence
99
100
  Sinatra::Base.error ActiveRecord::RecordInvalid do |e|
100
101
  [422, Base::Exceptions::ValidationError.from_model(e.record).to_json]
101
102
  end
103
+
104
+ Sinatra::Base.error Upfluence::Mixin::StrongParameters::ParameterMissing do |e|
105
+ [
106
+ 400,
107
+ {
108
+ error: 'missing_parameter',
109
+ param: e.param
110
+ }.to_json
111
+ ]
112
+ end
102
113
  end
103
114
  end
104
115
  end
@@ -0,0 +1,31 @@
1
+ module Upfluence
2
+ module HTTP
3
+ module Endpoint
4
+ class ValidationError
5
+ def initialize(validations)
6
+ @validations = validations
7
+ end
8
+
9
+ class << self
10
+ def from_model(model)
11
+ validations = model.errors.details.map do |error_field, errors|
12
+ errors.map do |error|
13
+ OpenStruct.new(
14
+ ressource: model.model_name.singular,
15
+ field: error_field.to_s,
16
+ code: error[:error].to_s
17
+ )
18
+ end
19
+ end.flatten
20
+
21
+ new(validations)
22
+ end
23
+ end
24
+
25
+ def to_json
26
+ { errors: @validations }.to_json
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -4,10 +4,7 @@ module Upfluence
4
4
  class ApplicationHeaders
5
5
  def initialize(app, handler)
6
6
  @app = app
7
- @headers = {
8
- "X-Upfluence-Unit-Name" => handler.getName,
9
- "X-Upfluence-Version" => build_version(handler.getVersion)
10
- }
7
+ @headers = handler ? build_headers(handler) : {}
11
8
  end
12
9
 
13
10
  def call(env)
@@ -17,14 +14,19 @@ module Upfluence
17
14
 
18
15
  private
19
16
 
17
+ def build_headers(handler)
18
+ {
19
+ 'X-Upfluence-Unit-Name' => handler.getName,
20
+ 'X-Upfluence-Version' => build_version(handler.getVersion)
21
+ }
22
+ end
23
+
20
24
  def build_version(thrift_version)
21
- if v = thrift_version.semantic_version
22
- return "v#{v.major}.#{v.minor}.#{v.patch}"
23
- end
25
+ v = thrift_version.semantic_version
26
+ return "v#{v.major}.#{v.minor}.#{v.patch}" if v
24
27
 
25
- if v = thrift_version.git_version
26
- return "v0.0.0-#{v.commit}"
27
- end
28
+ v = thrift_version.git_version
29
+ return "v0.0.0-#{v.commit}" if v
28
30
 
29
31
  'undefined'
30
32
  end
@@ -36,6 +36,11 @@ module Upfluence
36
36
  def initialize(options = {}, &block)
37
37
  @options = DEFAULT_OPTIONS.dup.merge(options)
38
38
  opts = @options
39
+ base_handler = nil
40
+
41
+ if opts[:base_handler_klass]
42
+ base_handler = opts[:base_handler_klass].new(@options[:interfaces])
43
+ end
39
44
 
40
45
  @builder = Builder.new do
41
46
  use Middleware::Logger
@@ -54,12 +59,9 @@ module Upfluence
54
59
  run(opts[:healthcheck_endpoint] || Endpoint::Healthcheck.new)
55
60
  end
56
61
 
57
- if opts[:base_processor_klass] && opts[:base_handler_klass]
62
+ if opts[:base_processor_klass] && base_handler
58
63
  map '/base' do
59
- run_thrift(
60
- opts[:base_processor_klass],
61
- opts[:base_handler_klass].new(@options[:interfaces])
62
- )
64
+ run_thrift(opts[:base_processor_klass], base_handler)
63
65
  end
64
66
  end
65
67
 
@@ -1,23 +1,15 @@
1
1
  module Upfluence
2
2
  module Resources
3
3
  COUNTRIES = %w[
4
- US FR GB DE CH AF AL DZ AS AD AO AI
5
- AG AR AM AW AU AT AZ BS BH BD BB BY
6
- BE BZ BJ BM BT BO BA BW BR BN BG BF
7
- BI CV KH CM CA KY CF TD CL CN CO KM
8
- CG CD CK CI HR CU CY CZ DK DJ DM DO
9
- GW GY HT VA HN HK HU IS IN ID IR IQ
10
- IE IM IL IT JM JP JE JO KZ KE KI KP
11
- KR KW KG LA LV LB LI LS LR LY LT LU
12
- MO MK MG MW MY MV ML MT MH MQ MR MU
13
- MX FM MD MC MN ME MS MA MZ MM NA NR
14
- NP NL NC NZ NI NE NG NO OM PK PW PS
15
- PA PG PY PE PH PL PT PR QA RE RO RU
16
- RW KN LC VC WS SM ST SA SN RS SC SL
17
- SG SK SI SB SO ZA ES LK SD SR SZ SE
18
- SY TW TJ TZ TH TL TG TO TT TN TR TM
19
- TC TV UG UA AE GB UY UZ VU VE VN VG
20
- VI EH YE ZM ZW CR
4
+ US FR GB DE CH AF AL DZ AS AD AO AI AG AR AM AW AU AT AZ BS BH BD BB BY BE
5
+ BZ BJ BM BT BO BA BW BR BN BG BF BI CV KH CM CA KY CF TD CL CN CO KM CG CD
6
+ CK CI HR CU CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FO FJ FI PF GA GM GE GH
7
+ GI GR GL GD GP GU GT GG GN GW GY HT VA HN HK HU IS IN ID IR IQ IE IM IL IT
8
+ JM JP JE JO KZ KE KI KP KR KW KG LA LV LB LI LS LR LY LT LU MO MK MG MW MY
9
+ MV ML MT MH MQ MR MU MX FM MD MC MN ME MS MA MZ MM NA NR NP NL NC NZ NI NE
10
+ NG NO OM PK PW PS PA PG PY PE PH PL PT PR QA RE RO RU RW KN LC VC WS SM ST
11
+ SA SN RS SC SL SG SK SI SB SO ZA ES LK SD SR SZ SE SY TW TJ TZ TH TL TG TO
12
+ TT TN TR TM TC TV UG UA AE GB UY UZ VU VE VN VG VI EH YE ZM ZW CR
21
13
  ].freeze
22
14
  end
23
15
  end
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.9.0'.freeze
3
+ VERSION = '0.9.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Upfluence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -235,6 +235,7 @@ files:
235
235
  - LICENSE.txt
236
236
  - README.md
237
237
  - Rakefile
238
+ - lib/test.rb
238
239
  - lib/upfluence.rb
239
240
  - lib/upfluence/amqp/server.rb
240
241
  - lib/upfluence/endpoint/api_endpoint.rb
@@ -246,6 +247,7 @@ files:
246
247
  - lib/upfluence/http/endpoint/api_endpoint.rb
247
248
  - lib/upfluence/http/endpoint/healthcheck.rb
248
249
  - lib/upfluence/http/endpoint/profiler.rb
250
+ - lib/upfluence/http/endpoint/validation_error.rb
249
251
  - lib/upfluence/http/middleware/application_headers.rb
250
252
  - lib/upfluence/http/middleware/cors.rb
251
253
  - lib/upfluence/http/middleware/handle_exception.rb
@@ -290,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
292
  - !ruby/object:Gem::Version
291
293
  version: '0'
292
294
  requirements: []
293
- rubygems_version: 3.0.3
295
+ rubygems_version: 3.1.4
294
296
  signing_key:
295
297
  specification_version: 4
296
298
  summary: Upfluence common utils for Ruby projects