Module: Contentful::Management::Resource::Publisher

Included in:
Asset, ContentType, Entry
Defined in:
lib/contentful/management/resource/publisher.rb

Overview

Wrapper for Resources with /published API

Instance Method Summary collapse

Instance Method Details

#publishContentful::Management::Resource

Publishes a resource.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/contentful/management/resource/publisher.rb', line 11

def publish
  ResourceRequester.new(client, self.class).publish(
    self,
    {
      space_id: space.id,
      environment_id: environment_id,
      resource_id: id,
      suffix: '/published'
    },
    version: sys[:version]
  )
end

#published?Boolean

Checks if a resource is published.

Returns:

  • (Boolean)


43
44
45
# File 'lib/contentful/management/resource/publisher.rb', line 43

def published?
  sys[:publishedAt] ? true : false
end

#unpublishContentful::Management::Resource

Unpublishes a resource.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/contentful/management/resource/publisher.rb', line 27

def unpublish
  ResourceRequester.new(client, self.class).unpublish(
    self,
    {
      space_id: space.id,
      environment_id: environment_id,
      resource_id: id,
      suffix: '/published'
    },
    version: sys[:version]
  )
end

#updated?Boolean

Checks if a resource has been updated since last publish. Returns false if resource has not been published before.

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/contentful/management/resource/publisher.rb', line 51

def updated?
  return false unless sys[:publishedAt]

  sanitize_date(sys[:publishedAt]) < sanitize_date(sys[:updatedAt])
end