require 'koala' module FacebookRails class Engine < Rails::Engine initializer "facebook_rails.load_app_instance_data" do |app| FacebookRails.setup do |config| config.app_root = app.root config.app_env = Rails.env end end initializer "facebook_rails.facebook" do begin ::FACEBOOK = YAML.load_file(FacebookRails.app_root.join("config/facebook.yml"))[FacebookRails.app_env] FACEBOOK.default = '' rescue Exception => e warn "WARNING: config/facebook.yml could not be loaded or a configuration is missing. Please run 'rails generate facebook_rails'." ::FACEBOOK = {} FACEBOOK.default = '' end ::Koala.http_service.http_options[:timeout] = FACEBOOK[:timeout].to_i unless FACEBOOK[:timeout].blank? ::Koala::Facebook::OAuth.class_eval do def initialize_with_default_settings(*args) case args.size when 0, 1 raise "application id and/or secret are not specified in the config" unless FACEBOOK['app_id'] && FACEBOOK['secret_key'] initialize_without_default_settings(FACEBOOK['app_id'].to_s, FACEBOOK['secret_key'].to_s, args.first) when 2, 3 initialize_without_default_settings(*args) end end alias_method_chain :initialize, :default_settings end end initializer "facebook_rails.facebook_post_patch" do Rails::Rack::Logger.class_eval do def call_with_post_override(env) if env["REQUEST_METHOD"]=="POST" and ((env["HTTP_REFERER"] and env["HTTP_REFERER"].to_s =~ /:\/\/[^\/]*facebook.com/) or (env["HTTP_ORIGIN"] and env["HTTP_ORIGIN"].to_s =~ /:\/\/[^\/]*facebook.com/)) env["REQUEST_METHOD"]="GET" info "\n**FACEBOOK POST CHANGED TO GET**" end call_without_post_override(env) end alias_method :call_without_post_override, :call alias_method :call, :call_with_post_override end end initializer "facebook_rails.application_controller" do ActionController::Base.send :include, FacebookRailsController ActionController::Base.send :helper_method, :facebook_href ActionController::Base.send :helper_method, :direct_href ActionController::Base.send :helper_method, :current_user_f8id ActionController::Base.send :helper_method, :get_facebook_locale end initializer "facebook_rails.application_helper" do ActionView::Base.send :include, FacebookRailsHelper end end end