Sha256: 27dccfa1ca75b64212036d089ff8c7c25bce05b5ee7396c1d75f2242dbbdf2f6

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# -*- coding: utf-8 -*-

class Courier::Service::Facebook < Courier::Service::Base

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

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

  #
  # message.options[:facebook_properties] are all available options from
  # http://developers.facebook.com/docs/reference/api/post/
  #
  def deliver_message(message)
    return true unless message.owner.facebook_id

    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 nil 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
courier-0.2.3 lib/courier/service/facebook.rb