class Feedbook::Notification
Attributes
template[R]
type[R]
variables[R]
Public Class Methods
new(opts = {})
click to toggle source
Initializes Notification
instance @param opts = {} [Hash] Hash with
@return [type] [description]
# File lib/feedbook/notification.rb, line 16 def initialize(opts = {}) @type = opts.fetch(:type, '') @variables = opts.fetch(:variables, {}) @template = parse_template(opts.fetch(:template, '')) end
Public Instance Methods
notify(object)
click to toggle source
Notifies selected gateway about new post @param object [Object] objct that respond to :to_hash method
@return [NilClass] nil
# File lib/feedbook/notification.rb, line 26 def notify(object) message = template.render(object.to_hash.merge(variables)) notifier.notify(message) end
valid?()
click to toggle source
Validates if given parameters are valid
@return [NilClass] nil @raise [Feedbook::Errors::InvalidVariablesFormatError] if variables parameter is not a Hash
# File lib/feedbook/notification.rb, line 36 def valid? unless variables.is_a? Hash raise Errors::InvalidVariablesFormatError.new end end
Private Instance Methods
notifier()
click to toggle source
Returms Notifier instance
@return [Notifier] Notifier instance for given type
# File lib/feedbook/notification.rb, line 58 def notifier @notifier ||= Factories::NotifiersFactory.create(type) end
parse_template(template)
click to toggle source
Parses template from string into a valid Liquid::Template @param template [String] String
with valid Liquid template
@return [Liquid::Template] compiled Liquid template @raise [Feedbook::Errors::TemplateSyntaxError] if there is a SyntaxError inside template
# File lib/feedbook/notification.rb, line 49 def parse_template(template) Liquid::Template.parse(template) rescue SyntaxError => e raise Errors::TemplateSyntaxError.new(e.message) end