strapi_ruby 0.1.0 → 0.1.1

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: 9903f53042e56a2738031589080d7708a0286ac979d5f4f4aba8e71a914dc63f
4
- data.tar.gz: 2108880a59532797595fad52bd7461c0cc4e3f12708f0d16213655f86ed1097f
3
+ metadata.gz: 6b57f00940ff27f894585565de2df3b5df945331e961232b5588af966e1fe40b
4
+ data.tar.gz: f0c734f9fade77f6bdd03dd505cedd40acc3f798bc566f3753ec879b204a1c08
5
5
  SHA512:
6
- metadata.gz: 35b87fdf4069cbccf2fcf9988cf82fb0f46d2dbaedd73464a29cb8d95420608bcef064f77348ab7c8a9507405f1694161b6093eab3a56e671a4252284d29b70a
7
- data.tar.gz: 4ca960cc893eeda6a890174f83036ab96f18aba94eca66b68febffa33330c713e361a56ece7db8c5a2401c0851caad7e126b842830d9d3824672d05e1598a1d2
6
+ metadata.gz: 366d106cf1f9e421d2205e962643c19dfad4971f035163efbe8e900787898e1fabc8d50669b00ac7921e2bfa9bbb1f9891aa41f183630b7050f29e77e150e91c
7
+ data.tar.gz: eb616feadc6c363b2f89d21735373b35cc5705b2f0c59345acd33bba67fba1711e40adef3dbb0129d241c0f2b2aecb7c5bf4b163bffe18112b7511e0ffd22a1d
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [0.1.1] - 2023-10-04
2
+
3
+ - Added logger for ClientError and ConfigError
2
4
 
3
5
  ## [0.1.0] - 2023-10-04
4
6
 
data/README.md CHANGED
@@ -531,6 +531,8 @@ class JSONParsingError < ClientError
531
531
 
532
532
  One way to handle errors and gracefuly degrade is using `.escape_empty_answer` and use a block to nest your data accessing code.
533
533
 
534
+ Errors will still be logged in red in console.
535
+
534
536
  ##### Definition
535
537
 
