json_api_toolbox 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07cee6578d3ec72b85799bb88a7b8f0fee45c63950516209dca50d65ee0d4bcb
4
- data.tar.gz: 9e6171341031bba7809a8337256d882e05ee5b11095bedd58e2f7ff2f62000d3
3
+ metadata.gz: d9c03a1afc1da78c6af3a8d92549ccee5cb1901eb996ee87a54d9fe918c5d313
4
+ data.tar.gz: cb6e51096559d9ad400cd4e3cd02a59f9a79afac1af504f91b283e26bb2cc456
5
5
  SHA512:
6
- metadata.gz: 24ab8d780ec3b8a21ace2100b29c8f60593bc01cef3f23dbe81a6d3993687aa7c3a93a22dd6e04c9647de17b62f693452c8e7b1a40941d191459879f89342c35
7
- data.tar.gz: 5aa57f37c3c11b462755ab90a3d85986ade02bdbb9d1d5a78a3f6ac5df025f5ee73eeb23ba9011277ace4a3a3742626a516ef8d62573976156d30cdc50bec496
6
+ metadata.gz: ad46e9d5e2a669d6471c7a8013afe86e13beae98867d0962e77eb3f89411de192b072266af5d455de695edf8ca5e621e9283dc40c67fded2fe55a3a2d66420f8
7
+ data.tar.gz: cf72e98693263a8a9b587443ec29fe0a0a7dad9a4ce4ba39a666e50993f255e4c09c24a72109c45480d0d87a3279ac31130e6f90a5d3594bb8b04641b0e54b32
data/.rubocop.yml CHANGED
@@ -2,5 +2,5 @@ inherit_from:
2
2
  - '.rubocop.base.yml'
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.6
5
+ TargetRubyVersion: 3.0
6
6
  SuggestExtensions: false
data/.version CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 3.0.0
data/CHANGELOG.md CHANGED
@@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.0.0] - 2024-06-04
10
+ ### Changed
11
+ - Atualiza imagem do ruby de 2.6 para 3.0
12
+ - Adiciona elastic-apm no renderizable exceptions
13
+
14
+ ### Added
15
+ - Adiciona gem elastic-apm
16
+
17
+ ### Removed
18
+ - Rake task: rake lint-and-test
19
+
20
+ ## [2.1.0] - 2022-11-09
21
+ ### Changed
22
+ - Permite seja via parametro, seja via ENV alterar o timeout do RestClient
23
+
9
24
  ## [2.0.1] - 2021-08-13
10
25
  ### Fixed
11
26
  - Fixed a constant loading problem on rails
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.6-alpine
1
+ FROM ruby:3.0.0-alpine
2
2
 
3
3
  RUN apk update \
4
4
  && apk upgrade \
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_api_toolbox (2.0.1)
4
+ json_api_toolbox (3.0.0)
5
5
  activerecord (>= 5.1.0)
6
6
  activesupport (>= 5.1.0)
7
+ elastic-apm
7
8
  json-api-vanilla
8
9
  jsonapi-serializable
9
10
  log_toolbox
@@ -73,33 +74,54 @@ GEM
73
74
  minitest (>= 5.1)
74
75
  tzinfo (~> 2.0)
75
76
  zeitwerk (~> 2.3)
77
+ addressable (2.8.6)
78
+ public_suffix (>= 2.0.2, < 6.0)
76
79
  ast (2.4.2)
80
+ base64 (0.2.0)
77
81
  builder (3.2.4)
78
82
  byebug (11.1.3)
79
83
  coderay (1.1.3)
80
84
  concurrent-ruby (1.1.9)
81
85
  crass (1.0.6)
86
+ date (3.3.4)
82
87
  diff-lcs (1.4.4)
83
- domain_name (0.5.20190701)
84
- unf (>= 0.0.5, < 1.0.0)
85
- erubi (1.10.0)
86
- globalid (0.5.2)
87
- activesupport (>= 5.0)
88
+ domain_name (0.6.20240107)
89
+ elastic-apm (4.7.3)
90
+ concurrent-ruby (~> 1.0)
91
+ http (>= 3.0)
92
+ ruby2_keywords
93
+ erubi (1.12.0)
94
+ ffi (1.17.0)
95
+ ffi-compiler (1.3.2)
96
+ ffi (>= 1.15.5)
97
+ rake
98
+ globalid (1.2.1)
99
+ activesupport (>= 6.1)
100
+ http (5.2.0)
101
+ addressable (~> 2.8)
102
+ base64 (~> 0.1)
103
+ http-cookie (~> 1.0)
104
+ http-form_data (~> 2.2)
105
+ llhttp-ffi (~> 0.5.0)
88
106
  http-accept (1.7.0)
89
- http-cookie (1.0.4)
107
+ http-cookie (1.0.6)
90
108
  domain_name (~> 0.5)
