dato-rails 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/dato/uploads.rb +1 -4
- data/lib/dato/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d61ca3870d999b82aed6ff238182a3a6fd4b294f87c608b1b9c4ee9425d97ad
|
4
|
+
data.tar.gz: 3032c72e0226946239830f8c5aaeb1a5f0640328aa349a269c1f156d9b40f6b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7733a018553585d7f51a8d85920932dabe04944581772d84c6e9bea5d9c8ec6107e0269c6b0832da4028533128d95c0fa91e409b17a4a1d4acf429ae9c5e1591
|
7
|
+
data.tar.gz: c705f72bf8f0ed731ff656459b0ef0e5adc4c0a351a79b250f4db55eb0835f6e17df8adb5e9e9a01f6420704c78c92972f894fc06935169795462b142b3a2a70
|
data/README.md
CHANGED
@@ -173,6 +173,9 @@ Dato::Client.new.items.destroy(item_id: '123')
|
|
173
173
|
Dato Rails also supports file uploads.
|
174
174
|
These can be created either from a local file or from a url.
|
175
175
|
Basically all file types are supported, as long as they are valid in the CMS.
|
176
|
+
Be aware that dato jobs are not synchronous, so you may need to
|
177
|
+
implement some kind of polling to check if the upload is finished.
|
178
|
+
The create method returns a job id, which can be used to retrieve the upload result.
|
176
179
|
|
177
180
|
> In addition to the binary file, also attributes and metadata can be uploaded.
|
178
181
|
Both metadata and attributes are optional.
|
@@ -203,9 +206,17 @@ attributes = { author: 'Dato Rails', default_field_metadata: meta }
|
|
203
206
|
```ruby
|
204
207
|
Dato::Client.new.uploads.create_from_url('https://picsum.photos/seed/picsum/200/300', filename: 'test.png')
|
205
208
|
Dato::Client.new.uploads.create_from_file(file.path, filename: 'test.png')
|
206
|
-
|
207
209
|
```
|
208
210
|
|
211
|
+
|
212
|
+
### Getting the upload id
|
213
|
+
As the file upload is asynchronous, you may need to implement some kind of polling to check if the upload is finished.
|
214
|
+
With the retrieve_job_result method you can retrieve the upload id from the job result.
|
215
|
+
```ruby
|
216
|
+
job_id = client.uploads.create_from_file(file.path) # get back a job id
|
217
|
+
response = client.uploads.retrieve_job_result(job_id).parse # check the status
|
218
|
+
upload_id = response.dig('data', 'attributes', 'payload', 'data', 'id') # if nil, it's not done yet
|
219
|
+
```
|
209
220
|
## Configuration
|
210
221
|
|
211
222
|
The following options are available:
|
@@ -279,7 +290,8 @@ You can now clone the dato-rails project
|
|
279
290
|
|
280
291
|
|
281
292
|
You then need to set a `DATO_API_TOKEN=abcd123x` in the `.env` file on the root of your project
|
282
|
-
to consume data from your project.
|
293
|
+
to consume data from your project. For testing purposes, set `TEST_MODEL_TYPE_ID=1234` in the `.env` file
|
294
|
+
with the id of the author model type in your project.
|
283
295
|
|
284
296
|
Then, run `bundle exec rspec` to run the tests.
|
285
297
|
|
data/lib/dato/uploads.rb
CHANGED
@@ -30,10 +30,7 @@ module Dato
|
|
30
30
|
|
31
31
|
upload_file_to_bucket(url: upload_url, path: path_to_file)
|
32
32
|
|
33
|
-
|
34
|
-
upload_id = retrieve_job_result(job_id).parse["data"]["attributes"]["payload"]["data"]["id"]
|
35
|
-
|
36
|
-
{upload_id:}
|
33
|
+
upload_file_to_dato(upload_id:, attributes:)
|
37
34
|
end
|
38
35
|
|
39
36
|
def retrieve_job_result(job_id)
|
data/lib/dato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dato-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|