contentful-scheduler 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -7
- data/lib/contentful/scheduler/queue.rb +4 -11
- data/lib/contentful/scheduler/version.rb +1 -1
- data/spec/contentful/scheduler/queue_spec.rb +2 -36
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd007e6c6d4a25ead5ebc991d556bcf0c54999ff
|
4
|
+
data.tar.gz: d1c46c66389f3e0e3156a74452c481677471df8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a93a782354a79b12c9c939ff29574a6fd647544865fad71447c5bac64af3f08e30ef666bb3a34581a835a4e95fb96918b1530e96558d11169e7cc6765b854ee2
|
7
|
+
data.tar.gz: f7a8ed7913141c24f9fc040d17232d451842a6ce4d4f4f80781b7158ea3990ce651466bcdef68eb299d85c9d2a32846ff593e12a6755ce276f9b62ee61f24f6a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,19 +3,19 @@
|
|
3
3
|
Scheduling Server for Contentful entries.
|
4
4
|
|
5
5
|
## Contentful
|
6
|
-
[Contentful](
|
7
|
-
mobile apps and connected devices. It allows you to create, edit & manage content in the cloud
|
8
|
-
and publish it anywhere via powerful API. Contentful offers tools for managing editorial
|
9
|
-
teams and enabling cooperation between organizations.
|
6
|
+
[Contentful](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
|
10
7
|
|
11
8
|
## What does `contentful-scheduler` do?
|
12
9
|
The aim of `contentful-scheduler` is to have developers setting up their Contentful
|
13
10
|
entries for scheduled publishing.
|
14
11
|
|
15
12
|
## How does it work
|
16
|
-
`contentful-scheduler` provides a web endpoint to receive webhook calls from Contentful
|
17
|
-
|
18
|
-
|
13
|
+
`contentful-scheduler` provides a web endpoint to receive webhook calls from Contentful.
|
14
|
+
|
15
|
+
Every time the endpoint recieves a call it looks for the value of the field defined in the configuration.
|
16
|
+
If the value is a time in the future -- and if the entry has not already been published -- it will schedule
|
17
|
+
the entry for publishing at the specified time.
|
18
|
+
|
19
19
|
A background worker based on the popular `resque` gem will then proceed to actually make the publish call
|
20
20
|
against the Content Management API at the due time. For this the Entries you wish to publish require a
|
21
21
|
customizable Date field, which we advice to call `publishDate`, this field can be configured inside your
|
@@ -16,7 +16,7 @@ module Contentful
|
|
16
16
|
def update_or_create(webhook)
|
17
17
|
return unless publishable?(webhook)
|
18
18
|
remove(webhook) if in_queue?(webhook)
|
19
|
-
return
|
19
|
+
return unless publish_is_future?(webhook)
|
20
20
|
|
21
21
|
success = Resque.enqueue_at(
|
22
22
|
publish_date(webhook),
|
@@ -55,21 +55,14 @@ module Contentful
|
|
55
55
|
return false unless spaces.key?(webhook.space_id)
|
56
56
|
|
57
57
|
if webhook_publish_field?(webhook)
|
58
|
-
return !webhook_publish_field(webhook).nil?
|
58
|
+
return !webhook_publish_field(webhook).nil? && publish_is_future?(webhook)
|
59
59
|
end
|
60
60
|
|
61
61
|
false
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
65
|
-
|
66
|
-
return false unless webhook.sys.key?('publishedAt')
|
67
|
-
|
68
|
-
if !webhook.sys['publishedAt'].nil?
|
69
|
-
return Chronic.parse(webhook.sys['publishedAt']).utc < Time.now.utc
|
70
|
-
end
|
71
|
-
|
72
|
-
false
|
64
|
+
def publish_is_future?(webhook)
|
65
|
+
publish_date(webhook) > Time.now.utc
|
73
66
|
end
|
74
67
|
|
75
68
|
def in_queue?(webhook)
|
@@ -100,32 +100,6 @@ describe Contentful::Scheduler::Queue do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe '#already_published?' do
|
104
|
-
it 'true if webhook publish_date is in past' do
|
105
|
-
expect(subject.already_published?(
|
106
|
-
WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2011-04-04T22:00:00+00:00'})
|
107
|
-
)).to be_truthy
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'true if sys.publishedAt is in past' do
|
111
|
-
expect(subject.already_published?(
|
112
|
-
WebhookDouble.new('bar', 'foo', {'publishedAt' => '2011-04-04T22:00:00+00:00'}, {'my_field' => '2099-04-04T22:00:00+00:00'})
|
113
|
-
)).to be_truthy
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'false if sys.publishedAt is not present' do
|
117
|
-
expect(subject.already_published?(
|
118
|
-
WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2099-04-04T22:00:00+00:00'})
|
119
|
-
)).to be_falsey
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'false if sys.publishedAt is present but nil' do
|
123
|
-
expect(subject.already_published?(
|
124
|
-
WebhookDouble.new('bar', 'foo', {'publishedAt' => nil}, {'my_field' => '2099-04-04T22:00:00+00:00'})
|
125
|
-
)).to be_falsey
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
103
|
describe '#publishable?' do
|
130
104
|
it 'false if webhook space not present in config' do
|
131
105
|
expect(subject.publishable?(
|
@@ -147,7 +121,7 @@ describe Contentful::Scheduler::Queue do
|
|
147
121
|
|
148
122
|
it 'true if publish_field is populated' do
|
149
123
|
expect(subject.publishable?(
|
150
|
-
WebhookDouble.new('bar', 'foo', {}, {'my_field' => '
|
124
|
+
WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2111-04-04T22:00:00+00:00'})
|
151
125
|
)).to be_truthy
|
152
126
|
end
|
153
127
|
end
|
@@ -221,14 +195,6 @@ describe Contentful::Scheduler::Queue do
|
|
221
195
|
|
222
196
|
subject.update_or_create(WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2099-04-04T22:00:00+00:00'}))
|
223
197
|
end
|
224
|
-
|
225
|
-
it 'removes old call if already published' do
|
226
|
-
allow(Resque).to receive(:peek) { [{'args' => ['foo', 'bar']}] }
|
227
|
-
expect(Resque).not_to receive(:enqueue_at)
|
228
|
-
expect(subject).to receive(:remove)
|
229
|
-
|
230
|
-
subject.update_or_create(WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2011-04-04T22:00:00+00:00'}))
|
231
|
-
end
|
232
198
|
end
|
233
199
|
end
|
234
200
|
|
@@ -250,7 +216,7 @@ describe Contentful::Scheduler::Queue do
|
|
250
216
|
allow(Resque).to receive(:peek) { [{'args' => ['foo', 'bar']}] }
|
251
217
|
expect(Resque).to receive(:remove_delayed)
|
252
218
|
|
253
|
-
subject.remove(WebhookDouble.new('bar', 'foo', {}, {'my_field' => '
|
219
|
+
subject.remove(WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2111-04-04T22:00:00+00:00'}))
|
254
220
|
end
|
255
221
|
end
|
256
222
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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:
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contentful-webhook-listener
|