536
538
  ```ruby
@@ -1,46 +1,50 @@
1
1
  module StrapiRuby
2
2
  class ClientError < StandardError
3
+ def initialize(message)
4
+ super(message)
5
+ StrapiRuby.logger.error(message)
6
+ end
3
7
  end
4
8
 
5
9
  class ConnectionError < ClientError
6
10
  def initialize(message)
7
- super("There is a problem while initializing the connection with Faraday: #{message}")
11
+ super("#{ErrorMessage.faraday_connection} #{message}")
8
12
  end
9
13
  end
10
14
 
11
15
  class UnauthorizedError < ClientError
12
16
  def initialize(message, status)
13
- super("There is an error from the Strapi server with status #{status}: #{message}. Make sure your strapi_token is valid.")
17
+ super("#{ErrorMessage.strapi_server_status} #{status}: #{message}. Make sure your strapi_token is valid.")
14
18
  end
15
19
  end
16
20
 
17
21
  class ForbiddenError < ClientError
18
22
  def initialize(message, status)
19
- super("There is an error from the Strapi server with status #{status}: #{message}. Make sure your strapi_token has the correct permissions or allow public access.")
23
+ super("#{ErrorMessage.strapi_server_status} #{status}: #{message}. Make sure your strapi_token has the correct permissions or allow public access.")
20
24
  end
21
25
  end
22
26
 
23
27
  class NotFoundError < ClientError
24
28
  def initialize(message, status)
25
- super("There is an error from the Strapi server with status #{status}: #{message}.")
29
+ super("#{ErrorMessage.strapi_server_status} #{status}: #{message}.")
26
30
  end
27
31
  end
28
32
 
29
33
  class UnprocessableEntityError < ClientError
30
34
  def initialize(message, status)
31
- super("There is an error from the Strapi server with status #{status}: #{message}.")
35
+ super("#{ErrorMessage.strapi_server_status} #{status}: #{message}.")
32
36
  end
33
37
  end
34
38
 
35
39
  class ServerError < ClientError
36
40
  def initialize(message, status)
37
- super("There is an error from the Strapi server with status #{status}: #{message}. Please try again later.")
41
+ super("#{ErrorMessage.strapi_server_status} #{status}: #{message}. Please try again later.")
38
42
  end
39
43
  end
40
44
 
41
45
  class BadRequestError < ClientError
42
46
  def initialize(message, status)
43
- super("There is an error from the Strapi server with status #{status}: #{message}. Check parameters")
47
+ super("#{ErrorMessage.strapi_server_status} #{status}: #{message}. Check parameters")
44
48
  end
45
49
  end
46
50
 
@@ -1,7 +1,7 @@
1
1
  module StrapiRuby
2
2
  class ConfigurationError < StandardError
3
3
  def initialize(message)
4
- super("You must configure StrapiRuby before using it. See README.md for details.\n #{message}")
4
+ super("#{ErrorMessage.configuration}\n #{message}")
5
5
  end
6
6
  end
7
7
  end
@@ -10,4 +10,7 @@ expected_string_symbol: Invalid argument type. Expected String or Symbol.
10
10
  expected_integer: Invalid argument type. Expected Integer.
11
11
  expected_proc: Invalid argument type. Expected Proc.
12
12
  publication_state: Invalid argument. Expected :live or :preview.
13
- pagination: Use a single pagination method, either by page or by offset
13
+ pagination: Use a single pagination method, either by page or by offset
14
+ strapi_server_status: There is an error from the Strapi server with status
15
+ faraday_connection: There is an error while implementing connection with Faraday
16
+ configuration: You must configure StrapiRuby before using it. See README.md for details.
@@ -0,0 +1,21 @@
1
+ require "colorize"
2
+
3
+ module StrapiRuby
4
+ class << self
5
+ attr_writer :logger
6
+
7
+ def logger
8
+ @logger ||= Logger.new($stdout).tap do |log|
9
+ log.progname = name
10
+ log.formatter = proc do |severity, datetime, progname, msg|
11
+ case severity
12
+ when "ERROR"
13
+ "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}] #{progname} - #{severity}: #{msg}".red
14
+ else
15
+ "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}] #{progname} - #{severity}: #{msg}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StrapiRuby
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/strapi_ruby.rb CHANGED
@@ -13,6 +13,7 @@ require_relative "strapi_ruby/configuration"
13
13
  require_relative "strapi_ruby/config"
14
14
 
15
15
  # Load errors
16
+ require_relative "strapi_ruby/errors/logger"
16
17
  require_relative "strapi_ruby/errors/client_error"
17
18
  require_relative "strapi_ruby/errors/configuration_error"
18
19
  require_relative "strapi_ruby/errors/error_message"
@@ -24,4 +25,3 @@ module StrapiRuby
24
25
  extend Configuration
25
26
  extend Interface
26
27
  end
27
-
Binary file
data/strapi_ruby.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.require_paths = ["lib"]
37
37
 
38
38
  # Uncomment to register a new dependency of your gem
39
+ spec.add_dependency "colorize", "~> 1.1.0"
39
40
  spec.add_dependency "faraday", "~> 2.7"
40
41
  spec.add_dependency "redcarpet", "~> 3.6"
41
42
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strapi_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxence Robinet
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2023-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +110,7 @@ files:
96
110
  - lib/strapi_ruby/errors/error_code.yml
97
111
  - lib/strapi_ruby/errors/error_message.rb
98
112
  - lib/strapi_ruby/errors/error_text.yml
113
+ - lib/strapi_ruby/errors/logger.rb
99
114
  - lib/strapi_ruby/formatter.rb
100
115
  - lib/strapi_ruby/interface.rb
101
116
  - lib/strapi_ruby/markdown.rb
@@ -105,6 +120,7 @@ files:
105
120
  - lib/strapi_ruby/version.rb
106
121
  - rubocop.txt
107
122
  - sig/strapi_ruby.rbs
123
+ - strapi_ruby-0.1.0.gem
108
124
  - strapi_ruby.gemspec
109
125
  homepage: https://github.com/saint-james-fr/strapi_ruby
110
126
  licenses: