strapi_ruby 0.1.3 → 1.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: a1ea7267c293e0bdd14967f64eedc922615f448b49d39a9ebdba914bb65b9336
4
- data.tar.gz: 99c88f5464b84da4e5eb99e106b77c00436cdc413a9be26b9aa6e44e23a0a31a
3
+ metadata.gz: 83a9ecc38dc8ff1adf64535662413da30dff9605533c1ae8e6a551b788ee88d0
4
+ data.tar.gz: 3fde93cdbcfa93470db99490c3e5596730120d5a95b7edc4434a5196cbbf96b0
5
5
  SHA512:
6
- metadata.gz: 96fffc52dfc440ebb3dcdefc07b26ced071d07cd96812d868388b7f4e382a2ef73814d9eb419e8c1f291c264fa68339fc3c263658b7b2535147709568b0a72e3
7
- data.tar.gz: 4e8c52118420a2d2dd2273e66221fa00c38ab7639fa7898a00647e53aec279557bcbfa0fb40859e911735890f947346a0990a22dd55d639dc44b2ab3cc1115ce
6
+ metadata.gz: a8586e54910503bca17a6963afe7c0562a4826ca0fd390518cce4b3b4f0b537755208a4e238e45ea08a650527e7783a96f7968b6c1064e39b98fe6338c701ad3
7
+ data.tar.gz: 98e4aace0f601b52fdbf54907f5338c82857ae3e822dfbb52ae67209a4c2a5e26a77e60c0081967383dda165f76eec665d5362e7adeac46990bdc3f3ddfc0606
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [0.1.3] - 2023-10-20
2
2
 
3
+ - Added error message for collection_query error
4
+
5
+ ## [0.1.3] - 2023-10-20
6
+
3
7
  - Check for errors when using collection strapi parameters like sort/filters... on single items
4
8
  - Fix Typo on ConfigError => ConfigurationError
5
9
 
data/README.md CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
  I think it's one of the actual coolest solution for integrating a CMS into Rails for example, so let's dive in!
12
12
 
13
+ ## Important Notice: Strapi V5 and strapi_ruby
14
+
15
+ Starting from version >=1.0.0, the StrapiRuby gem is only compatible with Strapi version 5 and above. This update includes significant changes to align with the new response format introduced in Strapi v5. Key changes include:
16
+
17
+ - **Flattened Response Format**: The `attributes` object has been removed, and fields are now directly part of the `data` object.
18
+ - **ID Handling**: The `id` field has been replaced with `documentId` to uniquely identify resources.
19
+ - **Filter Adjustments**: Filters that previously used `id` should now use `documentId`.
20
+
21
+ These changes ensure that the StrapiRuby gem takes full advantage of the improvements in Strapi v5, providing a more streamlined and efficient API interaction experience. Please ensure your Strapi server is updated to version 5 or later to use this version of the gem.
22
+
23
+ Following will be the documentation for 1.xx release.
24
+
13
25
  ## Table of contents
14
26
 
