contentful-scheduler-custom 1.6.116 → 1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/contentful-scheduler.gemspec +1 -0
- data/lib/contentful/scheduler/queue.rb +1 -2
- data/lib/contentful/scheduler/tasks/publish.rb +29 -6
- data/lib/contentful/scheduler/tasks/unpublish.rb +29 -6
- data/lib/contentful/scheduler/taskshelper.rb +31 -0
- data/lib/contentful/scheduler/version.rb +2 -2
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3da54c37d419eee61f8c110cb58fb927d2b75ac49ab5f0f714950658299e6b7e
|
4
|
+
data.tar.gz: 82fdd3836f5597dfad53cac1ddb6e73612b7df656ca7cbd6acd5dae602a3193a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
+
|
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.
|
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-
|
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
|