dato 0.7.9 → 0.7.16
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/CHANGELOG.md +55 -8
- data/Rakefile +4 -1
- data/dato.gemspec +2 -1
- data/lib/dato.rb +1 -0
- data/lib/dato/api_client.rb +21 -22
- data/lib/dato/cli.rb +3 -0
- data/lib/dato/local/field_type/file.rb +12 -1
- data/lib/dato/local/field_type/upload_id.rb +1 -1
- data/lib/dato/local/loader.rb +9 -2
- data/lib/dato/utils/build_modular_block.rb +31 -0
- data/lib/dato/utils/meta_tags/base.rb +1 -1
- data/lib/dato/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5497d73f33b5f38e2f931d32bba7fa6362d5069d0b8fa5cf3b85326f339ab0ba
|
4
|
+
data.tar.gz: b085c940d24c1f3a2bea211ad0fef22cf0455bbb958c85c0932fa4659c9a362c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce46783a3fe8719de2400ea08b94bde2b7c64856c889129cd22580c97e727931c8025f97740dd8c5124997d973178aff3b284f103967bee91ff4a857151afc6f
|
7
|
+
data.tar.gz: dce4329c9bf0a556a0044b7e17c21e4e091a51da35466734fd03987dd59206a5f00d57b7496f0c46451cba4ebaf446628664bac89d0454f824488108825d23e4
|
data/CHANGELOG.md
CHANGED
@@ -1,30 +1,77 @@
|
|
1
|
+
# 0.7.16
|
2
|
+
|
3
|
+
Fixes bug when launching `dato dump --watch` together with the `environment` option.
|
4
|
+
|
5
|
+
# 0.7.13
|
6
|
+
|
7
|
+
Add option to pass a project's environment:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "dato"
|
11
|
+
client = Dato::Site::Client.new("YOUR-API-KEY", environment: 'sandbox-foobar')
|
12
|
+
```
|
13
|
+
|
14
|
+
# 0.7.12
|
15
|
+
|
16
|
+
Introduces `Dato::Utils::BuildModularBlock` class to help creating modular blocks.
|
17
|
+
|
18
|
+
An example usage can be:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
description = [
|
22
|
+
Dato::Utils::BuildModularBlock.build(
|
23
|
+
item_type: "1235",
|
24
|
+
name: "Best dog in the world",
|
25
|
+
year: "2020",
|
26
|
+
picture: picture
|
27
|
+
)
|
28
|
+
]
|
29
|
+
|
30
|
+
record = client.items.create(
|
31
|
+
item_type: "1234", # model ID
|
32
|
+
name: "Gigio",
|
33
|
+
description: description
|
34
|
+
)
|
35
|
+
```
|
36
|
+
|
37
|
+
Find more info [on the documentation](https://www.datocms.com/docs/content-management-api/resources/item/create).
|
38
|
+
|
39
|
+
# 0.7.11 (not released)
|
40
|
+
|
41
|
+
- Updated specs cassettes after `appeareance -> appearance` typo fix
|
42
|
+
- Some style changes
|
43
|
+
|
44
|
+
# 0.7.10
|
45
|
+
|
46
|
+
- Fixed SEO title retrieval. Now it fallbacks to default SEO title is item title is blank
|
47
|
+
|
1
48
|
# 0.7.9
|
2
49
|
|
3
|
-
|
50
|
+
- Added new attributes to uploads
|
4
51
|
|
5
52
|
# 0.7.0
|
6
53
|
|
7
|
-
|
54
|
+
- Real-time events are now much more granular and the gem avoids downloading all the content every time a change occurs
|
8
55
|
|
9
56
|
# 0.6.18
|
10
57
|
|
11
|
-
|
58
|
+
- Fixed regression where you could no longer access items' item type
|
12
59
|
|
13
60
|
# 0.6.15
|
14
61
|
|
15
|
-
|
62
|
+
- Handle `429 Too Many Requests` responses from API
|
16
63
|
|
17
64
|
# 0.6.12
|
18
65
|
|
19
|
-
|
66
|
+
- Allow empty responses from server
|
20
67
|
|
21
68
|
# 0.6.10
|
22
69
|
|
23
|
-
|
70
|
+
- Introduced `.meta` on `Dato::Local::Item` to fetch all meta information about the records
|
24
71
|
|
25
72
|
# 0.6.5
|
26
73
|
|
27
|
-
|
74
|
+
- The `.seo_meta_tags` method now generates fallback titles based on the model field title
|
28
75
|
|
29
76
|
# v0.6.2
|
30
77
|
|
@@ -32,7 +79,7 @@ Moved `json_schema` as runtime dependency
|
|
32
79
|
|
33
80
|
# v0.6.1
|
34
81
|
|
35
|
-
The big change is that the methods the client makes available are
|
82
|
+
The big change is that the methods the client makes available are generated at runtime based on the [JSON Schema of our CMA](https://www.datocms.com/content-management-api/). This means any new API endpoint — or changes to existing ones — will instantly be reflected to the client, without the need to upgrade to the latest client version.
|
36
83
|
|
37
84
|
We also added a new `deserialize_response` option to every call, that you can use if you want to retrieve the exact payload the DatoCMS returns:
|
38
85
|
|
data/Rakefile
CHANGED
data/dato.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'rubocop'
|
31
31
|
spec.add_development_dependency 'coveralls'
|
32
32
|
spec.add_development_dependency 'pry'
|
33
|
+
spec.add_development_dependency 'pry-byebug'
|
33
34
|
spec.add_development_dependency 'front_matter_parser'
|
34
35
|
|
35
36
|
spec.add_runtime_dependency 'faraday', ['>= 0.9.0']
|
@@ -37,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
37
38
|
spec.add_runtime_dependency 'activesupport', ['>= 4.2.7']
|
38
39
|
spec.add_runtime_dependency 'addressable'
|
39
40
|
spec.add_runtime_dependency 'thor'
|
40
|
-
spec.add_runtime_dependency 'imgix', ['
|
41
|
+
spec.add_runtime_dependency 'imgix', ['~> 4']
|
41
42
|
spec.add_runtime_dependency 'toml'
|
42
43
|
spec.add_runtime_dependency 'cacert'
|
43
44
|
spec.add_runtime_dependency 'dotenv'
|
data/lib/dato.rb
CHANGED
data/lib/dato/api_client.rb
CHANGED
@@ -20,7 +20,7 @@ module Dato
|
|
20
20
|
base.extend ClassMethods
|
21
21
|
|
22
22
|
base.class_eval do
|
23
|
-
attr_reader :token, :base_url, :schema, :extra_headers
|
23
|
+
attr_reader :token, :environment, :base_url, :schema, :extra_headers
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,27 +29,28 @@ module Dato
|
|
29
29
|
define_method(:initialize) do |token, options = {}|
|
30
30
|
@token = token
|
31
31
|
@base_url = options[:base_url] || "https://#{subdomain}.datocms.com"
|
32
|
+
@environment = options[:environment]
|
32
33
|
@extra_headers = options[:extra_headers] || {}
|
33
34
|
end
|
34
35
|
|
36
|
+
# FOR DEV
|
37
|
+
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
35
38
|
response = Faraday.get(
|
36
|
-
# FOR DEV
|
37
|
-
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
38
39
|
"https://#{subdomain}.datocms.com/docs/#{subdomain}-hyperschema.json"
|
39
40
|
)
|
40
41
|
|
41
42
|
schema = JsonSchema.parse!(JSON.parse(response.body))
|
42
43
|
schema.expand_references!
|
43
44
|
|
44
|
-
schema.definitions.each do |type,
|
45
|
-
is_collection =
|
45
|
+
schema.definitions.each do |type, obj|
|
46
|
+
is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
|
46
47
|
namespace = is_collection ? type.pluralize : type
|
47
48
|
|
48
49
|
define_method(namespace) do
|
49
50
|
instance_variable_set(
|
50
51
|
"@#{namespace}",
|
51
52
|
instance_variable_get("@#{namespace}") ||
|
52
|
-
Dato::Repo.new(self, type,
|
53
|
+
Dato::Repo.new(self, type, obj)
|
53
54
|
)
|
54
55
|
end
|
55
56
|
end
|
@@ -76,16 +77,10 @@ module Dato
|
|
76
77
|
method, absolute_path, body, params = args
|
77
78
|
|
78
79
|
response = connection.send(method, absolute_path, body) do |c|
|
79
|
-
if params
|
80
|
-
c.params = params
|
81
|
-
end
|
80
|
+
c.params = params if params
|
82
81
|
end
|
83
82
|
|
84
|
-
if response.body.is_a?(Hash)
|
85
|
-
response.body.with_indifferent_access
|
86
|
-
else
|
87
|
-
nil
|
88
|
-
end
|
83
|
+
response.body.with_indifferent_access if response.body.is_a?(Hash)
|
89
84
|
rescue Faraday::SSLError => e
|
90
85
|
raise e if ENV['SSL_CERT_FILE'] == Cacert.pem
|
91
86
|
|
@@ -101,14 +96,14 @@ module Dato
|
|
101
96
|
sleep(to_wait + 1)
|
102
97
|
request(*args)
|
103
98
|
elsif e.response[:status] == 422 && batch_data_validation?(e.response)
|
104
|
-
puts
|
99
|
+
puts 'Validating items, waiting 1 second and retrying...'
|
105
100
|
sleep(1)
|
106
101
|
request(*args)
|
107
102
|
else
|
108
103
|
error = ApiError.new(e.response)
|
109
|
-
puts
|
104
|
+
puts '===='
|
110
105
|
puts error.message
|
111
|
-
puts
|
106
|
+
puts '===='
|
112
107
|
raise error
|
113
108
|
end
|
114
109
|
end
|
@@ -123,12 +118,12 @@ module Dato
|
|
123
118
|
end
|
124
119
|
|
125
120
|
return false unless body
|
126
|
-
return false unless body[
|
121
|
+
return false unless body['data']
|
127
122
|
|
128
|
-
body[
|
129
|
-
e[
|
123
|
+
body['data'].any? do |e|
|
124
|
+
e['attributes']['code'] == 'BATCH_DATA_VALIDATION_IN_PROGRESS'
|
130
125
|
end
|
131
|
-
rescue
|
126
|
+
rescue StandardError
|
132
127
|
false
|
133
128
|
end
|
134
129
|
|
@@ -141,9 +136,13 @@ module Dato
|
|
141
136
|
'X-Api-Version' => '3'
|
142
137
|
}
|
143
138
|
|
139
|
+
if environment
|
140
|
+
default_headers.merge!('X-Environment' => environment)
|
141
|
+
end
|
142
|
+
|
144
143
|
options = {
|
145
144
|
url: base_url,
|
146
|
-
headers: default_headers.merge(extra_headers)
|
145
|
+
headers: default_headers.merge(extra_headers)
|
147
146
|
}
|
148
147
|
|
149
148
|
@connection ||= Faraday.new(options) do |c|
|
data/lib/dato/cli.rb
CHANGED
@@ -11,8 +11,10 @@ module Dato
|
|
11
11
|
desc 'dump', 'dumps DatoCMS content into local files'
|
12
12
|
option :config, default: 'dato.config.rb'
|
13
13
|
option :token, default: ENV['DATO_API_TOKEN'], required: true
|
14
|
+
option :environment, type: :string, required: false
|
14
15
|
option :preview, default: false, type: :boolean
|
15
16
|
option :watch, default: false, type: :boolean
|
17
|
+
|
16
18
|
def dump
|
17
19
|
config_file = File.expand_path(options[:config])
|
18
20
|
watch_mode = options[:watch]
|
@@ -20,6 +22,7 @@ module Dato
|
|
20
22
|
|
21
23
|
client = Dato::Site::Client.new(
|
22
24
|
options[:token],
|
25
|
+
environment: options[:environment],
|
23
26
|
extra_headers: {
|
24
27
|
'X-Reason' => 'dump',
|
25
28
|
'X-SSG' => Dump::SsgDetector.new(Dir.pwd).detect
|
@@ -210,7 +210,7 @@ module Dato
|
|
210
210
|
|
211
211
|
def file
|
212
212
|
Imgix::Client.new(
|
213
|
-
|
213
|
+
domain: @imgix_host,
|
214
214
|
secure: true,
|
215
215
|
include_library_param: false
|
216
216
|
).path(path)
|
@@ -220,6 +220,17 @@ module Dato
|
|
220
220
|
file.to_url(opts)
|
221
221
|
end
|
222
222
|
|
223
|
+
def lqip_data_url(opts = {})
|
224
|
+
@imgix_host != "www.datocms-assets.com" and
|
225
|
+
raise "#lqip_data_url can only be used with www.datocms-assets.com domain"
|
226
|
+
|
227
|
+
response = Faraday.get(file.to_url(opts.merge(lqip: "blurhash")))
|
228
|
+
|
229
|
+
if response.status == 200
|
230
|
+
"data:image/jpeg;base64,#{Base64.strict_encode64(response.body)}"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
223
234
|
def to_hash(*_args)
|
224
235
|
{
|
225
236
|
id: id,
|
data/lib/dato/local/loader.rb
CHANGED
@@ -43,7 +43,13 @@ module Dato
|
|
43
43
|
|
44
44
|
return if pusher && pusher.connected
|
45
45
|
|
46
|
-
|
46
|
+
channel_name = if client.environment
|
47
|
+
"private-site-#{site_id}-environment-#{client.environment}"
|
48
|
+
else
|
49
|
+
"private-site-#{site_id}"
|
50
|
+
end
|
51
|
+
|
52
|
+
pusher.subscribe(channel_name)
|
47
53
|
|
48
54
|
bind_on_site_upsert(&block)
|
49
55
|
bind_on_item_destroy(&block)
|
@@ -66,7 +72,8 @@ module Dato
|
|
66
72
|
bind_on("site:upsert", block) do |data|
|
67
73
|
threads = [
|
68
74
|
Thread.new { Thread.current[:output] = site },
|
69
|
-
Thread.new { Thread.current[:output] = all_items }
|
75
|
+
Thread.new { Thread.current[:output] = all_items },
|
76
|
+
Thread.new { Thread.current[:output] = all_uploads }
|
70
77
|
]
|
71
78
|
|
72
79
|
results = threads.map do |t|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dato/json_api_serializer'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Utils
|
7
|
+
module BuildModularBlock
|
8
|
+
def self.build(unserialized_body)
|
9
|
+
json_api_serializer = JsonApiSerializer.new('item', nil)
|
10
|
+
attributes = json_api_serializer.serialized_attributes(unserialized_body)
|
11
|
+
|
12
|
+
payload = {
|
13
|
+
type: 'item',
|
14
|
+
attributes: attributes,
|
15
|
+
relationships: {
|
16
|
+
item_type: {
|
17
|
+
data: {
|
18
|
+
id: unserialized_body[:item_type],
|
19
|
+
type: 'item_type',
|
20
|
+
},
|
21
|
+
},
|
22
|
+
},
|
23
|
+
}
|
24
|
+
|
25
|
+
payload[:id] = unserialized_body[:id] if unserialized_body[:id]
|
26
|
+
|
27
|
+
payload
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/dato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry-byebug
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: front_matter_parser
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -238,16 +252,16 @@ dependencies:
|
|
238
252
|
name: imgix
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
240
254
|
requirements:
|
241
|
-
- - "
|
255
|
+
- - "~>"
|
242
256
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
257
|
+
version: '4'
|
244
258
|
type: :runtime
|
245
259
|
prerelease: false
|
246
260
|
version_requirements: !ruby/object:Gem::Requirement
|
247
261
|
requirements:
|
248
|
-
- - "
|
262
|
+
- - "~>"
|
249
263
|
- !ruby/object:Gem::Version
|
250
|
-
version:
|
264
|
+
version: '4'
|
251
265
|
- !ruby/object:Gem::Dependency
|
252
266
|
name: toml
|
253
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -429,6 +443,7 @@ files:
|
|
429
443
|
- lib/dato/upload/create_upload_path.rb
|
430
444
|
- lib/dato/upload/file.rb
|
431
445
|
- lib/dato/upload/image.rb
|
446
|
+
- lib/dato/utils/build_modular_block.rb
|
432
447
|
- lib/dato/utils/favicon_tags_builder.rb
|
433
448
|
- lib/dato/utils/locale_value.rb
|
434
449
|
- lib/dato/utils/meta_tags/article_modified_time.rb
|
@@ -464,8 +479,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
464
479
|
- !ruby/object:Gem::Version
|
465
480
|
version: '0'
|
466
481
|
requirements: []
|
467
|
-
|
468
|
-
rubygems_version: 2.7.6
|
482
|
+
rubygems_version: 3.0.3
|
469
483
|
signing_key:
|
470
484
|
specification_version: 4
|
471
485
|
summary: Ruby client for DatoCMS API
|