Class: Feedbook::Notifiers::FacebookNotifier

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/feedbook/notifiers/facebook_notifier.rb

Instance Method Summary collapse

Instance Method Details

#load_configuration(configuration = {}) ⇒ NilClass

Load configuration for FacebookNotifier

Parameters:

  • configuration (defaults to: {})

    {} [Hash] Configuration hash (required: token, optional: app_secret)

Returns:

  • (NilClass)

    nil

Raises:



31
32
33
34
35
36
37
# File 'lib/feedbook/notifiers/facebook_notifier.rb', line 31

def load_configuration(configuration = {})
  @client = Koala::Facebook::API.new(configuration.fetch('token'), configuration.fetch('app_secret', nil))

  puts 'Configuration loaded for FacebookNotifier'
rescue Koala::KoalaError => e
  raise Errors::NotifierConfigurationError.new(:facebook, e.message)
end

#notify(message) ⇒ NilClass

Sends notification to Facebook wall

Parameters:

  • message (String)

    message to be send to Facebook wall

Returns:

  • (NilClass)

    nil

Raises:

  • (Feedbook::Errors::NotifierNotifyError)

    if notify method fails



15
16
17
18
19
20
21
22
23
24
# File 'lib/feedbook/notifiers/facebook_notifier.rb', line 15

def notify(message)
  if client.nil?
    puts "Message has not been notified on Facebook: #{message} because of invalid client configuration"
  else
    client.put_wall_post(message)
    puts "New message has been notified on Facebook: #{message}"
  end
rescue Koala::KoalaError => e
  p "FacebookNotifier did not notify because of client error (#{e.message})."
end