facebooker2/lib/facebooker2.rb

50 lines
1.4 KiB
Ruby
Raw Normal View History

2010-05-04 16:30:49 +00:00
# Facebooker2
2010-05-05 16:07:05 +00:00
require "mogli"
2010-05-05 15:42:11 +00:00
module Facebooker2
2010-05-05 20:28:18 +00:00
class NotConfigured < Exception; end
2010-05-05 15:42:11 +00:00
class << self
attr_accessor :api_key, :secret, :app_id
end
2010-05-05 20:28:18 +00:00
def self.secret
@secret || raise_unconfigured_exception
end
def self.app_id
@app_id || raise_unconfigured_exception
end
def self.raise_unconfigured_exception
raise NotConfigured.new("No configuration provided for Facebooker2. Either set the app_id and secret or call Facebooker2.load_facebooker_yaml in an initializer")
end
def self.configuration=(hash)
self.api_key = hash[:api_key]
self.secret = hash[:secret]
self.app_id = hash[:app_id]
end
def self.load_facebooker_yaml
config = YAML.load(File.read(File.join(::Rails.root,"config","facebooker.yml")))[::Rails.env]
raise NotConfigured.new("Unable to load configuration for #{::Rails.env} from facebooker.yml. Is it set up?") if config.nil?
self.configuration = config.with_indifferent_access
end
2010-05-05 16:07:05 +00:00
def self.cast_to_facebook_id(object)
if object.kind_of?(Mogli::Profile)
object.id
elsif object.respond_to?(:facebook_id)
object.facebook_id
else
object
end
end
2010-05-05 15:42:11 +00:00
end
require "facebooker2/rails/controller"
2010-05-05 16:07:05 +00:00
require "facebooker2/rails/helpers/facebook_connect"
2010-05-05 18:08:46 +00:00
require "facebooker2/rails/helpers/javascript"
2010-05-05 16:07:05 +00:00
require "facebooker2/rails/helpers/user"
require "facebooker2/rails/helpers"