Sha256: 513cef667152b6d93b572271edbda8c404d3f6f0b69684089351ea534a14abb3

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

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

class Courier::Service::Facebook < Courier::Service::Base
  def initialize
    raise "No Koala defined. Add gem 'koala' to your Gemfile. " unless defined? Koala
    super
  end

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

  def deliver_all!
    cache={}
    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] || 'me') and
        message.set_delivered
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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