strapi_ruby 0.1.0 → 0.1.2

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: b287ea9daf48f9208a65d0b604a453ef528ec576ab8312265608fbc032f616a9
4
+ data.tar.gz: 2d91df1a2215a1167fd8cc4ee0c0d99c6c4a5a6edd61c61f1c80f941c1636e6b
5
5
  SHA512:
6
- metadata.gz: 35b87fdf4069cbccf2fcf9988cf82fb0f46d2dbaedd73464a29cb8d95420608bcef064f77348ab7c8a9507405f1694161b6093eab3a56e671a4252284d29b70a
7
- data.tar.gz: 4ca960cc893eeda6a890174f83036ab96f18aba94eca66b68febffa33330c713e361a56ece7db8c5a2401c0851caad7e126b842830d9d3824672d05e1598a1d2
6
+ metadata.gz: 703efd7aa92556623aca9f27b53f229dddab82becb2408d4e2c2673c6feddfe39140df14d19f3f726706d36ea859bee201dc39a26d2f436931b4008443f25146
7
+ data.tar.gz: 1b31b0080faa5e81d91ba171386c654eb0f19bcca6d2692eb5533335558d500691bfc4127bf180982da7df415d5531b8e4d15f7cc9167b1eb5a76ffa98b23995
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## [Unreleased]
1
+ ## [0.1.2] - 2023-10-04
2
+
3
+ - Updated README
4
+
5
+ ## [0.1.1] - 2023-10-04
6
+
7
+ - Added logger for ClientError and ConfigError
2
8
 
3
9
  ## [0.1.0] - 2023-10-04
4
10
 
data/README.md CHANGED
@@ -34,6 +34,9 @@ I think it's one of the actual coolest solution for integrating a CMS into Rails
34
34
  - [DateTime conversion](#datetime-conversion)
35
35
  - [Markdown conversion](#markdown-conversion)
36
36
  - [Faraday block](#faraday-block)
37
+ - [Handling Errors](#handling-errors)
38
+ - [Errors Classes](#errors-classes)
39
+ - [Graceful degradation](#graceful-degradation)
37
40
  - [Contributing](#contributing)
38
41
  - [Tests](#tests)
39
42
 
@@ -151,7 +154,7 @@ StrapiRuby.delete(resource: :articles, id: 12)
151
154
 
152
155
  #### .escape_empty_answer
153
156
 
154
- See [`.escape_empty_answer`](#gracefuly-degrade-errors-when-they-happen)
157
+ See [`.escape_empty_answer`](#graceful-degradation)
155
158
 
156
159
  ### Basic Example: Rails
157
160
 
@@ -507,7 +510,7 @@ default_headers = { "Content-Type" => "application/json",
507
510
 
508
511
  Depending on your utilisation, there are multiple ways to handle errors.
509
512
 
510
- #### Error Classes
513
+ #### Errors Classes
511
514
 
512
515
  ```ruby
513
516
  # Config Error
@@ -527,10 +530,12 @@ class BadRequestError < ClientError
527
530
  class JSONParsingError < ClientError
528
531
  ```
529
532
 
530
- #### Gracefuly degrade errors when they happen
533
+ #### Graceful degradation
531
534
 
532
535
  One way to handle errors and gracefuly degrade is using `.escape_empty_answer` and use a block to nest your data accessing code.
533
536
 
537
+ Errors will still be logged in red in console.
538
+
534
539
  ##### Definition
535
540
 
536
541
  ```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.2"
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
-
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.2
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