Class: Courier::Service::Facebook

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

Constant Summary collapse

FACEBOOK_PROPERTY_ATTRS =
[:from, :to, :picture, :link, :name, :caption, :description, :message,
:source, :icon, :attribution, :actions, :privacy, :targeting]

Instance Method Summary collapse

Methods inherited from Base

#check_args, config, configure, #deliver_all!, inherited, #message, #messages, #name, #to_label, #to_s

Constructor Details

#initializeFacebook

Returns a new instance of Facebook.



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

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

Instance Method Details

#deliver_message(message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/courier/service/facebook.rb', line 18

def deliver_message(message)
  args = message.options[:facebook_properties] || message.options.slice(FACEBOOK_PROPERTY_ATTRS)

  args[:message] ||= message.options[:text] || Courier.template(message.template).
    get_text(message.service, message.options)

  token = args[:token]
  token ||= message.owner.facebook_token if message.owner.respond_to?(:facebook_token)

  return true unless token

  to = args[:to] || (message.owner.respond_to?(:facebook_id) ? message.owner.facebook_id : nil) || 'me'

  # Settings.omniauth.facebook.app_id, Settings.omniauth.facebook.secret
  # Это post_on_wall
  Koala::Facebook::GraphAPI.new(token).put_object(to, "feed", args)
end