Sha256: 846863219ece4a3937f99d496641979586fe602061cad7d74c3905a92d1b296e

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

require 'singleton'
require 'koala'
require 'feedbook/errors/notifier_configuration_error'

module Feedbook
  module Notifiers
    class FacebookNotifier
      include Singleton

      # Sends notification to Facebook wall
      # @param message [String] message to be send to Facebook wall
      # 
      # @return [NilClass] nil
      # @raise [Feedbook::Errors::NotifierNotifyError] if notify method fails 
      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

      # Load configuration for FacebookNotifier
      # @param configuration = {} [Hash] Configuration hash (required: token, optional: app_secret)
      #
      # @return [NilClass] nil
      # @raise [Feedbook::Errors::NotifierConfigurationError] if notifier configuration fails 
      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

      private
      attr_reader :client
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
feedbook-1.1.0 lib/feedbook/notifiers/facebook_notifier.rb
feedbook-1.0.0 lib/feedbook/notifiers/facebook_notifier.rb