109
+ http-form_data (2.3.0)
91
110
  i18n (1.8.10)
92
111
  concurrent-ruby (~> 1.0)
93
- json-api-vanilla (1.0.2)
112
+ json-api-vanilla (1.0.4)
94
113
  jsonapi-renderer (0.2.2)
95
114
  jsonapi-serializable (0.3.1)
96
115
  jsonapi-renderer (~> 0.2.0)
116
+ llhttp-ffi (0.5.0)
117
+ ffi-compiler (~> 1.0)
118
+ rake (~> 13.0)
97
119
  log_toolbox (1.3.11)
98
120
  lograge (>= 0.11.1)
99
121
  logstash-event (>= 1.2.02)
100
122
  logstash-logger (>= 0.26.1)
101
123
  rails (>= 5.0)
102
- lograge (0.11.2)
124
+ lograge (0.14.0)
103
125
  actionpack (>= 4)
104
126
  activesupport (>= 4)
105
127
  railties (>= 4)
@@ -107,23 +129,33 @@ GEM
107
129
  logstash-event (1.2.02)
108
130
  logstash-logger (0.26.1)
109
131
  logstash-event (~> 1.2)
110
- loofah (2.12.0)
132
+ loofah (2.22.0)
111
133
  crass (~> 1.0.2)
112
- nokogiri (>= 1.5.9)
113
- mail (2.7.1)
134
+ nokogiri (>= 1.12.0)
135
+ mail (2.8.1)
114
136
  mini_mime (>= 0.1.1)
115
- marcel (1.0.1)
137
+ net-imap
138
+ net-pop
139
+ net-smtp
140
+ marcel (1.0.4)
116
141
  method_source (1.0.0)
117
- mime-types (3.3.1)
142
+ mime-types (3.5.2)
118
143
  mime-types-data (~> 3.2015)
119
- mime-types-data (3.2021.0704)
120
- mini_mime (1.1.0)
144
+ mime-types-data (3.2024.0507)
145
+ mini_mime (1.1.5)
121
146
  minitest (5.14.4)
147
+ net-imap (0.4.12)
148
+ date
149
+ net-protocol
150
+ net-pop (0.1.2)
151
+ net-protocol
152
+ net-protocol (0.2.2)
153
+ timeout
154
+ net-smtp (0.5.0)
155
+ net-protocol
122
156
  netrc (0.11.0)
123
- nio4r (2.5.8)
124
- nokogiri (1.12.3-x86_64-darwin)
125
- racc (~> 1.4)
126
- nokogiri (1.12.3-x86_64-linux)
157
+ nio4r (2.7.3)
158
+ nokogiri (1.16.5-x86_64-linux)
127
159
  racc (~> 1.4)
128
160
  parallel (1.20.1)
129
161
  parser (3.0.2.0)
@@ -134,10 +166,11 @@ GEM
134
166
  pry-byebug (3.9.0)
135
167
  byebug (~> 11.0)
136
168
  pry (~> 0.13.0)
137
- racc (1.5.2)
138
- rack (2.2.3)
139
- rack-test (1.1.0)
140
- rack (>= 1.0, < 3)
169
+ public_suffix (5.0.5)
170
+ racc (1.8.0)
171
+ rack (2.2.9)
172
+ rack-test (2.1.0)
173
+ rack (>= 1.3)
141
174
  rails (6.1.4)
142
175
  actioncable (= 6.1.4)
143
176
  actionmailbox (= 6.1.4)
@@ -153,11 +186,13 @@ GEM
153
186
  bundler (>= 1.15.0)
154
187
  railties (= 6.1.4)
155
188
  sprockets-rails (>= 2.0.0)
156
- rails-dom-testing (2.0.3)
157
- activesupport (>= 4.2.0)
189
+ rails-dom-testing (2.2.0)
190
+ activesupport (>= 5.0.0)
191
+ minitest
158
192
  nokogiri (>= 1.6)
159
- rails-html-sanitizer (1.3.0)
160
- loofah (~> 2.3)
193
+ rails-html-sanitizer (1.6.0)
194
+ loofah (~> 2.21)
195
+ nokogiri (~> 1.14)
161
196
  railties (6.1.4)
162
197
  actionpack (= 6.1.4)
163
198
  activesupport (= 6.1.4)
@@ -167,7 +202,7 @@ GEM
167
202
  rainbow (3.0.0)
168
203
  rake (13.0.6)
169
204
  regexp_parser (2.1.1)
170
- request_store (1.5.0)
205
+ request_store (1.7.0)
171
206
  rack (>= 1.4)
172
207
  rest-client (2.1.0)
173
208
  http-accept (>= 1.7.0, < 2.0)
