yury-facebooker 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/COPYING +19 -0
  3. data/History.txt +16 -0
  4. data/Manifest.txt +77 -0
  5. data/README +46 -0
  6. data/README.txt +81 -0
  7. data/Rakefile +62 -0
  8. data/TODO.txt +10 -0
  9. data/facebooker.yml.tpl +41 -0
  10. data/init.rb +53 -0
  11. data/install.rb +7 -0
  12. data/lib/facebooker.rb +143 -0
  13. data/lib/facebooker/data.rb +40 -0
  14. data/lib/facebooker/feed.rb +78 -0
  15. data/lib/facebooker/model.rb +123 -0
  16. data/lib/facebooker/parser.rb +518 -0
  17. data/lib/facebooker/rails/controller.rb +241 -0
  18. data/lib/facebooker/rails/facebook_asset_path.rb +18 -0
  19. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  20. data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
  21. data/lib/facebooker/rails/facebook_session_handling.rb +58 -0
  22. data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
  23. data/lib/facebooker/rails/helpers.rb +615 -0
  24. data/lib/facebooker/rails/routing.rb +49 -0
  25. data/lib/facebooker/rails/test_helpers.rb +88 -0
  26. data/lib/facebooker/rails/utilities.rb +22 -0
  27. data/lib/facebooker/server_cache.rb +24 -0
  28. data/lib/facebooker/service.rb +31 -0
  29. data/lib/facebooker/session.rb +550 -0
  30. data/lib/facebooker/version.rb +9 -0
  31. data/lib/net/http_multipart_post.rb +123 -0
  32. data/lib/tasks/facebooker.rake +17 -0
  33. data/lib/tasks/tunnel.rake +43 -0
  34. data/setup.rb +1585 -0
  35. data/test/event_test.rb +15 -0
  36. data/test/facebook_cache_test.rb +43 -0
  37. data/test/facebook_data_test.rb +50 -0
  38. data/test/facebooker_test.rb +855 -0
  39. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  40. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  41. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  42. data/test/http_multipart_post_test.rb +54 -0
  43. data/test/model_test.rb +91 -0
  44. data/test/rails_integration_test.rb +993 -0
  45. data/test/session_test.rb +559 -0
  46. data/test/test_helper.rb +60 -0
  47. data/test/user_test.rb +219 -0
  48. metadata +130 -0
