contentful-scheduler-custom 1.6.116 → 1.7

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: 7f8a7d88bc6392835f76f171fabfde5aed9d64f59c5606a89aaefb07e43d7230
4
- data.tar.gz: 3a9d7ccbfe3d5ad7e3a80bccf7a8f69cd776e89b4323dc55f3a26129103144cc
3
+ metadata.gz: 3da54c37d419eee61f8c110cb58fb927d2b75ac49ab5f0f714950658299e6b7e
4
+ data.tar.gz: 82fdd3836f5597dfad53cac1ddb6e73612b7df656ca7cbd6acd5dae602a3193a
5
5
  SHA512:
6
- metadata.gz: d0cbdcf5cffb8fd674b7cfba28fccaea2166625cb1e250a511e649d39862e477644085f6a5e5a660e3baef6683cd08d4fd357fb2cccf1c807bbbb0479c7273d4
7
- data.tar.gz: 227a4780d34a1c5becc8029bd538e810a8a49a1ee183b6a3b5e1d8e86bd936e1ea59bec7aefa4f5d44c7031d466be73a245a7c10521595d1f695f1747eb1a795
6
+ metadata.gz: 33c4f182623da852a81486e6fe1b6e9b5c9f8e1586866d5bbf65b28d52b6a31b440ce2c5e917dc22ff118217ceb97f8b1e18ef42616c2d587439c39b8e723545
7
+ data.tar.gz: 1be3647f52670146eb513671d3f9c66ee1bfdc70f1e03548ef918385b792f85c46c169e308207acab2433333cf6ae44b3e39eb1eaa10ccc8b2a382e9d9e242d5
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_runtime_dependency "contentful", "~> 2.11.1"
22
23
  spec.add_runtime_dependency "contentful-webhook-listener", "~> 0.2"
23
24
  spec.add_runtime_dependency "contentful-management", "~> 1.8"
24
25
  spec.add_runtime_dependency "resque", "~> 1.27.4"
@@ -1,5 +1,4 @@
1
- require_relative "tasks"
2
- require_relative "tasks"
1
+ require_relative 'tasks'
3
2
  require 'chronic'
4
3
  require 'contentful/webhook/listener'
5
4
 
@@ -1,4 +1,7 @@
1
1
  require 'contentful/management'
2
+ require 'contentful'
3
+ require 'logger'
4
+ require_relative '../taskshelper'
2
5
 
3
6
  module Contentful
4
7
  module Scheduler
@@ -7,13 +10,33 @@ module Contentful
7
10
  @queue = :publish
8
11
 
9
12
  def self.perform(space_id, entry_id, token)
