dato 0.7.10 → 0.7.13

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: 3c0c8876b3874673682917304166e526920fde1a607306d8a75335f6e92dbcdc
4
- data.tar.gz: 25ff226def0f2c3633bce0b17053bc0734516639991d7530e32a482e78aa17a0
3
+ metadata.gz: 8911d925c9122207b1b12804415839e1a60c6f42212523f8a9d8590a0ac3b609
4
+ data.tar.gz: fcb4dfbed9102fd7c037c635bb0a436ea8c5671964e51e7dcf1c9b7345f25471
5
5
  SHA512:
6
- metadata.gz: d07b5291010a9703bb29449425836fde87132d3776f5b7f7ed5479340f2935cfbde6e98ac0868ecfca68f767cf969844dba118ea66beb6acb8c785dfc6cd9e77
7
- data.tar.gz: 57ee98d19caf26eefaee762afb46fd44448400d600858386526fafc56f163df330249efb16d6362a6a6b393b76b7c6d4b84e6f5e724ab9e09521819332b678df
6
+ metadata.gz: 127d2b647b57bbf530f3def61fefd302f763ec0ead035dc0f7a3d53cb6d6646948a994a75c5b6f22533e815e35a1a27a1d1f6cb0b85f2eedb86e8985971bbc87
7
+ data.tar.gz: 9709363be3b119354890d3d1de8a16bd8a020faf3e58692022e50de1ba25dcd4af6c49f1962e03cd8e8b82f35334140efa61cd7ff9f3f9835b39c5901b3e904b
@@ -1,3 +1,42 @@
1
+ # 0.7.13
2
+
3
+ Add option to pass a project's environment:
4
+
5
+ ```ruby
6
+ require "dato"
7
+ client = Dato::Site::Client.new("YOUR-API-KEY", environment: 'sandbox-foobar')
8
+ ```
9
+
10
+ # 0.7.12
11
+
12
+ Introduces `Dato::Utils::BuildModularBlock` class to help creating modular blocks.
13
+
14
+ An example usage can be:
15
+
16
+ ```ruby
17
+ description = [
18
+ Dato::Utils::BuildModularBlock.build(
19
+ item_type: "1235",
20
+ name: "Best dog in the world",
21
+ year: "2020",
22
+ picture: picture
23
+ )
24
+ ]
25
+
26
+ record = client.items.create(
27
+ item_type: "1234", # model ID
28
+ name: "Gigio",
29
+ description: description
30
+ )
31
+ ```
32
+
33
+ Find more info [on the documentation](https://www.datocms.com/docs/content-management-api/resources/item/create).
34
+
35
+ # 0.7.11 (not released)
36
+
37
+ * Updated specs cassettes after `appeareance -> appearance` typo fix
38
+ * Some style changes
39
+
1
40
  # 0.7.10
2
41
 
3
42
  * Fixed SEO title retrieval. Now it fallbacks to default SEO title is item title is blank
@@ -8,6 +8,7 @@ require 'dato/local/site'
8
8
  require 'dato/cli'
9
9
  require 'dato/utils/seo_tags_builder'
10
10
  require 'dato/utils/favicon_tags_builder'
11
+ require 'dato/utils/build_modular_block'
11
12
 
12
13
  module Dato
13
14
  end
@@ -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, schema|
45
- is_collection = schema.links.select { |x| x.rel === 'instances' }.any?
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, schema)
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 "Validating items, waiting 1 second and retrying..."
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["data"]
121
+ return false unless body['data']
127
122
 
128
- body["data"].any? do |e|
129
- e["attributes"]["code"] == "BATCH_DATA_VALIDATION_IN_PROGRESS"
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|
@@ -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
@@ -43,7 +43,13 @@ module Dato
43
43
 
44
44
  return if pusher && pusher.connected
45
45
 
46
- pusher.subscribe("private-site-#{site_id}")
46
+ channel_name = if client.environment
47
+ "private-site-#{site_id}-environment-#{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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dato
4
- VERSION = '0.7.10'
4
+ VERSION = '0.7.13'
5
5
  end
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.10
4
+ version: 0.7.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -429,6 +429,7 @@ files:
429
429
  - lib/dato/upload/create_upload_path.rb
430
430
  - lib/dato/upload/file.rb
431
431
  - lib/dato/upload/image.rb
432
+ - lib/dato/utils/build_modular_block.rb
432
433
  - lib/dato/utils/favicon_tags_builder.rb
433
434
  - lib/dato/utils/locale_value.rb
434
435
  - lib/dato/utils/meta_tags/article_modified_time.rb