File without changes
data/COPYING ADDED
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright (c) 2007 Chad Fowler <chad@infoether.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in the
6
+ # Software without restriction, including without limitation the rights to use,
7
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8
+ # Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18
+ # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ === x.x.x / 2008-xx-xx
2
+
3
+ * fixed typo in set app properties parser [Andrew Grim, shane]
4
+ * Removed actor_id param from templatized feed [shane]
5
+ * Added admin.get_allocation [shane]
6
+ * Added data.get_cookies and data.set_cookie [shane]
7
+ * Added admin.get_app_properties and admin.set_app_properties [shane]
8
+
9
+ === 0.9.9 / 2008-09-08
10
+
11
+ * Re-package as gem after reworking for new API
12
+
13
+
14
+ === 0.9.5 / 2008-02-13
15
+
16
+ * Next release of documentation
@@ -0,0 +1,77 @@
1
+ CHANGELOG.txt
2
+ COPYING
3
+ History.txt
4
+ Manifest.txt
5
+ README
6
+ README.txt
7
+ Rakefile
8
+ TODO.txt
9
+ facebooker.yml.tpl
10
+ generators/publisher/publisher_generator.rb
11
+ generators/publisher/templates/publisher.rb
12
+ init.rb
13
+ install.rb
14
+ lib/facebooker/adapters/adapter_base.rb
15
+ lib/facebooker/adapters/bebo_adapter.rb
16
+ lib/facebooker/adapters/facebook_adapter.rb
17
+ lib/facebooker/admin.rb
18
+ lib/facebooker/batch_request.rb
19
+ lib/facebooker/data.rb
20
+ lib/facebooker/feed.rb
21
+ lib/facebooker/model.rb
22
+ lib/facebooker/models/affiliation.rb
23
+ lib/facebooker/models/album.rb
24
+ lib/facebooker/models/applicationproperties.rb
25
+ lib/facebooker/models/cookie.rb
26
+ lib/facebooker/models/education_info.rb
27
+ lib/facebooker/models/event.rb
28
+ lib/facebooker/models/friend_list.rb
29
+ lib/facebooker/models/group.rb
30
+ lib/facebooker/models/info_item.rb
31
+ lib/facebooker/models/info_section.rb
32
+ lib/facebooker/models/location.rb
33
+ lib/facebooker/models/notifications.rb
34
+ lib/facebooker/models/page.rb
35
+ lib/facebooker/models/photo.rb
36
+ lib/facebooker/models/tag.rb
37
+ lib/facebooker/models/user.rb
38
+ lib/facebooker/models/work_info.rb
39
+ lib/facebooker/parser.rb
40
+ lib/facebooker/rails/controller.rb
41
+ lib/facebooker/rails/facebook_asset_path.rb
42
+ lib/facebooker/rails/facebook_form_builder.rb
43
+ lib/facebooker/rails/facebook_pretty_errors.rb
44
+ lib/facebooker/rails/facebook_request_fix.rb
45
+ lib/facebooker/rails/facebook_session_handling.rb
46
+ lib/facebooker/rails/facebook_url_rewriting.rb
47
+ lib/facebooker/rails/helpers.rb
48
+ lib/facebooker/rails/profile_publisher_extensions.rb
49
+ lib/facebooker/rails/publisher.rb
50
+ lib/facebooker/rails/routing.rb
51
+ lib/facebooker/rails/test_helpers.rb
52
+ lib/facebooker/rails/utilities.rb
53
+ lib/facebooker/server_cache.rb
54
+ lib/facebooker/service.rb
55
+ lib/facebooker/session.rb
56
+ lib/facebooker/version.rb
57
+ lib/facebooker.rb
58
+ lib/net/http_multipart_post.rb
59
+ lib/tasks/facebooker.rake
60
+ lib/tasks/tunnel.rake
61
+ setup.rb
62
+ test/batch_request_test.rb
63
+ test/event_test.rb
64
+ test/facebook_admin_test.rb
65
+ test/facebook_cache_test.rb
66
+ test/facebook_data_test.rb
67
+ test/facebooker_test.rb
68
+ test/fixtures/multipart_post_body_with_only_parameters.txt
69
+ test/fixtures/multipart_post_body_with_single_file.txt
70
+ test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt
71
+ test/http_multipart_post_test.rb
72
+ test/model_test.rb
73
+ test/publisher_test.rb
74
+ test/rails_integration_test.rb
75
+ test/session_test.rb
76
+ test/test_helper.rb
77
+ test/user_test.rb
data/README ADDED
@@ -0,0 +1,46 @@
1
+ Copyright (c) 2007 Chad Fowler, Patrick Ewing
2
+
3
+ = Facebooker
4
+
5
+ Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://developer.facebook.com]. Its goals are:
6
+
7
+ * Idiomatic Ruby
8
+ * No dependencies outside of the Ruby standard library (This is true with Rails 2.1. Previous Rails versions require the JSON gem)
9
+ * Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available
10
+ * Well tested
11
+
12
+ = Installing (Non Rails)
13
+
14
+ The best way is:
15
+
16
+ gem install facebooker
17
+
18
+ If, for some reason, you can't/won't use RubyGems, you can do:
19
+
20
+ (sudo) ruby setup.rb
21
+
22
+ = Installing (Rails)
23
+
24
+ Facebooker can be installed as a Rails plugin by:
25
+
26
+ script/plugin install git://github.com/mmangino/facebooker.git
27
+
28
+ If you don't have git, the plugin can be downloaded from http://github.com/mmangino/facebooker/tarball/master
29
+
30
+ Once the plugin is installed, you will need to configure your Facebook app in config/facebooker.yml.
31
+
32
+ Your application users will need to have added the application in facebook to access all of facebooker's features. You enforce this by adding
33
+
34
+ ensure_application_is_installed_by_facebook_user
35
+
36
+ to your application controller.
37
+
38
+
39
+ == Work in Progress
40
+
41
+ I'm not saying it meets its goals fully yet. Please help. I'm especially interested in feedback and criticism re: Ruby style and design and testing. RCov has the library (at the time of this writing) at 100% coverage. I take that with a grain of salt, but it's a good start.
42
+
43
+ == Contribute
44
+
45
+ Please visit the {RubyForge project page}[http://rubyforge.org/projects/facebooker] to get the latest source via svn, write some tests, add/fix features, and submit a patch via the tracker. If you submit a good patch, it's likely that I'll add you to the project for commit access if you want to be added.
46
+
@@ -0,0 +1,81 @@
1
+ = facebooker
2
+
3
+ * http://facebooker.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://developer.facebook.com]. Its goals are:
8
+
9
+ * Idiomatic Ruby
10
+ * No dependencies outside of the Ruby standard library (This is true with Rails 2.1. Previous Rails versions require the JSON gem)
11
+ * Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available
12
+ * Well tested
13
+
14
+
15
+ == FEATURES/PROBLEMS:
16
+
17
+ * Idiomatic Ruby
18
+ * No dependencies outside of the Ruby standard library
19
+ * Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available
20
+ * Well tested
21
+
22
+ == SYNOPSIS:
23
+
24
+ View David Clements' {excellent tutorial}[http://apps.facebook.com/facebooker_tutorial] at {http://apps.facebook.com/facebooker_tutorial/}[http://apps.facebook.com/facebooker_tutorial] or check out {Developing Facebook Platform Applications with Rails}[http://www.pragprog.com/titles/mmfacer].
25
+
26
+ == REQUIREMENTS:
27
+
28
+ None
29
+
30
+ == INSTALL:
31
+
32
+ * Non Rails
33
+
34
+ The best way is:
35
+
36
+ gem install facebooker
37
+
38
+ If, for some reason, you can't/won't use RubyGems, you can do:
39
+
40
+ (sudo) ruby setup.rb
41
+
42
+ * Rails
43
+
44
+ Facebooker can be installed as a Rails plugin by:
45
+
46
+ script/plugin install git://github.com/mmangino/facebooker.git
47
+
48
+ If you don't have git, the plugin can be downloaded from http://github.com/mmangino/facebooker/tarball/master
49
+
50
+ Once the plugin is installed, you will need to configure your Facebook app in config/facebooker.yml.
51
+
52
+ Your application users will need to have added the application in facebook to access all of facebooker's features. You enforce this by adding
53
+
54
+ ensure_application_is_installed_by_facebook_user
55
+
56
+ to your application controller.
57
+
58
+ == LICENSE:
59
+
60
+ (The MIT License)
61
+
62
+ Copyright (c) 2008 FIX
63
+
64
+ Permission is hereby granted, free of charge, to any person obtaining
65
+ a copy of this software and associated documentation files (the
66
+ 'Software'), to deal in the Software without restriction, including
67
+ without limitation the rights to use, copy, modify, merge, publish,
68
+ distribute, sublicense, and/or sell copies of the Software, and to
69
+ permit persons to whom the Software is furnished to do so, subject to
70
+ the following conditions:
71
+
72
+ The above copyright notice and this permission notice shall be
73
+ included in all copies or substantial portions of the Software.
74
+
75
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
76
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
77
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
78
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
79
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
80
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
81
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # -*- ruby -*-
2
+ #
3
+ require 'rubygems'
4
+ ENV['RUBY_FLAGS']="-I#{%w(lib ext bin test).join(File::PATH_SEPARATOR)}"
5
+ require 'hoe'
6
+ $: << File.dirname(__FILE__) + '/lib'
7
+ require './lib/facebooker.rb'
8
+
9
+ Hoe.new('facebooker', Facebooker::VERSION::STRING) do |p|
10
+ p.rubyforge_name = 'facebooker'
11
+ p.author = ['Chad Fowler', 'Patrick Ewing','Mike Mangino','Shane Vitarana']
12
+ p.email = 'mmangino@elevatedrails.com'
13
+ p.summary = 'Pure, idiomatic Ruby wrapper for the Facebook REST API.'
14
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
15
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
16
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
17
+ p.remote_rdoc_dir = '' # Release to root
18
+ p.test_globs = 'test/*.rb'
19
+ p.extra_deps << ['json', '>= 1.0.0']
20
+ end
21
+
22
+ require 'rcov/rcovtask'
23
+
24
+ namespace :test do
25
+ namespace :coverage do
26
+ desc "Delete aggregate coverage data."
27
+ task(:clean) { rm_f "coverage.data" }
28
+ end
29
+ desc 'Aggregate code coverage for unit, functional and integration tests'
30
+ Rcov::RcovTask.new(:coverage) do |t|
31
+ t.libs << "test"
32
+ t.test_files = FileList["test/*.rb"]
33
+ t.output_dir = "coverage/"
34
+ t.verbose = true
35
+ end
36
+ end
37
+ # vim: syntax=Ruby
38
+ #
39
+ #
40
+ # require File.dirname(__FILE__) + '/vendor/gardener/lib/gardener'
41
+ #
42
+ # require 'facebooker'
43
+ #
44
+ # namespace :doc do
45
+ # task :readme do
46
+ # puts "Readme"
47
+ # end
48
+ # end
49
+ #
50
+ # Gardener.configure do
51
+ # gem_spec do |spec|
52
+ # spec.name = 'facebooker'
53
+ # spec.version = Gem::Version.new(Facebooker::VERSION::STRING)
54
+ # spec.summary = "Pure, idiomatic Ruby wrapper for the Facebook REST API."
55
+ # spec.email = 'chad@infoether.com'
56
+ # spec.author = ['Chad Fowler', 'Patrick Ewing','Mike Mangino','Shane Vitarana']
57
+ # spec.extra_rdoc_files = %w(COPYING)
58
+ # spec.rdoc_options = ['--title', "Gardener",
59
+ # '--main', 'README',
60
+ # '--line-numbers', '--inline-source']
61
+ # end
62
+ # end
@@ -0,0 +1,10 @@
1
+ [ ] Remove facebook prefix from resource routes, making them worth with facebook and regular Rails controllers
2
+ [ ] Use fb_sig_request_method to make facebook routes more Rails-like
3
+ [ ] Refactor facebook form builder so erbout won't be deeply nested, causing erubis to break
4
+ [ ] Support missing parameters on methods---most notably authentication-related parameters such as next and canvas
5
+ [ ] Finish FQL Querying
6
+ [ ] Refactor FQL Querying
7
+ [ ] Transform incoming data into appropriate classes (Integers, Dates, etc.)
8
+
9
+ [x] Specify fields wanted when getting user info (defaults to all now) [shane]
10
+ [x] Create facebooker.yml config file and merge with tunnel.yml [shane]
@@ -0,0 +1,41 @@
1
+ # The api key, secret key, and canvas page name are required to get started
2
+ # Tunnel configuration is only needed if you are going to use the facebooker:tunnel Rake tasks
3
+ # Your callback url in Facebook should be set to http://public_host:public_port
4
+ # To develop for the new profile design, add the following key..
5
+ # api: new
6
+ # remove the key or set it to anything else to use the old facebook design.
7
+ # This should only be necessary until the final version of the new profile is released.
8
+
9
+ development:
10
+ api_key:
11
+ secret_key:
12
+ canvas_page_name:
13
+ callback_url:
14
+ pretty_errors: true
15
+ tunnel:
16
+ public_host_username:
17
+ public_host:
18
+ public_port: 4007
19
+ local_port: 3000
20
+
21
+ test:
22
+ api_key:
23
+ secret_key:
24
+ canvas_page_name:
25
+ callback_url:
26
+ tunnel:
27
+ public_host_username:
28
+ public_host:
29
+ public_port: 4007
30
+ local_port: 3000
31
+
32
+ production:
33
+ api_key:
34
+ secret_key:
35
+ canvas_page_name:
36
+ callback_url:
37
+ tunnel:
38
+ public_host_username:
39
+ public_host:
40
+ public_port: 4007
41
+ local_port: 3000
data/init.rb ADDED
@@ -0,0 +1,53 @@
1
+ # Added support to the Facebooker.yml file for switching to the new profile design..
2
+ # Config parsing needs to happen before files are required.
3
+ facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
4
+
5
+ require 'facebooker'
6
+ FACEBOOKER = Facebooker.load_configuration(facebook_config)
7
+
8
+ # enable logger before including everything else, in case we ever want to log initialization
9
+ Facebooker.logger = RAILS_DEFAULT_LOGGER if Object.const_defined? :RAILS_DEFAULT_LOGGER
10
+
11
+ require 'net/http_multipart_post'
12
+ require 'facebooker/rails/controller'
13
+ require 'facebooker/rails/facebook_url_rewriting'
14
+ require 'facebooker/rails/facebook_session_handling'
15
+ require 'facebooker/rails/facebook_asset_path'
16
+ require 'facebooker/rails/facebook_request_fix'
17
+ require 'facebooker/rails/routing'
18
+ require 'facebooker/rails/facebook_pretty_errors' rescue nil
19
+ module ::ActionController
20
+ class Base
21
+ def self.inherited_with_facebooker(subclass)
22
+ inherited_without_facebooker(subclass)
23
+ if subclass.to_s == "ApplicationController"
24
+ subclass.send(:include,Facebooker::Rails::Controller)
25
+ subclass.helper Facebooker::Rails::Helpers
26
+ end
27
+ end
28
+ class << self
29
+ alias_method_chain :inherited, :facebooker
30
+ end
31
+ end
32
+ end
33
+
34
+ class ActionController::Routing::Route
35
+ def recognition_conditions_with_facebooker
36
+ defaults = recognition_conditions_without_facebooker
37
+ defaults << " env[:canvas] == conditions[:canvas] " if conditions[:canvas]
38
+ defaults
39
+ end
40
+ alias_method_chain :recognition_conditions, :facebooker
41
+ end
42
+
43
+ # We turn off route optimization to make named routes use our code for figuring out if they should go to the session
44
+ # If this fails, it means we're on rails 1.2, we can ignore it
45
+ begin
46
+ ActionController::Base::optimise_named_routes = false
47
+ rescue NoMethodError=>e
48
+ nil
49
+ end
50
+
51
+ # pull :canvas=> into env in routing to allow for conditions
52
+ ActionController::Routing::RouteSet.send :include, Facebooker::Rails::Routing::RouteSetExtensions
53
+ ActionController::Routing::RouteSet::Mapper.send :include, Facebooker::Rails::Routing::MapperExtensions
@@ -0,0 +1,7 @@
1
+ require 'fileutils'
2
+ require 'rubygems'
3
+ facebook_config = File.join(RAILS_ROOT,"config","facebooker.yml")
4
+ facebook_js = File.join(RAILS_ROOT,"public","javascripts",'facebooker.js')
5
+ FileUtils.cp File.join(File.dirname(__FILE__) , 'facebooker.yml.tpl'), facebook_config unless File.exist?(facebook_config)
6
+ FileUtils.cp File.join(File.dirname(__FILE__) , 'javascripts','facebooker.js'), facebook_js unless File.exist?(facebook_js)
7
+ puts IO.read(File.join(File.dirname(__FILE__), 'README'))
@@ -0,0 +1,143 @@
1
+ begin
2
+ unless Object.const_defined?("ActiveSupport") and ActiveSupport.const_defined?("JSON")
3
+ require 'json'
4
+ module Facebooker
5
+ def self.json_decode(str)
6
+ JSON.parse(str)
7
+ end
8
+ end
9
+ else
10
+ module Facebooker
11
+ def self.json_decode(str)
12
+ ActiveSupport::JSON.decode(str)
13
+ end
14
+ end
15
+ end
16
+ rescue
17
+ require 'json'
18
+ end
19
+ require 'zlib'
20
+ require 'digest/md5'
21
+
22
+ require 'facebooker/batch_request'
23
+ require 'facebooker/feed'
24
+ require 'facebooker/logging'
25
+ require 'facebooker/model'
26
+ require 'facebooker/parser'
27
+ require 'facebooker/service'
28
+ require 'facebooker/server_cache'
29
+ require 'facebooker/data'
30
+ require 'facebooker/admin'
31
+ require 'facebooker/session'
32
+ require 'facebooker/version'
33
+ require 'facebooker/models/location'
34
+ require 'facebooker/models/affiliation'
35
+ require 'facebooker/models/album'
36
+ require 'facebooker/models/education_info'
37
+ require 'facebooker/models/work_info'
38
+ require 'facebooker/models/event'
39
+ require 'facebooker/models/group'
40
+ require 'facebooker/models/notifications'
41
+ require 'facebooker/models/page'
42
+ require 'facebooker/models/photo'
43
+ require 'facebooker/models/cookie'
44
+ require 'facebooker/models/applicationproperties'
45
+ require 'facebooker/models/tag'
46
+ require 'facebooker/models/user'
47
+ require 'facebooker/models/info_item'
48
+ require 'facebooker/models/info_section'
49
+ require 'facebooker/adapters/adapter_base'
50
+ require 'facebooker/adapters/facebook_adapter'
51
+ require 'facebooker/adapters/bebo_adapter'
52
+ require 'facebooker/models/friend_list'
53
+
54
+ module Facebooker
55
+
56
+ class << self
57
+
58
+ def load_configuration(facebooker_yaml_file)
59
+ if File.exist?(facebooker_yaml_file)
60
+ if defined? RAILS_ENV
61
+ facebooker = YAML.load_file(facebooker_yaml_file)[RAILS_ENV]
62
+ else
63
+ facebooker = YAML.load_file(facebooker_yaml_file)
64
+ end
65
+ ENV['FACEBOOK_API_KEY'] = facebooker['api_key']
66
+ ENV['FACEBOOK_SECRET_KEY'] = facebooker['secret_key']
67
+ ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = facebooker['canvas_page_name']
68
+ ENV['FACEBOOKER_API'] = facebooker['api']
69
+ if Object.const_defined?("ActionController")
70
+ ActionController::Base.asset_host = facebooker['callback_url'] if(ActionController::Base.asset_host.blank?)
71
+ end
72
+ @facebooker_configuration = facebooker
73
+ end
74
+ end
75
+
76
+ def facebooker_config
77
+ @facebooker_configuration
78
+ end
79
+
80
+ def current_adapter=(adapter_class)
81
+ @current_adapter = adapter_class
82
+ end
83
+
84
+ def current_adapter
85
+ @current_adapter || Facebooker::AdapterBase.default_adapter
86
+ end
87
+
88
+ def load_adapter(params)
89
+ self.current_adapter = Facebooker::AdapterBase.load_adapter(params)
90
+ end
91
+
92
+ def facebook_path_prefix=(path)
93
+ current_adapter.facebook_path_prefix = path
94
+ end
95
+
96
+ # Default is canvas_page_name in yml file
97
+ def facebook_path_prefix
98
+ current_adapter.facebook_path_prefix
99
+ end
100
+
101
+ def is_for?(application_container)
102
+ current_adapter.is_for?(application_container)
103
+ end
104
+
105
+
106
+
107
+ [:api_key,:secret_key, :www_server_base_url,:login_url_base,:install_url_base,:api_rest_path,:api_server_base,:api_server_base_url,:canvas_server_base].each do |delegated_method|
108
+ define_method(delegated_method){ return current_adapter.send(delegated_method)}
109
+ end
110
+
111
+
112
+ def path_prefix
113
+ @path_prefix
114
+ end
115
+
116
+
117
+ # Set the asset path to the canvas path for just this one request
118
+ # by definition, we will make this a canvas request
119
+ def with_asset_path_for_canvas
120
+ original_asset_host = ActionController::Base.asset_host
121
+ begin
122
+ ActionController::Base.asset_host = Facebooker.api_server_base_url
123
+ request_for_canvas(true) do
124
+ yield
125
+ end
126
+ ensure
127
+ ActionController::Base.asset_host = original_asset_host
128
+ end
129
+ end
130
+
131
+ # If this request is_canvas_request
132
+ # then use the application name as the url root
133
+ def request_for_canvas(is_canvas_request)
134
+ original_path_prefix = @path_prefix
135
+ begin
136
+ @path_prefix = facebook_path_prefix if is_canvas_request
137
+ yield
138
+ ensure
139
+ @path_prefix = original_path_prefix
140
+ end
141
+ end
142
+ end
143
+ end