10
- client = ::Contentful::Management::Client.new(
11
- token,
12
- raise_errors: true,
13
- application_name: 'contentful.scheduler',
14
- application_version: Contentful::Scheduler::VERSION
13
+
14
+ logger = Logger.new(STDOUT)
15
+
16
+ client = Contentful::Client.new(
17
+ space: space_id,
18
+ access_token: ::Contentful::Scheduler.config[:spaces][space_id][:delivery_token]
19
+ )
20
+
21
+ clientManagement = ::Contentful::Management::Client.new(
22
+ token,
23
+ raise_errors: true,
24
+ application_name: 'contentful.scheduler',
25
+ application_version: Contentful::Scheduler::VERSION
15
26
  )
16
- client.entries(include: 3).find(space_id, entry_id).publish
27
+
28
+ linked_entries = client.entries(links_to_entry: entry_id)
29
+
30
+ if !linked_entries.raw["includes"].nil? && !linked_entries.raw["includes"]["Entry"].nil?
31
+ linked_entries_ids = Taskshelper.extract_element_ids(linked_entries.raw["includes"]["Entry"])
32
+ logger.info("Linked enteries for entry_id ==>> #{entry_id} are ==>> #{linked_entries_ids}")
33
+ linked_entries_ids.each do |id|
34
+ logger.info"Publishing linked entry with id #{id}"
35
+ clientManagement.entries.find(space_id, id).publish
36
+ end
37
+ end
38
+
39
+ clientManagement.entries.find(space_id, entry_id).publish
17
40
  end
18
41
  end
19
42
  end
@@ -1,4 +1,7 @@
1
1
  require 'contentful/management'
2
+ require 'contentful'
3
+ require 'logger'
4
+ require_relative '../taskshelper'
2
5
 
3
6
  module Contentful
4
7
  module Scheduler
@@ -7,13 +10,33 @@ module Contentful
7
10
  @queue = :unpublish
8
11
 
9
12
  def self.perform(space_id, entry_id, token)
10
- client = ::Contentful::Management::Client.new(
11
- token,
12
- raise_errors: true,
13
- application_name: 'contentful.scheduler',
14
- application_version: Contentful::Scheduler::VERSION
13
+
14
+ logger = Logger.new(STDOUT)
15
+
16
+ client = Contentful::Client.new(
17
+ space: space_id,
18
+ access_token: ::Contentful::Scheduler.config[:spaces][space_id][:delivery_token]
19
+ )
20
+
21
+ clientManagement = ::Contentful::Management::Client.new(
22
+ token,
23
+ raise_errors: true,
24
+ application_name: 'contentful.scheduler',
25
+ application_version: Contentful::Scheduler::VERSION
15
26
  )
16
- client.entries(include: 3).find(space_id, entry_id).unpublish
27
+
28
+ linked_entries = client.entries(links_to_entry: entry_id)
29
+
30
+ if !linked_entries.raw["includes"].nil? && !linked_entries.raw["includes"]["Entry"].nil?
31
+ linked_entries_ids = Taskshelper.extract_element_ids(linked_entries.raw["includes"]["Entry"])
32
+ logger.info("Linked enteries for entry_id ==>> #{entry_id} are ==>> #{linked_entries_ids}")
33
+ linked_entries_ids.each do |id|
34
+ logger.info"Unpublishing linked entry with id #{id}"
35
+ clientManagement.entries.find(space_id, id).unpublish
36
+ end
37
+ end
38
+
39
+ clientManagement.entries.find(space_id, entry_id).unpublish
17
40
  end
18
41
  end
19
42
  end
@@ -0,0 +1,31 @@
1
+ module Contentful
2
+ module Scheduler
3
+ module Taskshelper
4
+ def Taskshelper.extract_element_ids input_array
5
+ ids = []
6
+ input_array.each {|item| (ids << (Taskshelper.get_each_field item)).flatten!}
7
+ return ids.uniq
8
+ end
9
+
10
+ def Taskshelper.get_each_field item
11
+ ids = []
12
+ keys = item["fields"].keys
13
+ keys.each {|key| (ids << (Taskshelper.get_each_element key, item["fields"])).flatten!}
14
+ return ids
15
+ end
16
+
17
+ def Taskshelper.get_each_element key, item
18
+ ids = []
19
+ if item[key].is_a?(::Array)
20
+ item[key].each do |i|
21
+ (!(i["sys"]["linkType"].nil?) && i["sys"]["linkType"] == "Entry") ? ids.push(i["sys"]["id"]) : nil
22
+ end
23
+ elsif item[key].is_a?(::Hash)
24
+ (!(item[key]["sys"]["linkType"].nil?) && item[key]["sys"]["linkType"] == "Entry") ? ids.push(item[key]["sys"]["id"]) : nil
25
+ end
26
+ return ids
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -1,5 +1,5 @@
1
1
  module Contentful
2
2
  module Scheduler
3
- VERSION = "1.6.116"
3
+ VERSION = "1.7"
4
4
  end
5
- end
5
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful-scheduler-custom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.116
4
+ version: '1.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (David Litvak Bruno0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-07 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: contentful
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.11.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.11.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: contentful-webhook-listener
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -208,6 +222,7 @@ files:
208
222
  - lib/contentful/scheduler/tasks.rb
209
223
  - lib/contentful/scheduler/tasks/publish.rb
210
224
  - lib/contentful/scheduler/tasks/unpublish.rb
225
+ - lib/contentful/scheduler/taskshelper.rb
211
226
  - lib/contentful/scheduler/version.rb
212
227
  - spec/contentful/scheduler/auth_spec.rb
213
228
  - spec/contentful/scheduler/controller_spec.rb