upfluence-utils 0.12.6 → 0.12.8

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: ea9c2d716e73e1b7e75c956697b57490c5f186dc7dc6fbce331b8c9dec57ca59
4
- data.tar.gz: 4d77fded409b2ed689b8bd3dc8f4ff4c464474ac130d7e1437b67ccd37e48429
3
+ metadata.gz: 803a89e0f85660a1e560a132ca48f0fc8c6456224127589ce64fde865fea5256
4
+ data.tar.gz: 648ec627139b9b2784535204420b0f96eedfdc09d0b0e2946d5750245d230088
5
5
  SHA512:
6
- metadata.gz: b61684b170e6fa36e93189d58866cd359d3a83bf12fa58d89b4c881451f947a637c4bf6b6f84adb592f4018d544e0486474277c9dc21270aceabee27c9bd7656
7
- data.tar.gz: 6451711114ae81c5e04be67c97df30978cb87ef3873df55f648c7cc2ee7675bf33fa00da6e4d555354c638a1be6a1f2df0e22abe0ddaad551ee9778211b7881f
6
+ metadata.gz: b4597f0914e84b9dc20cb33e13fed94915e1d869fed622fbd131a0c30bbc9ec93de579fd31cfe376ed13a9426b458823acc242256801449e49f11d53c099703e
7
+ data.tar.gz: 0b31ac7d2ada93d55b5507be794065a0649d181061f0d252bac2a37da199b3c67d04f2fe33f80b59153b43aa816930e79c1c0ccd63ab689fa5230bd0f1476dfa
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in rbutils.gemspec
3
+ # Specify your gem's dependencies in upfluence_utils.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1 +1,98 @@
1
- # Rbutils
1
+ # Upfluence_Utils
2
+
3
+ # Description
4
+
5
+ Upfluence-utils is an utility box for ruby ​​projects. Some important abstractions are:
6
+
7
+ - Sentry error logger
8
+
9
+ - Base Api Endpoint
10
+
11
+ - Middlewares
12
+
13
+ - Mixins
14
+
15
+ ## Usage
16
+
17
+ Add in your gemfile the `gem 'upfluence-utils'` and run `bundle install`
18
+
19
+ ### Sentry error logger
20
+
21
+ Upfluence-utils provides the tool to notify sentry when a ruby error is raised.
22
+
23
+ It is based on the 'sentry-ruby' sdk, you can check the [documentation](https://docs.sentry.io/platforms/ruby/)..
24
+
25
+ Upfluence-utils also already provides the [basic configuration](https://docs.sentry.io/platforms/ruby/configuration/options/?original_referrer=https%3A%2F%2Fwww.google.com%2F) [here](https://github.com/upfluence/upfluence_utils/blob/fd9bb88960f7dbe04dc43180489207d2739cb0ff/lib/upfluence/error_logger/sentry.rb#L17) so it works like 'plug and play' and you just have to be aware of the environment variables.
26
+
27
+ ### Base ApiEndpoint
28
+
29
+ The class APIEndpoint can be inherited from your new endpoint mapped class in you ruby project, so you can take advantage of some resources, like:
30
+
31
+ - Healthcheck endpoint
32
+ - Access token validation
33
+ - Request body and serialize json_params
34
+ - `respond_with` to easily serialize a body response
35
+ - Base errors
36
+
37
+ You can inherit like:
38
+ ```ruby
39
+ class YourClassEndpoint < Upfluence::Endpoint::ApiEndpoint
40
+ end
41
+ ```
42
+
43
+ ### Middlewares
44
+
45
+ Provide some utils for http requests, such as:
46
+
47
+ - Headers builder
48
+ - Cors
49
+ - Prometheus logger
50
+ - Base Exceptions
51
+
52
+ ### Mixins
53
+
54
+ Based on the concept of [mixins](https://en.wikipedia.org/wiki/Mixin#:~:text=at%20the%20time.-,Definition,mixed%20in%20with%20other%20classes.), these classes provide some good tools, like:
55
+
56
+ - Pagination
57
+ - StrongParameters (class to validate params received/sent on endpoint)
58
+
59
+ you can use mixins from upfluence-utils like:
60
+
61
+ ```ruby
62
+ class YourClassEndpoint < AuthorizedEndpoint
63
+ include Upfluence::Mixin::Pagination
64
+ include Upfluence::Mixin::StrongParameters
65
+ end
66
+ ```
67
+
68
+ #### Pagination
69
+
70
+ For pagination, you can be inspired on this example:
71
+
72
+ ```http
73
+ [GET] /my_entity/?per_page=1&page=1
74
+ ```
75
+
76
+ ```ruby
77
+ get '/' do
78
+ respond_with_pagination(
79
+ payload: my_entity_paginated, # this should return the paginated model, you can use active record methods to do that
80
+ each_serializer: MyEntity::MyEntitySerializer, # serializer related to the model
81
+ except: %i[field], # some entity related you want to ignore on serialization
82
+ root: 'my_entity'
83
+ )
84
+ end
85
+ ```
86
+
87
+ #### StrongParams
88
+
89
+ For StrongParams mixin, you can be inspired like this example how to permit only some specific fields on POST request:
90
+
91
+ ```ruby
92
+ def create_params
93
+ json_params.require(:my_entity).permit(
94
+ :entity_name,
95
+ :entity_number
96
+ )
97
+ end
98
+ ```
@@ -9,17 +9,19 @@ module Upfluence
9
9
  def call(env)
10
10
  @app.call(env)
11
11
  rescue => e
12
- Upfluence.logger.error("Error: #{e.class}: #{e.message}")
13
- e.backtrace.each do |b|
14
- Upfluence.logger.error("\t#{b}")
15
- end
12
+ notify(error)
16
13
 
17
14
  raise e
18
15
  end
19
16
  end
20
17
 
21
18
  def notify(error, *_args)
22
- Upfluence.logger.error(error.inspect)
19
+ Upfluence.logger.error("Error: #{error.class}: #{error.message}")
20
+ Upfluence.logger.error("Inspect: #{error.inspect}")
21
+
22
+ error.backtrace.each do |b|
23
+ Upfluence.logger.error("\t#{b}")
24
+ end
23
25
  end
24
26
 
25
27
  def ignore_exception(*_kls); end
@@ -55,17 +55,19 @@ module Upfluence
55
55
  end
56
56
 
57
57
  @builder = Builder.new do
58
- if opts[:request_timeout]
59
- use Rack::Timeout, service_timeout: opts[:request_timeout]
60
- end
61
-
62
58
  use Middleware::RequestStapler
63
59
  use Middleware::Logger
64
60
  use Middleware::Prometheus
65
- use Prometheus::Middleware::Exporter if opts[:prometheus_endpoint]
66
61
  use Middleware::ApplicationHeaders, base_handler
67
62
  use Middleware::HandleException
63
+
64
+ if opts[:request_timeout]
65
+ use Rack::Timeout, service_timeout: opts[:request_timeout]
66
+ end
67
+
68
68
  use Upfluence.error_logger.middleware
69
+ use Prometheus::Middleware::Exporter if opts[:prometheus_endpoint]
70
+
69
71
  use Rack::ContentLength
70
72
  use Rack::Chunked
71
73
  use Rack::Lint if Upfluence.env.development?
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.12.6'.freeze
3
+ VERSION = '0.12.8'.freeze
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['dev@upfluence.com']
11
11
 
12
12
  spec.summary = 'Upfluence common utils for Ruby projects'
13
- spec.homepage = 'https://github.com/upfluence/rbutils'
13
+ spec.homepage = 'https://github.com/upfluence/upfluence_utils'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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.12.6
4
+ version: 0.12.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Upfluence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -303,8 +303,8 @@ files:
303
303
  - lib/upfluence/utils/thrift/middleware/request_logger.rb
304
304
  - lib/upfluence/utils/thrift/middleware/timeout.rb
305
305
  - lib/upfluence/utils/version.rb
306
- - rbutils.gemspec
307
- homepage: https://github.com/upfluence/rbutils
306
+ - upfluence_utils.gemspec
307
+ homepage: https://github.com/upfluence/upfluence_utils
308
308
  licenses:
309
309
  - MIT
310
310
  metadata: {}
@@ -323,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  - !ruby/object:Gem::Version
324
324
  version: '0'
325
325
  requirements: []
326
- rubygems_version: 3.3.3
326
+ rubygems_version: 3.2.32
327
327
  signing_key:
328
328
  specification_version: 4
329
329
  summary: Upfluence common utils for Ruby projects