@@ -200,26 +235,25 @@ GEM
200
235
  rubocop-ast (1.10.0)
201
236
  parser (>= 3.0.1.1)
202
237
  ruby-progressbar (1.11.0)
238
+ ruby2_keywords (0.0.5)
203
239
  shoulda-matchers (5.0.0)
204
240
  activesupport (>= 5.2.0)
205
- sprockets (4.0.2)
241
+ sprockets (4.2.1)
206
242
  concurrent-ruby (~> 1.0)
207
- rack (> 1, < 3)
208
- sprockets-rails (3.2.2)
209
- actionpack (>= 4.0)
210
- activesupport (>= 4.0)
243
+ rack (>= 2.2.4, < 4)
244
+ sprockets-rails (3.4.2)
245
+ actionpack (>= 5.2)
246
+ activesupport (>= 5.2)
211
247
  sprockets (>= 3.0.0)
212
- thor (1.1.0)
248
+ thor (1.3.1)
249
+ timeout (0.4.1)
213
250
  tzinfo (2.0.4)
214
251
  concurrent-ruby (~> 1.0)
215
- unf (0.1.4)
216
- unf_ext
217
- unf_ext (0.0.7.7)
218
252
  unicode-display_width (2.0.0)
219
- websocket-driver (0.7.5)
253
+ websocket-driver (0.7.6)
220
254
  websocket-extensions (>= 0.1.0)
221
255
  websocket-extensions (0.1.5)
222
- will_paginate (3.3.1)
256
+ will_paginate (4.0.0)
223
257
  zeitwerk (2.4.2)
224
258
 
225
259
  PLATFORMS
data/Rakefile CHANGED
@@ -1,11 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require "rubocop/rake_task"
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
- RuboCop::RakeTask.new(:lint)
7
-
8
- task default: :spec
9
-
10
- desc 'Execute both RuboCop and RSpec'
11
- task "lint-and-test" => [:lint, :spec]
@@ -1,10 +1,9 @@
1
- image: ruby:2.6
1
+ image: ruby:3.0
2
2
 
3
3
  definitions:
4
4
  caches:
5
- bundler-26: vendor/bundle
6
- bundler-27: vendor/bundle
7
5
  bundler-30: vendor/bundle
6
+ bundler-31: vendor/bundle
8
7
 
9
8
  steps:
10
9
  - step: &test
@@ -12,9 +11,12 @@ definitions:
12
11
  script:
13
12
  - apt-get install git
14
13
  - gem update --system
14
+ - gem install bundler -v $(cat Gemfile.lock | awk '/BUNDLED WITH/{ getline;print; }')
15
+ - bundle install
15
16
  - bundle config set --local path "vendor/bundle"
16
17
  - bin/setup.sh --strict
17
- - bundle exec rake lint-and-test
18
+ - bundle exec rubocop .
19
+ - RAILS_ENV=test bundle exec rspec
18
20
  - step: &release
19
21
  name: Release gem
20
22
  script:
@@ -31,24 +33,18 @@ pipelines:
31
33
  pull-requests:
32
34
  '**':
33
35
  - parallel:
34
- - step:
35
- <<: *test
36
- name: Ruby 2.6
37
- image: ruby:2.6
38
- caches:
39
- - bundler-26
40
- - step:
41
- <<: *test
42
- name: Ruby 2.7
43
- image: ruby:2.7
44
- caches:
45
- - bundler-27
46
36
  - step:
47
37
  <<: *test
48
38
  name: Ruby 3.0
49
39
  image: ruby:3.0
50
40
  caches:
51
41
  - bundler-30
42
+ - step:
43
+ <<: *test
44
+ name: Ruby 3.1
45
+ image: ruby:3.1
46
+ caches:
47
+ - bundler-31
52
48
  branches:
53
49
  master:
54
50
  - step: *release
@@ -4,8 +4,9 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'json_api_toolbox/version'
6
6
 
7
+ # rubocop:disable Metrics/BlockLength
7
8
  Gem::Specification.new do |spec|
8
- spec.required_ruby_version = '>= 2.6.0'
9
+ spec.required_ruby_version = '>= 3.0'
9
10
  spec.name = 'json_api_toolbox'
10
11
  spec.version = JsonApiToolbox::VERSION
11
12
 
@@ -22,6 +23,7 @@ Gem::Specification.new do |spec|
22
23
 
23
24
  spec.add_dependency 'activerecord', '>= 5.1.0'
24
25
  spec.add_dependency 'activesupport', '>= 5.1.0'
26
+ spec.add_dependency 'elastic-apm'
25
27
  spec.add_dependency 'jsonapi-serializable'
26
28
  spec.add_dependency 'json-api-vanilla'
27
29
  spec.add_dependency 'log_toolbox'
@@ -36,3 +38,4 @@ Gem::Specification.new do |spec|
36
38
  spec.add_development_dependency 'rubocop'
