upfluence-utils 0.12.7 → 0.12.9

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: 0ad61cd35c4b4c028b3c14dabda1472f5a643c85332a3ff1bf70f2b469c19f17
4
+ data.tar.gz: f76dc4478c6d50b373c7438dff22b8ed844278de026d058665842bfdf41edfa5
5
5
  SHA512:
6
- metadata.gz: 56eca8dbd6e79313f6901e0381d804556a138485b13dbcedf0724fa72d418417eb225929c42621b4279dffa281605aa37212913d84e49f71de4c3b6a5f3d5407
7
- data.tar.gz: b3fc2813b90ba677a41078ccb7b3f940e0d2fe20470679eec30b5340423348a4481a7433d4677e26b5d41fa356e092c8170feb9601e9628121e0998dc22cdb0e
6
+ metadata.gz: b95e490013d83ab4ea075fdc3c2b2487b9f936649f2f9b4816e6d9f37e06774fe989f9f6ec117f083795a1730871566463863c0905dc892203d1283fa17c75f6
7
+ data.tar.gz: 878a2fe304f2a8176dca49a18f5490a86e21d7ede881e35f044178053f9f1b57147a785e4fda195f36d946782a21801a135bc383f1aecaee9b64544bdd850e00
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
@@ -41,10 +41,13 @@ module Upfluence
41
41
  end
42
42
 
43
43
  def initialize(level = (ENV['LOGGER_LEVEL'] || '').downcase, caller_depth = 0)
44
- STDOUT.sync = true
45
- @logdev = STDOUT
46
- @level = logger_level(level)
47
- @formatter = Formatter.new(caller_depth)
44
+ $stdout.sync = true
45
+
46
+ super(
47
+ $stdout,
48
+ level: logger_level(level),
49
+ formatter: Formatter.new(caller_depth)
50
+ )
48
51
  end
49
52
  end
50
53
 
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.12.7'.freeze
3
+ VERSION = '0.12.9'.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.9
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-06-12 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.2.32
326
+ rubygems_version: 3.3.26
327
327
  signing_key:
328
328
  specification_version: 4
329
329
  summary: Upfluence common utils for Ruby projects