upfluence-utils 0.12.7 → 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: 8cc751a8c15d5d50d5a4e6233925f5842b6b5253f99f88794e9ce5764f3b0fd6
4
- data.tar.gz: c8da722fb01f9d4ceebb537fd8b94e3abbde514d4c8d9a71a71659ebc9b4e2bb
3
+ metadata.gz: 803a89e0f85660a1e560a132ca48f0fc8c6456224127589ce64fde865fea5256
4
+ data.tar.gz: 648ec627139b9b2784535204420b0f96eedfdc09d0b0e2946d5750245d230088
5
5
  SHA512:
6
- metadata.gz: 56eca8dbd6e79313f6901e0381d804556a138485b13dbcedf0724fa72d418417eb225929c42621b4279dffa281605aa37212913d84e49f71de4c3b6a5f3d5407
7
- data.tar.gz: b3fc2813b90ba677a41078ccb7b3f940e0d2fe20470679eec30b5340423348a4481a7433d4677e26b5d41fa356e092c8170feb9601e9628121e0998dc22cdb0e
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
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.12.7'.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.7
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-02 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: {}