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



15
16
17
18
19
# File 'lib/feedbook/notification.rb', line 15

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.



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

def template
  @template
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#variablesObject (readonly)

Returns the value of attribute variables.



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

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



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

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:



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

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