Class: Contentful::Scheduler::Tasks::Publish

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/scheduler/tasks/publish.rb

Class Method Summary collapse

Class Method Details

.perform(space_id, entry_id, token) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contentful/scheduler/tasks/publish.rb', line 12

def self.perform(space_id, entry_id, token)

  logger = ::Contentful::Scheduler.config[:logger]
  access_token = ::Contentful::Scheduler.config[:spaces][space_id][:delivery_token]

  client = Contentful::Client.new(
      space: space_id,
      access_token: access_token
  )

  clientManagement = ::Contentful::Management::Client.new(
      token,
      raise_errors: true,
      application_name: 'contentful.scheduler',
      application_version: Contentful::Scheduler::VERSION
  )

  linked_entries = client.entries(links_to_entry: entry_id)

  if !linked_entries.raw["includes"].nil? && !linked_entries.raw["includes"]["Entry"].nil?
    linked_entries_ids = Taskshelper.extract_element_ids(linked_entries.raw["includes"]["Entry"])
    logger.info("Linked enteries for entry_id ==>> #{entry_id} are ==>> #{linked_entries_ids}")
    linked_entries_ids.each do |id|
      logger.info"Publishing linked entry with id #{id}"
      clientManagement.entries.find(space_id, id).publish
    end
  end

  clientManagement.entries.find(space_id, entry_id).publish
end