15
27
  - [Installation](#installation)
@@ -50,8 +62,6 @@ Add this line to your application's Gemfile:
50
62
  gem "strapi_ruby"
51
63
  ```
52
64
 
53
-
54
-
55
65
  Then if you use Rails, run in your terminal to generate a config initializer. Otherwise copy paste and fill the config block.
56
66
 
57
67
  ```bash
@@ -105,9 +115,9 @@ data = answer.data
105
115
  meta = answer.meta
106
116
 
107
117
  # Access a specific attribute
108
- answer = StrapiRuby.get(resource: :articles, id: 2)
118
+ answer = StrapiRuby.get(resource: :articles, document_id: "clkgylmcc000008lcdd868feh")
109
119
  article = answer.data
110
- title = article.attributes.title
120
+ title = article.title
111
121
 
112
122
  # If an error occur, it will be raised to be rescued and displayed in the answer.
113
123
  data = answer.data # => nil
@@ -125,7 +135,7 @@ answer = StrapiRuby.get(resource: :restaurants)
125
135
 
126
136
 
127
137
  # Get a specific element
128
- StrapiRuby.get(resource: :restaurants, id: 1)
138
+ StrapiRuby.get(resource: :restaurants, document_id: "clkgylmcc000008lcdd868feh")
129
139
  ```
130
140
 
131
141
  #### .post
@@ -143,7 +153,7 @@ StrapiRuby.post(resource: :articles,
143
153
  ```ruby
144
154
  # Update a specific item, return item updated
145
155
  StrapiRuby.put(resource: :articles,
146
- id: 23,
156
+ document_id: "clkgylmcc000008lcdd868feh",
147
157
  data: {content: "'I've edited this article via a PUT request'"})
148
158
  ```
149
159
 
@@ -151,7 +161,7 @@ StrapiRuby.put(resource: :articles,
151
161
 
152
162
  ```ruby
153
163
  # Delete an item, return item deleted
154
- StrapiRuby.delete(resource: :articles, id: 12)
164
+ StrapiRuby.delete(resource: :articles, document_id: "clkgylmcc000008lcdd868feh")
155
165
 
156
166
  ```
157
167
 
@@ -176,7 +186,7 @@ end
176
186
  <ul>
177
187
  <% @articles.data.each do |article| %>
178
188
  <li>
179
- <%= article.attributes.title %>
189
+ <%= article.title %>
180
190
  </li>
181
191
  <% end %>
182
192
  </ul>
@@ -324,11 +334,11 @@ StrapiRuby.get(resource: :users, filters: { username: { "$eq" => "John" } })
324
334
  # Using $in operator to match multiples values
325
335
  StrapiRuby.get(resource: :restaurants,
326
336
  filters: {
327
- id: {
328
- "$in" => ["3", "6", "8"],
337
+ documentId: {
338
+ "$in" => ["clkgylmcc000008lcdd868feh", "clkgylw7d000108lc4rw1bb6s"],
329
339
  },
330
340
  })
331
- # => /restaurants?filters[id][$in][0]=3&filters[id][$in][1]=6&filters[id][$in][2]=8
341
+ # => /restaurants?filters[documentId][$in][0]=clkgylmcc000008lcdd868feh&filters[documentId][$in][0]=clkgylw7d000108lc4rw1bb6s
332
342
 
333
343
  # --------------------------------
334
344
 
@@ -40,7 +40,8 @@ module StrapiRuby
40
40
  "User-Agent" => "StrapiRuby/#{StrapiRuby::VERSION}" }
41
41
 
42
42
  Faraday.new(url: url) do |faraday|
43
- faraday.request :url_encoded
43
+ # Use FlatParamsEncoder to prevent double encoding of special characters
44
+ faraday.options.params_encoder = Faraday::FlatParamsEncoder
44
45
  faraday.adapter Faraday.default_adapter
45
46
  block&.call(faraday)
46
47
  faraday.headers = default_headers.merge(faraday.headers)
@@ -69,9 +70,9 @@ module StrapiRuby
69
70
 
70
71
  # rubocop:disable Metrics/AbcSize
71
72
  def handle_response(response)
72
- body = convert_json_to_open_struct(response.body)
73
+ body = convert_json_to_open_struct(response.body) unless response.body.empty?
73
74
  case response.status
74
- when 200
75
+ when 200, 201
75
76
  body
76
77
  when 400
77
78
  raise BadRequestError.new(body.error.message, response.status)
@@ -3,7 +3,7 @@ module StrapiRuby
3
3
  class Builder
4
4
  def initialize(options = {})
5
5
  @resource = options[:resource]
6
- @id = options[:id]
6
+ @document_id = options[:document_id]
7
7
  @query = Query.new(options).call
8
8
  @result = nil
9
9
  end
@@ -20,7 +20,7 @@ module StrapiRuby
20
20
  @result = if collection?
21
21
  "#{base_uri}/#{@resource}"
22
22
  else
23
- "#{base_uri}/#{@resource}/#{@id}"
23
+ "#{base_uri}/#{@resource}/#{@document_id}"
24
24
  end
25
25
  end
26
26
 
@@ -29,7 +29,7 @@ module StrapiRuby
29
29
  end
30
30
 
31
31
  def collection?
32
- @id.nil?
32
+ @document_id.nil?
33
33
  end
34
34
 
35
35
  def base_uri
@@ -114,12 +114,11 @@ module StrapiRuby
114
114
  traverse_hash({ index => item }, current_key)
115
115
  end
116
116
  else
117
- # We can pass values as symbols but we need to convert them to string
118
- # to be able to escape them
119
117
  value = value.to_s if value.is_a?(Symbol)
118
+ next if value.nil? # Skip nil values
120
119
  "#{current_key}=#{CGI.escape(value)}"
121
120
  end
122
- end.join("&")
121
+ end.compact.join("&")
123
122
  end
124
123
  end
125
124
  end
@@ -13,4 +13,5 @@ publication_state: Invalid argument. Expected :live or :preview.
13
13
  pagination: Use a single pagination method, either by page or by offset
14
14
  strapi_server_status: There is an error from the Strapi server with status
15
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.
16
+ configuration: You must configure StrapiRuby before using it. See README.md for details.
17
+ collection_query: You try to use Strapi parameters on a single item but they should be used on a collection.
@@ -20,9 +20,9 @@ module StrapiRuby
20
20
  return unless StrapiRuby.config.convert_to_datetime
21
21
 
22
22
  if collection?(data)
23
- data.each { |item| parse_into_datetime!(item.attributes) }
23
+ data.each { |item| parse_into_datetime!(item) }
24
24
  else
25
- parse_into_datetime!(data.attributes)
25
+ parse_into_datetime!(data)
26
26
  end
27
27
  end
28
28
 
@@ -62,9 +62,9 @@ module StrapiRuby
62
62
 
63
63
  def convert_to_html!(data)
64
64
  if collection?(data)
65
- data.each { |item| convert_attributes!(item.attributes) }
65
+ data.each { |item| convert_attributes!(item) }
66
66
  else
67
- convert_attributes!(data.attributes)
67
+ convert_attributes!(data)
68
68
  end
69
69
  end
70
70
 
@@ -30,8 +30,10 @@ module StrapiRuby
30
30
  validate_options(options)
31
31
  @endpoint = build_endpoint(options)
32
32
  answer = build_answer(http_verb, @endpoint, options)
33
- data = format_data(answer.data, options)
34
- meta = answer.meta
33
+ if answer
34
+ data = format_data(answer.data, options) unless answer.data.nil?
35
+ meta = answer.meta unless answer.meta.nil?
36
+ end
35
37
 
36
38
  return_success_open_struct(data, meta, options)
37
39
  rescue StrapiRuby::ClientError, StrapiRuby::ConfigurationError => e
@@ -8,6 +8,8 @@ module StrapiRuby
8
8
  include Singleton
9
9
 
10
10
  def to_html(markdown)
11
+ return "" if markdown.nil?
12
+
11
13
  markdown_renderer.render(markdown)
12
14
  end
13
15
 
@@ -14,7 +14,7 @@ module StrapiRuby
14
14
  def validate_options(options)
15
15
  validate_config_presence
16
16
  validate_resource(options)
17
- validate_id(options)
17
+ validate_document_id(options)
18
18
  validate_show_endpoint_params(options)
19
19
  validate_body(options)
20
20
  end
@@ -47,8 +47,8 @@ module StrapiRuby
47
47
  raise TypeError, "#{ErrorMessage.expected_string_symbol} Got #{options[:resource].class.name}" unless options[:resource].is_a?(String) || options[:resource].is_a?(Symbol)
48
48
  end
49
49
 
50
- def validate_id(options)
51
- raise TypeError, "#{ErrorMessage.expected_integer} Got #{options[:id].class.name}" if options.key?(:id) && !options[:id].is_a?(Integer)
50
+ def validate_document_id(options)
51
+ raise TypeError, "#{ErrorMessage.expected_string} Got #{options[:document_id].class.name}" if options.key?(:document_id) && !options[:document_id].is_a?(String)
52
52
  end
53
53
 
54
54
  def validate_show_endpoint_params(options)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StrapiRuby
4
- VERSION = "0.1.3"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/strapi_ruby.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require "ostruct"
2
3
 
3
4
  require_relative "strapi_ruby/version"
4
5
  require_relative "strapi_ruby/validations"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strapi_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxence Robinet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.3.7
146
+ rubygems_version: 3.5.3
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Ruby wrapper around Strapi API.