Class: Feedbook::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/feedbook/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ type

Initializes Notification instance

Parameters:

  • opts (defaults to: {})

    {} [Hash] Hash with



16
17
18
19
20
# 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

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



10
11
12
# File 'lib/feedbook/notification.rb', line 10

def template
  @template
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/feedbook/notification.rb', line 10

def type
  @type
end

#variablesObject (readonly)

Returns the value of attribute variables.



10
11
12
# File 'lib/feedbook/notification.rb', line 10

def variables
  @variables
end

Instance Method Details

#notify(object) ⇒ NilClass

Notifies selected gateway about new post

Parameters:

  • object (Object)

    objct that respond to :to_hash method

Returns:

  • (NilClass)

    nil



26
27
28
29
30
# File 'lib/feedbook/notification.rb', line 26

def notify(object)
  message = template.render(object.to_hash.merge(variables))
  
  notifier.notify(message)
end

#valid?NilClass

Validates if given parameters are valid

Returns:

  • (NilClass)

    nil

Raises:



36
37
38
39
40
# File 'lib/feedbook/notification.rb', line 36

def valid?
  unless variables.is_a? Hash
    raise Errors::InvalidVariablesFormatError.new
  end
end