consyncful 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2f62207463a8f75a74abef31265619b16425ef9b8cfa9cecc8935ab8fd74937
4
- data.tar.gz: 5eca96bb788eb38855afa49cafaf5091eabbb5343f09828266f4f7e95cba3d29
3
+ metadata.gz: 7098621f9a1f36a61f658c4897016b0b578e30003a2e0efd84aca0c5c7385088
4
+ data.tar.gz: 6017ae2bb5a5565555d6fb264815d650bca697bd781b855f1b4df622ecc2c61f
5
5
  SHA512:
6
- metadata.gz: 2c9188b10e74d92bf2078e3227ecf7f189a749e088a5a64990f7f66fe0256eccc9628b07cb287ef78307f15287c2a7f57992688170b574e802fbc5f03b916508
7
- data.tar.gz: a63b5e7ddca0cab2dc969b8a83b48ca66c4957b7641ddf7caa6be22e45733cb9bebb405187bb867280bd5149b2c2b2bd2e7399694df80fba39e1874979887dbd
6
+ metadata.gz: 1938e0faa4a541d1f8c2070c81ecf5cd67ac2bc677cccd85eeb39c5d90d633ac9a2c3468f9880335f7a1090e32bcc5dbe56eef8ca1dc8c8742151798106f4a32
7
+ data.tar.gz: bfa6e4d41df6a91434411ef58a2eacd6a790eec522f3b392754d3fc2bf496ec79e436b3c0d95d527a61e74c9900a51cdae6b29fd8ed415fd8fb523cd8134d390
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consyncful (0.7.2)
4
+ consyncful (0.8.0)
5
5
  contentful (>= 2.11.1, < 3.0.0)
6
6
  hooks (>= 0.4.1)
7
- mongoid (>= 7.0.2, < 8.0.0)
7
+ mongoid (>= 7.0.2, < 9.0.0)
8
8
  rainbow
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activemodel (7.0.3)
14
- activesupport (= 7.0.3)
15
- activesupport (7.0.3)
13
+ activemodel (7.0.4.2)
14
+ activesupport (= 7.0.4.2)
15
+ activesupport (7.0.4.2)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
19
19
  tzinfo (~> 2.0)
20
- addressable (2.8.0)
21
- public_suffix (>= 2.0.2, < 5.0)
20
+ addressable (2.8.1)
21
+ public_suffix (>= 2.0.2, < 6.0)
22
22
  ast (2.4.2)
23
23
  bson (4.15.0)
24
- concurrent-ruby (1.1.10)
24
+ concurrent-ruby (1.2.0)
25
25
  contentful (2.16.3)
26
26
  http (> 0.8, < 5.0)
27
27
  multi_json (~> 1)
@@ -47,18 +47,18 @@ GEM
47
47
  ffi-compiler (>= 1.0, < 2.0)
48
48
  i18n (1.12.0)
49
49
  concurrent-ruby (~> 1.0)
50
- minitest (5.16.2)
51
- mongo (2.17.1)
52
- bson (>= 4.8.2, < 5.0.0)
53
- mongoid (7.4.0)
50
+ minitest (5.17.0)
51
+ mongo (2.18.2)
52
+ bson (>= 4.14.1, < 5.0.0)
53
+ mongoid (8.0.3)
54
54
  activemodel (>= 5.1, < 7.1, != 7.0.0)
55
- mongo (>= 2.10.5, < 3.0.0)
55
+ mongo (>= 2.18.0, < 3.0.0)
56
56
  ruby2_keywords (~> 0.0.5)
57
57
  multi_json (1.15.0)
58
58
  parallel (1.22.1)
59
59
  parser (3.1.2.0)
60
60
  ast (~> 2.4.1)
61
- public_suffix (4.0.7)
61
+ public_suffix (5.0.1)
62
62
  rainbow (3.1.1)
63
63
  rake (13.0.1)
64
64
  regexp_parser (2.3.1)
@@ -93,7 +93,7 @@ GEM
93
93
  rubocop (~> 1.19)
94
94
  ruby-progressbar (1.11.0)
95
95
  ruby2_keywords (0.0.5)
96
- tzinfo (2.0.4)
96
+ tzinfo (2.0.6)
97
97
  concurrent-ruby (~> 1.0)
98
98
  uber (0.0.15)
99
99
  unf (0.1.4)
data/README.md CHANGED
@@ -42,7 +42,7 @@ If you don't already use Mongoid, generate a mongoid.yml by running:
42
42
 
43
43
  Add an initializer:
44
44
 
