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 +4 -4
- data/Gemfile +1 -1
- data/README.md +98 -1
- data/lib/upfluence/error_logger/null.rb +7 -5
- data/lib/upfluence/logger.rb +7 -4
- data/lib/upfluence/utils/version.rb +1 -1
- data/{rbutils.gemspec → upfluence_utils.gemspec} +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad61cd35c4b4c028b3c14dabda1472f5a643c85332a3ff1bf70f2b469c19f17
|
4
|
+
data.tar.gz: f76dc4478c6d50b373c7438dff22b8ed844278de026d058665842bfdf41edfa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b95e490013d83ab4ea075fdc3c2b2487b9f936649f2f9b4816e6d9f37e06774fe989f9f6ec117f083795a1730871566463863c0905dc892203d1283fa17c75f6
|
7
|
+
data.tar.gz: 878a2fe304f2a8176dca49a18f5490a86e21d7ede881e35f044178053f9f1b57147a785e4fda195f36d946782a21801a135bc383f1aecaee9b64544bdd850e00
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1 +1,98 @@
|
|
1
|
-
#
|
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
|
-
|
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.
|
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
|
data/lib/upfluence/logger.rb
CHANGED
@@ -41,10 +41,13 @@ module Upfluence
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def initialize(level = (ENV['LOGGER_LEVEL'] || '').downcase, caller_depth = 0)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
|
@@ -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/
|
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.
|
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:
|
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
|
-
-
|
307
|
-
homepage: https://github.com/upfluence/
|
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.
|
326
|
+
rubygems_version: 3.3.26
|
327
327
|
signing_key:
|
328
328
|
specification_version: 4
|
329
329
|
summary: Upfluence common utils for Ruby projects
|