37
39
  spec.add_development_dependency 'shoulda-matchers'
38
40
  end
41
+ # rubocop:enable Metrics/BlockLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonApiToolbox
4
- VERSION = '2.0.1'
4
+ VERSION = '3.0.0'
5
5
  end
@@ -11,12 +11,8 @@ module JsonApiToolbox
11
11
  end
12
12
 
13
13
  def render_any_exception(exception)
14
- if Gem.loaded_specs.key?('log_toolbox')
15
- log_critical(exception)
16
- else
17
- puts_build_log_error(exception)
18
- end
19
-
14
+ log_exception(exception)
15
+ send_to_apm(exception)
20
16
  render build_jsonapi(exception)
21
17
  end
22
18
 
@@ -32,6 +28,18 @@ module JsonApiToolbox
32
28
  }, status: :internal_server_error }
33
29
  end
34
30
 
31
+ def log_exception(exception)
32
+ if Gem.loaded_specs.key?('log_toolbox')
33
+ log_critical(exception)
34
+ else
35
+ puts_build_log_error(exception)
36
+ end
37
+ end
38
+
39
+ def send_to_apm(exception)
40
+ ElasticAPM.report(exception) if Gem.loaded_specs.key?('elastic-apm')
41
+ end
42
+
35
43
  def puts_build_log_error(error)
36
44
  puts messages: error.try(:message), trace: error.try(:backtrace)
37
45
  end
data/lib/service.rb CHANGED
@@ -6,12 +6,15 @@ require 'json-api-vanilla'
6
6
 
7
7
  module JsonApiToolbox
8
8
  class Service
9
- attr_reader :http_method, :url, :body, :extra_headers
9
+ attr_reader :http_method, :url, :body, :extra_headers, :timeout
10
10
 
11
- def initialize(http_method, url, body, extra_headers = {})
11
+ DEFAULT_TIMEOUT = ENV.fetch('JSON_API_TOOLBOX_TIMEOUT', 60).to_i
12
+
13
+ def initialize(http_method, url, body, timeout, extra_headers = {})
12
14
  @http_method = http_method
13
15
  @url = url
14
16
  @body = body
17
+ @timeout = timeout
15
18
  @extra_headers = extra_headers
16
19
  end
17
20
 
@@ -24,7 +27,8 @@ module JsonApiToolbox
24
27
  method: http_method,
25
28
  url: url,
26
29
  payload: build_body,
27
- headers: build_header
30
+ headers: build_header,
31
+ timeout: timeout
28
32
  )
29
33
  end
30
34
 
@@ -44,21 +48,21 @@ module JsonApiToolbox
44
48
  end
45
49
 
46
50
  class << self
47
- def get(url: nil, includes: nil, query_string: nil, headers: {})
51
+ def get(url: nil, includes: nil, query_string: nil, timeout: DEFAULT_TIMEOUT, headers: {})
48
52
  body = build_query_string(includes, query_string)
49
- new(:get, url, body, headers).execute
53
+ new(:get, url, body, timeout, headers).execute
50
54
  end
51
55
 
52
- def post(url: nil, body: nil, headers: {})
53
- new(:post, url, body, headers).execute
56
+ def post(url: nil, body: nil, timeout: DEFAULT_TIMEOUT, headers: {})
57
+ new(:post, url, body, timeout, headers).execute
54
58
  end
55
59
 
56
- def patch(url: nil, body: nil, headers: {})
57
- new(:patch, url, body, headers).execute
60
+ def patch(url: nil, body: nil, timeout: DEFAULT_TIMEOUT, headers: {})
61
+ new(:patch, url, body, timeout, headers).execute
58
62
  end
59
63
 
60
- def put(url: nil, body: nil, headers: {})
61
- new(:put, url, body, headers).execute
64
+ def put(url: nil, body: nil, timeout: DEFAULT_TIMEOUT, headers: {})
65
+ new(:put, url, body, timeout, headers).execute
62
66
  end
63
67
 
64
68
  def parse_response(response)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriano Bacha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-16 00:00:00.000000000 Z
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 5.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: elastic-apm
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: jsonapi-serializable
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -252,14 +266,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
266
  requirements:
253
267
  - - ">="
254
268
  - !ruby/object:Gem::Version
255
- version: 2.6.0
269
+ version: '3.0'
256
270
  required_rubygems_version: !ruby/object:Gem::Requirement
257
271
  requirements:
258
272
  - - ">="
259
273
  - !ruby/object:Gem::Version
260
274
  version: '0'
261
275
  requirements: []
262
- rubygems_version: 3.2.25
276
+ rubygems_version: 3.5.11
263
277
  signing_key:
264
278
  specification_version: 4
265
279
  summary: Json API usefull tools