class Contentful::Moderator::Controller
Public Instance Methods
auto_save()
click to toggle source
# File lib/contentful/moderator/controller.rb, line 7 def auto_save return unless webhook.entry? return unless notificable?(webhook) logger.debug("Workflow Webhook Received for '#{webhook.space_id}/#{webhook.id}': Checking for Notifications") emails = [] emails << notify_authors(webhook) if notify_author?(webhook) emails << notify_reviewers(webhook) if notify_reviewer?(webhook) send_emails(emails) logger.debug("\tDone!") end
Also aliased as: save
config()
click to toggle source
# File lib/contentful/moderator/controller.rb, line 22 def config ::Contentful::Moderator.config end
content_type(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 62 def content_type(webhook) config.content_types[webhook_content_type(webhook)] end
email_body(type, webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 54 def email_body(type, webhook) self.send("#{type}_field", webhook).email_body.gsub("'webhook_url'", webhook_url(webhook)) end
notificable?(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 66 def notificable?(webhook) config.content_types.keys.include?(webhook_content_type(webhook)) end
notify_reviewer?(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 79 def notify_reviewer?(webhook) field = webhook.fields[author_field(webhook).field_id] if field.is_a? Hash return field[field.keys.first] == author_field(webhook).notify_reviewer_on else return field == author_field(webhook).notify_reviewer_on end end
notify_reviewers(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 43 def notify_reviewers(webhook) logger.debug("\tCreating Reviewer Notification Email") this = self ::Mail.new do from this.config.mail_origin to this.config.editors subject this.author_field(webhook).email_subject body this.email_body(:author, webhook) end end
reviewer_field(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 92 def reviewer_field(webhook) content_type(webhook).reviewer_field end
send_emails(emails)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 26 def send_emails(emails) emails.each do |email| email.deliver! end end
webhook_content_type(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 58 def webhook_content_type(webhook) webhook.sys['contentType']['sys']['id'] end
webhook_url(webhook)
click to toggle source
# File lib/contentful/moderator/controller.rb, line 96 def webhook_url(webhook) "https://app.contentful.com/spaces/#{webhook.space_id}/entries/#{webhook.id}" end