strapi_ruby 0.1.4 → 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 +4 -4
- data/README.md +21 -11
- data/lib/strapi_ruby/client.rb +4 -3
- data/lib/strapi_ruby/endpoint/builder.rb +3 -3
- data/lib/strapi_ruby/endpoint/strapi_parameters.rb +2 -3
- data/lib/strapi_ruby/formatter.rb +4 -4
- data/lib/strapi_ruby/interface.rb +4 -2
- data/lib/strapi_ruby/markdown.rb +2 -0
- data/lib/strapi_ruby/validations.rb +3 -3
- data/lib/strapi_ruby/version.rb +1 -1
- data/lib/strapi_ruby.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83a9ecc38dc8ff1adf64535662413da30dff9605533c1ae8e6a551b788ee88d0
|
4
|
+
data.tar.gz: 3fde93cdbcfa93470db99490c3e5596730120d5a95b7edc4434a5196cbbf96b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8586e54910503bca17a6963afe7c0562a4826ca0fd390518cce4b3b4f0b537755208a4e238e45ea08a650527e7783a96f7968b6c1064e39b98fe6338c701ad3
|
7
|
+
data.tar.gz: 98e4aace0f601b52fdbf54907f5338c82857ae3e822dfbb52ae67209a4c2a5e26a77e60c0081967383dda165f76eec665d5362e7adeac46990bdc3f3ddfc0606
|
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,
|
118
|
+
answer = StrapiRuby.get(resource: :articles, document_id: "clkgylmcc000008lcdd868feh")
|
109
119
|
article = answer.data
|
110
|
-
title = article.
|
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,
|
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
|
-
|
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,
|
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.
|
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
|
-
|
328
|
-
"$in" => ["
|
337
|
+
documentId: {
|
338
|
+
"$in" => ["clkgylmcc000008lcdd868feh", "clkgylw7d000108lc4rw1bb6s"],
|
329
339
|
},
|
330
340
|
})
|
331
|
-
# => /restaurants?filters[
|
341
|
+
# => /restaurants?filters[documentId][$in][0]=clkgylmcc000008lcdd868feh&filters[documentId][$in][0]=clkgylw7d000108lc4rw1bb6s
|
332
342
|
|
333
343
|
# --------------------------------
|
334
344
|
|
data/lib/strapi_ruby/client.rb
CHANGED
@@ -40,7 +40,8 @@ module StrapiRuby
|
|
40
40
|
"User-Agent" => "StrapiRuby/#{StrapiRuby::VERSION}" }
|
41
41
|
|
42
42
|
Faraday.new(url: url) do |faraday|
|
43
|
-
|
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
|
-
@
|
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}/#{@
|
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
|
-
@
|
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
|
@@ -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
|
23
|
+
data.each { |item| parse_into_datetime!(item) }
|
24
24
|
else
|
25
|
-
parse_into_datetime!(data
|
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
|
65
|
+
data.each { |item| convert_attributes!(item) }
|
66
66
|
else
|
67
|
-
convert_attributes!(data
|
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
|
-
|
34
|
-
|
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
|
data/lib/strapi_ruby/markdown.rb
CHANGED
@@ -14,7 +14,7 @@ module StrapiRuby
|
|
14
14
|
def validate_options(options)
|
15
15
|
validate_config_presence
|
16
16
|
validate_resource(options)
|
17
|
-
|
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
|
51
|
-
raise TypeError, "#{ErrorMessage.
|
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)
|
data/lib/strapi_ruby/version.rb
CHANGED
data/lib/strapi_ruby.rb
CHANGED
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.
|
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:
|
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
|
146
|
+
rubygems_version: 3.5.3
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Ruby wrapper around Strapi API.
|