Class: Courier::Service::Facebook

Inherits:
Base
  • Object
show all
Defined in:
lib/courier/service/facebook.rb

Instance Method Summary collapse

Methods inherited from Base

config, configure, inherited, #message, #name

Constructor Details

#initializeFacebook

Returns a new instance of Facebook.



4
5
6
7
# File 'lib/courier/service/facebook.rb', line 4

def initialize
  raise "No Koala defined. Add gem 'koala' to your Gemfile. " unless defined? Koala
  super
end

Instance Method Details

#check_args(owner, template, args) ⇒ Object



9
10
11
12
13
# File 'lib/courier/service/facebook.rb', line 9

def check_args owner, template, args
  args[:to]|='me'
  args[:attachment]||={}
  super
end

#deliver!Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/courier/service/facebook.rb', line 15

def deliver!
  cache={}
  courier_messages.fresh.each do |message|
    message.owner.respond_to?(:facebook_token) or
      raise "method facebook_token is not defined in your owner's model #{owner.class}"
    token = message.owner.facebook_token or raise "owner's facebook_token is empty"
    graph = cache[token] ||= Koala::Facebook::GraphAPI.new(token)
    graph.put_wall_post(message.options[:text], message.options[:attachment], message.options[:to]) and
      message.set_delivered
  end
end