Class: Contentful::Moderator::Controller
- Inherits:
-
Webhook::Listener::Controllers::WebhookAware
- Object
- Webhook::Listener::Controllers::WebhookAware
- Contentful::Moderator::Controller
- Defined in:
- lib/contentful/moderator/controller.rb
Instance Method Summary collapse
- #author_field(webhook) ⇒ Object
- #auto_save ⇒ Object (also: #save)
- #config ⇒ Object
- #content_type(webhook) ⇒ Object
- #email_body(type, webhook) ⇒ Object
- #notificable?(webhook) ⇒ Boolean
- #notify_author?(webhook) ⇒ Boolean
- #notify_authors(webhook) ⇒ Object
- #notify_reviewer?(webhook) ⇒ Boolean
- #notify_reviewers(webhook) ⇒ Object
- #reviewer_field(webhook) ⇒ Object
- #send_emails(emails) ⇒ Object
- #webhook_content_type(webhook) ⇒ Object
- #webhook_url(webhook) ⇒ Object
Instance Method Details
#author_field(webhook) ⇒ Object
88 89 90 |
# File 'lib/contentful/moderator/controller.rb', line 88 def (webhook) content_type(webhook). end |
#auto_save ⇒ Object Also known as: save
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 << (webhook) if (webhook) emails << notify_reviewers(webhook) if notify_reviewer?(webhook) send_emails(emails) logger.debug("\tDone!") end |
#config ⇒ Object
22 23 24 |
# File 'lib/contentful/moderator/controller.rb', line 22 def config ::Contentful::Moderator.config end |
#content_type(webhook) ⇒ Object
62 63 64 |
# File 'lib/contentful/moderator/controller.rb', line 62 def content_type(webhook) config.content_types[webhook_content_type(webhook)] end |
#email_body(type, webhook) ⇒ Object
54 55 56 |
# 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) ⇒ Boolean
66 67 68 |
# File 'lib/contentful/moderator/controller.rb', line 66 def notificable?(webhook) config.content_types.keys.include?(webhook_content_type(webhook)) end |
#notify_author?(webhook) ⇒ Boolean
70 71 72 73 74 75 76 77 |
# File 'lib/contentful/moderator/controller.rb', line 70 def (webhook) field = webhook.fields[reviewer_field(webhook).field_id] if field.is_a? Hash return field[field.keys.first] == reviewer_field(webhook). else return field == reviewer_field(webhook). end end |
#notify_authors(webhook) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/contentful/moderator/controller.rb', line 32 def (webhook) logger.debug("\tCreating Author Notification Email") this = self ::Mail.new do from this.config.mail_origin to this.config. subject this.reviewer_field(webhook).email_subject body this.email_body(:reviewer, webhook) end end |
#notify_reviewer?(webhook) ⇒ Boolean
79 80 81 82 83 84 85 86 |
# File 'lib/contentful/moderator/controller.rb', line 79 def notify_reviewer?(webhook) field = webhook.fields[(webhook).field_id] if field.is_a? Hash return field[field.keys.first] == (webhook).notify_reviewer_on else return field == (webhook).notify_reviewer_on end end |
#notify_reviewers(webhook) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# 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.(webhook).email_subject body this.email_body(:author, webhook) end end |
#reviewer_field(webhook) ⇒ Object
92 93 94 |
# File 'lib/contentful/moderator/controller.rb', line 92 def reviewer_field(webhook) content_type(webhook).reviewer_field end |
#send_emails(emails) ⇒ Object
26 27 28 29 30 |
# File 'lib/contentful/moderator/controller.rb', line 26 def send_emails(emails) emails.each do |email| email.deliver! end end |
#webhook_content_type(webhook) ⇒ Object
58 59 60 |
# File 'lib/contentful/moderator/controller.rb', line 58 def webhook_content_type(webhook) webhook.sys['contentType']['sys']['id'] end |
#webhook_url(webhook) ⇒ Object
96 97 98 |
# File 'lib/contentful/moderator/controller.rb', line 96 def webhook_url(webhook) "https://app.contentful.com/spaces/#{webhook.space_id}/entries/#{webhook.id}" end |