45
- Consyncful uses [contentful.rb](https://github.com/contentful/contentful.rb); client options are as documented there.
45
+ Consyncful uses [contentful.rb](https://github.com/contentful/contentful.rb); client options are as documented there. Sync options are documented in the [Content Delivery Sync API docs](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization).
46
46
  ```rb
47
47
  Consyncful.configure do |config|
48
48
  config.locale = 'en-NZ'
@@ -53,6 +53,11 @@ Consyncful.configure do |config|
53
53
  environment: 'master', # optional
54
54
  logger: Logger.new(STDOUT) # optional for debugging
55
55
  }
56
+
57
+ # optional to override the Sync API defaults
58
+ config.contentful_sync_options = {
59
+ limit: 50
60
+ }
56
61
  end
57
62
  ```
58
63
 
data/consyncful.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
 
42
42
  spec.add_dependency 'contentful', ['>=2.11.1', '<3.0.0']
43
43
  spec.add_dependency 'hooks', '>=0.4.1'
44
- spec.add_dependency 'mongoid', ['>=7.0.2', '<8.0.0']
44
+ spec.add_dependency 'mongoid', ['>=7.0.2', '<9.0.0']
45
45
  spec.add_dependency 'rainbow'
46
46
  spec.metadata['rubygems_mfa_required'] = 'true'
47
47
  end
@@ -83,13 +83,17 @@ module Consyncful
83
83
  end
84
84
 
85
85
  def start_sync
86
- if next_url.present?
87
- puts Rainbow("Starting update, last update: #{last_run_at} (#{(Time.current - last_run_at).round(3)}s ago)").blue
88
- Consyncful.client.sync(next_url)
89
- else
90
- puts Rainbow('Starting full refresh').blue
91
- Consyncful.client.sync(initial: true)
92
- end
86
+ next_url.present? ? start_update : start_new_sync
87
+ end
88
+
89
+ def start_update
90
+ puts Rainbow("Starting update, last update: #{last_run_at} (#{(Time.current - last_run_at).round(3)}s ago)").blue
91
+ Consyncful.client.sync(next_url)
92
+ end
93
+
94
+ def start_new_sync
95
+ puts Rainbow('Starting full refresh').blue
96
+ Consyncful.client.sync(Consyncful.configuration.initial_sync_options)
93
97
  end
94
98
 
95
99
  def sync_items(sync, stats)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Consyncful
4
- VERSION = '0.7.2'
4
+ VERSION = '0.8.0'
5
5
  end
data/lib/consyncful.rb CHANGED
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'consyncful/version'
4
-
5
4
  require 'mongoid'
6
5
  require 'contentful'
7
-
8
6
  require 'consyncful/base'
9
7
  require 'consyncful/sync'
10
-
11
8
  require 'consyncful/railtie' if defined?(Rails)
12
9
 
13
10
  module Consyncful
14
11
  # Handles Rails configurations for Consynful
15
12
  class Configuration
16
13
  attr_accessor :contentful_client_options,
14
+ :contentful_sync_options,
17
15
  :locale,
18
16
  :mongo_client,
19
17
  :mongo_collection,
@@ -22,9 +20,8 @@ module Consyncful
22
20
  :preserve_contentful_timestamps
23
21
 
24
22
  def initialize
25
- @contentful_client_options = {
26
- api_url: 'cdn.contentful.com'
27
- }
23
+ @contentful_client_options = {}
24
+ @contentful_sync_options = {}
28
25
  @locale = 'en-NZ'
29
26
  @mongo_client = :default
30
27
  @mongo_collection = 'contentful_models'
@@ -32,6 +29,17 @@ module Consyncful
32
29
  @ignore_content_tags = []
33
30
  @preserve_contentful_timestamps = false
34
31
  end
32
+
33
+ def initial_sync_options
34
+ options = { initial: true }
35
+ options = options.reverse_merge(@contentful_sync_options)
36
+ options.reverse_merge(DEFAULT_SYNC_OPTIONS)
37
+ end
38
+
39
+ def client_options
40
+ options = @contentful_client_options
41
+ options.reverse_merge!(DEFAULT_CLIENT_OPTIONS)
42
+ end
35
43
  end
36
44
 
37
45
  DEFAULT_CLIENT_OPTIONS = {
@@ -39,6 +47,12 @@ module Consyncful
39
47
  api_url: 'cdn.contentful.com'
40
48
  }.freeze
41
49
 
50
+ # see https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization
51
+ DEFAULT_SYNC_OPTIONS = {
52
+ limit: 100,
53
+ type: 'all'
54
+ }.freeze
55
+
42
56
  class << self
43
57
  def configuration
44
58
  @configuration ||= Configuration.new
@@ -49,11 +63,7 @@ module Consyncful
49
63
  end
50
64
 
51
65
  def client
52
- @client ||= begin
53
- options = Consyncful.configuration.contentful_client_options
54
- options.reverse_merge!(DEFAULT_CLIENT_OPTIONS)
55
- Contentful::Client.new(options)
56
- end
66
+ @client ||= Contentful::Client.new(Consyncful.configuration.client_options)
57
67
  end
58
68
  end
59
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consyncful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Anastasiadis-Gray
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-24 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,7 +151,7 @@ dependencies:
151
151
  version: 7.0.2
152
152
  - - "<"
153
153
  - !ruby/object:Gem::Version
154
- version: 8.0.0
154
+ version: 9.0.0
155
155
  type: :runtime
156
156
  prerelease: false
157
157
  version_requirements: !ruby/object:Gem::Requirement
@@ -161,7 +161,7 @@ dependencies:
161
161
  version: 7.0.2
162
162
  - - "<"
163
163
  - !ruby/object:Gem::Version
164
- version: 8.0.0
164
+ version: 9.0.0
165
165
  - !ruby/object:Gem::Dependency
166
166
  name: rainbow
167
167
  requirement: !ruby/object:Gem::Requirement