2010-05-04 16:30:49 +00:00
# Facebooker2
2010-05-05 16:07:05 +00:00
require " mogli "
2010-09-17 17:12:58 +00:00
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
2010-09-17 17:12:58 +00:00
attr_accessor :api_key , :secret , :app_id , :canvas_page_name
2010-05-05 15:42:11 +00:00
end
2010-09-17 17:12:58 +00:00
2010-05-05 20:28:18 +00:00
def self . secret
2010-09-17 17:12:58 +00:00
@secret || raise_unconfigured_exception
2010-05-05 20:28:18 +00:00
end
2010-09-17 17:12:58 +00:00
2010-05-05 20:28:18 +00:00
def self . app_id
@app_id || raise_unconfigured_exception
end
2010-09-17 17:12:58 +00:00
2010-05-05 20:28:18 +00:00
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
2010-09-17 17:12:58 +00:00
2010-05-05 20:28:18 +00:00
def self . configuration = ( hash )
self . api_key = hash [ :api_key ]
self . secret = hash [ :secret ]
self . app_id = hash [ :app_id ]
2010-09-17 17:12:58 +00:00
self . canvas_page_name = hash [ :canvas_page_name ]
2010-05-05 20:28:18 +00:00
end
2010-09-17 17:12:58 +00:00
2010-05-05 20:28:18 +00:00
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-09-17 17:12:58 +00:00
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-09-17 17:12:58 +00:00
require " facebooker2/rails/controller/canvas_oauth "
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-06 14:52:04 +00:00
require " facebooker2/rails/helpers/request_forms "
2010-05-05 16:07:05 +00:00
require " facebooker2/rails/helpers/user "
2010-09-17 17:12:58 +00:00
require " facebooker2/rails/helpers "
require " facebooker2/oauth_exception "