contentful-scheduler 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: 14dd6e0b1a4ab640ac6dc86da32aaf78dd662b24
4
- data.tar.gz: b29d84702d42a542f8e19dcb2702e47fc87cf6d1
3
+ metadata.gz: bd007e6c6d4a25ead5ebc991d556bcf0c54999ff
4
+ data.tar.gz: d1c46c66389f3e0e3156a74452c481677471df8e
5
5
  SHA512:
6
- metadata.gz: '087d6c529736e060a0a9b5994a0399459907030276ae1bc5d6654f5fb44b178ebbc086f1e472bf3b629c0d51fa247dfeab587b6dfc609201acfd8acb021c61f6'
7
- data.tar.gz: 62eb5b0c1828c8e6d323d0b595dc684a20ea80b4f2cde62d716671373d5d1c9dd8375919c80762bff5ccada05dd8a88c67972964ef51ed3954a067254808d541
6
+ metadata.gz: a93a782354a79b12c9c939ff29574a6fd647544865fad71447c5bac64af3f08e30ef666bb3a34581a835a4e95fb96918b1530e96558d11169e7cc6765b854ee2
7
+ data.tar.gz: f7a8ed7913141c24f9fc040d17232d451842a6ce4d4f4f80781b7158ea3990ce651466bcdef68eb299d85c9d2a32846ff593e12a6755ce276f9b62ee61f24f6a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.3.0
6
+ ### Added
7
+ * Added possibility to republish already published content. [#5](https://github.com/contentful/contentful-scheduler.rb/issues/5)
8
+
5
9
  ## 0.2.1
6
10
 
7
11
  ### Fixed
data/README.md CHANGED
@@ -3,19 +3,19 @@
3
3
  Scheduling Server for Contentful entries.
4
4
 
5
5
  ## Contentful
6
- [Contentful](http://www.contentful.com) is a content management platform for web applications,
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
- every time the endpoint recieves a call it looks for the value of the field defined in the configuration,
18
- if the value is a time in the future it will schedule the entry for publishing at the specified time.
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 if already_published?(webhook)
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 already_published?(webhook)
65
- return true if publish_date(webhook) < Time.now.utc
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)
@@ -1,5 +1,5 @@
1
1
  module Contentful
2
2
  module Scheduler
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -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' => '2011-04-04T22:00:00+00:00'})
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' => '2011-04-04T22:00:00+00:00'}))
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.2.1
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: 2017-11-02 00:00:00.000000000 Z
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