facebooker 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/COPYING +19 -0
  3. data/History.txt +3 -0
  4. data/Manifest.txt +60 -0
  5. data/README +44 -0
  6. data/README.txt +79 -0
  7. data/Rakefile +38 -0
  8. data/TODO.txt +10 -0
  9. data/facebooker.yml.tpl +36 -0
  10. data/init.rb +52 -0
  11. data/install.rb +5 -0
  12. data/lib/facebooker.rb +63 -0
  13. data/lib/facebooker/affiliation.rb +10 -0
  14. data/lib/facebooker/album.rb +11 -0
  15. data/lib/facebooker/cookie.rb +10 -0
  16. data/lib/facebooker/data.rb +38 -0
  17. data/lib/facebooker/education_info.rb +11 -0
  18. data/lib/facebooker/event.rb +26 -0
  19. data/lib/facebooker/feed.rb +65 -0
  20. data/lib/facebooker/group.rb +35 -0
  21. data/lib/facebooker/location.rb +8 -0
  22. data/lib/facebooker/model.rb +118 -0
  23. data/lib/facebooker/notifications.rb +17 -0
  24. data/lib/facebooker/parser.rb +386 -0
  25. data/lib/facebooker/photo.rb +9 -0
  26. data/lib/facebooker/rails/controller.rb +174 -0
  27. data/lib/facebooker/rails/facebook_asset_path.rb +18 -0
  28. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  29. data/lib/facebooker/rails/facebook_request_fix.rb +14 -0
  30. data/lib/facebooker/rails/facebook_session_handling.rb +58 -0
  31. data/lib/facebooker/rails/facebook_url_rewriting.rb +31 -0
  32. data/lib/facebooker/rails/helpers.rb +535 -0
  33. data/lib/facebooker/rails/routing.rb +49 -0
  34. data/lib/facebooker/rails/test_helpers.rb +11 -0
  35. data/lib/facebooker/rails/utilities.rb +22 -0
  36. data/lib/facebooker/server_cache.rb +24 -0
  37. data/lib/facebooker/service.rb +25 -0
  38. data/lib/facebooker/session.rb +385 -0
  39. data/lib/facebooker/tag.rb +12 -0
  40. data/lib/facebooker/user.rb +200 -0
  41. data/lib/facebooker/version.rb +9 -0
  42. data/lib/facebooker/work_info.rb +9 -0
  43. data/lib/net/http_multipart_post.rb +123 -0
  44. data/lib/tasks/facebooker.rake +16 -0
  45. data/lib/tasks/tunnel.rake +39 -0
  46. data/setup.rb +1585 -0
  47. data/test/event_test.rb +15 -0
  48. data/test/facebook_cache_test.rb +43 -0
  49. data/test/facebook_data_test.rb +50 -0
  50. data/test/facebooker_test.rb +766 -0
  51. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  52. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  53. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  54. data/test/http_multipart_post_test.rb +54 -0
  55. data/test/model_test.rb +79 -0
  56. data/test/rails_integration_test.rb +732 -0
  57. data/test/session_test.rb +396 -0
  58. data/test/test_helper.rb +54 -0
  59. data/test/user_test.rb +101 -0
  60. 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,3 @@
1
+ === 0.9.5 / 2008-02-13
2
+
3
+ * Next release of documentation
@@ -0,0 +1,60 @@
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
+ init.rb
11
+ install.rb
12
+ lib/facebooker.rb
13
+ lib/facebooker/affiliation.rb
14
+ lib/facebooker/album.rb
15
+ lib/facebooker/cookie.rb
16
+ lib/facebooker/data.rb
17
+ lib/facebooker/education_info.rb
18
+ lib/facebooker/event.rb
19
+ lib/facebooker/feed.rb
20
+ lib/facebooker/group.rb
21
+ lib/facebooker/location.rb
22
+ lib/facebooker/model.rb
23
+ lib/facebooker/notifications.rb
24
+ lib/facebooker/parser.rb
25
+ lib/facebooker/photo.rb
26
+ lib/facebooker/rails/controller.rb
27
+ lib/facebooker/rails/facebook_asset_path.rb
28
+ lib/facebooker/rails/facebook_form_builder.rb
29
+ lib/facebooker/rails/facebook_request_fix.rb
30
+ lib/facebooker/rails/facebook_session_handling.rb
31
+ lib/facebooker/rails/facebook_url_rewriting.rb
32
+ lib/facebooker/rails/helpers.rb
33
+ lib/facebooker/rails/routing.rb
34
+ lib/facebooker/rails/test_helpers.rb
35
+ lib/facebooker/rails/utilities.rb
36
+ lib/facebooker/server_cache.rb
37
+ lib/facebooker/service.rb
38
+ lib/facebooker/session.rb
39
+ lib/facebooker/tag.rb
40
+ lib/facebooker/user.rb
41
+ lib/facebooker/version.rb
42
+ lib/facebooker/work_info.rb
43
+ lib/net/http_multipart_post.rb
44
+ lib/tasks/facebooker.rake
45
+ lib/tasks/tunnel.rake
46
+ setup.rb
47
+ test/event_test.rb
48
+ test/facebook_cache_test.rb
49
+ test/facebook_data_test.rb
50
+ test/facebooker_test.rb
51
+ test/fixtures/multipart_post_body_with_only_parameters.txt
52
+ test/fixtures/multipart_post_body_with_single_file.txt
53
+ test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt
54
+ test/http_multipart_post_test.rb
55
+ test/model_test.rb
56
+ test/rails_integration_test.rb
57
+ test/session_test.rb
58
+ test/test_helper.rb
59
+ test/user_test.rb
60
+
data/README ADDED
@@ -0,0 +1,44 @@
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
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 http://facebooker.rubyforge.org/svn/trunk/facebooker/
27
+
28
+ Once the plugin is installed, you will need to configure your Facebook app in config/facebooker.yml.
29
+
30
+ Your application users will need to have added the application in facebook to access all of facebooker's features. You enforce this by adding
31
+
32
+ ensure_application_is_installed_by_facebook_user
33
+
34
+ to your application controller.
35
+
36
+
37
+ == Work in Progress
38
+
39
+ 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.
40
+
41
+ == Contribute
42
+
43
+ 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.
44
+
@@ -0,0 +1,79 @@
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
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
+ Facebooker tutorial coming soon
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 http://facebooker.rubyforge.org/svn/trunk/facebooker/
47
+
48
+ Once the plugin is installed, you will need to configure your Facebook app in config/facebooker.yml.
49
+
50
+ Your application users will need to have added the application in facebook to access all of facebooker's features. You enforce this by adding
51
+
52
+ ensure_application_is_installed_by_facebook_user
53
+
54
+ to your application controller.
55
+
56
+ == LICENSE:
57
+
58
+ (The MIT License)
59
+
60
+ Copyright (c) 2008 FIX
61
+
62
+ Permission is hereby granted, free of charge, to any person obtaining
63
+ a copy of this software and associated documentation files (the
64
+ 'Software'), to deal in the Software without restriction, including
65
+ without limitation the rights to use, copy, modify, merge, publish,
66
+ distribute, sublicense, and/or sell copies of the Software, and to
67
+ permit persons to whom the Software is furnished to do so, subject to
68
+ the following conditions:
69
+
70
+ The above copyright notice and this permission notice shall be
71
+ included in all copies or substantial portions of the Software.
72
+
73
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
74
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
75
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
76
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
77
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
78
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
79
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ $: << File.dirname(__FILE__) + '/lib'
6
+ require './lib/facebooker.rb'
7
+
8
+ Hoe.new('facebooker', Facebooker::VERSION) do |p|
9
+ p.rubyforge_name = 'facebooker'
10
+ p.author = ['Chad Fowler', 'Patrick Ewing','Mike Mangino','Shane Vitarana']
11
+ p.email = 'mmangino@elevatedrails.com'
12
+ p.summary = 'Pure, idiomatic Ruby wrapper for the Facebook REST API.'
13
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
14
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
15
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
16
+ p.remote_rdoc_dir = '' # Release to root
17
+ end
18
+
19
+ # vim: syntax=Ruby
20
+ #
21
+ #
22
+ # require File.dirname(__FILE__) + '/vendor/gardener/lib/gardener'
23
+ #
24
+ # require 'facebooker'
25
+ #
26
+ # Gardener.configure do
27
+ # gem_spec do |spec|
28
+ # spec.name = 'facebooker'
29
+ # spec.version = Gem::Version.new(Facebooker::VERSION::STRING)
30
+ # spec.summary = "Pure, idiomatic Ruby wrapper for the Facebook REST API."
31
+ # spec.email = 'chad@infoether.com'
32
+ # spec.author = ['Chad Fowler', 'Patrick Ewing','Mike Mangino','Shane Vitarana']
33
+ # spec.extra_rdoc_files = %w(COPYING)
34
+ # spec.rdoc_options = ['--title', "Gardener",
35
+ # '--main', 'README',
36
+ # '--line-numbers', '--inline-source']
37
+ # end
38
+ # 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,36 @@
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
+
5
+ development:
6
+ api_key:
7
+ secret_key:
8
+ canvas_page_name:
9
+ callback_url:
10
+ tunnel:
11
+ public_host_username:
12
+ public_host:
13
+ public_port: 4007
14
+ local_port: 3000
15
+
16
+ test:
17
+ api_key:
18
+ secret_key:
19
+ canvas_page_name:
20
+ callback_url:
21
+ tunnel:
22
+ public_host_username:
23
+ public_host:
24
+ public_port: 4007
25
+ local_port: 3000
26
+
27
+ production:
28
+ api_key:
29
+ secret_key:
30
+ canvas_page_name:
31
+ callback_url:
32
+ tunnel:
33
+ public_host_username:
34
+ public_host:
35
+ public_port: 4007
36
+ local_port: 3000
data/init.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'net/http_multipart_post'
2
+ require 'facebooker/rails/controller'
3
+ require 'facebooker/rails/facebook_url_rewriting'
4
+ require 'facebooker/rails/facebook_session_handling'
5
+ require 'facebooker/rails/facebook_asset_path'
6
+ require 'facebooker/rails/facebook_request_fix'
7
+ require 'facebooker/rails/routing'
8
+
9
+ module ::ActionController
10
+ class Base
11
+ def self.inherited_with_facebooker(subclass)
12
+ inherited_without_facebooker(subclass)
13
+ if subclass.to_s == "ApplicationController"
14
+ subclass.send(:include,Facebooker::Rails::Controller)
15
+ subclass.helper Facebooker::Rails::Helpers
16
+ end
17
+ end
18
+ class << self
19
+ alias_method_chain :inherited, :facebooker
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+ class ActionController::Routing::Route
26
+ def recognition_conditions_with_facebooker
27
+ defaults = recognition_conditions_without_facebooker
28
+ defaults << " env[:canvas] == conditions[:canvas] " if conditions[:canvas]
29
+ defaults
30
+ end
31
+ alias_method_chain :recognition_conditions, :facebooker
32
+ end
33
+ # We turn off route optimization to make named routes use our code for figuring out if they should go to the session
34
+ # If this fails, it means we're on rails 1.2, we can ignore it
35
+ begin
36
+ ActionController::Base::optimise_named_routes = false
37
+ rescue NoMethodError=>e
38
+ nil
39
+ end
40
+ # pull :canvas=> into env in routing to allow for conditions
41
+ ActionController::Routing::RouteSet.send :include, Facebooker::Rails::Routing::RouteSetExtensions
42
+ ActionController::Routing::RouteSet::Mapper.send :include, Facebooker::Rails::Routing::MapperExtensions
43
+
44
+ facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
45
+
46
+ if File.exist?(facebook_config)
47
+ FACEBOOKER = YAML.load_file(facebook_config)[RAILS_ENV]
48
+ ENV['FACEBOOK_API_KEY'] = FACEBOOKER['api_key']
49
+ ENV['FACEBOOK_SECRET_KEY'] = FACEBOOKER['secret_key']
50
+ ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = FACEBOOKER['canvas_page_name']
51
+ ActionController::Base.asset_host = FACEBOOKER['callback_url']
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'fileutils'
2
+
3
+ facebook_config = File.dirname(__FILE__) + '/../../../config/facebooker.yml'
4
+ FileUtils.cp File.dirname(__FILE__) + '/facebooker.yml.tpl', facebook_config unless File.exist?(facebook_config)
5
+ puts IO.read(File.join(File.dirname(__FILE__), 'README'))
@@ -0,0 +1,63 @@
1
+
2
+ require 'facebooker/affiliation'
3
+ require 'facebooker/album'
4
+ require 'facebooker/education_info'
5
+ require 'facebooker/feed'
6
+ require 'facebooker/location'
7
+ require 'facebooker/model'
8
+ require 'facebooker/notifications'
9
+ require 'facebooker/parser'
10
+ require 'facebooker/photo'
11
+ require 'facebooker/cookie'
12
+ require 'facebooker/service'
13
+ require 'facebooker/server_cache'
14
+ require 'facebooker/data'
15
+ require 'facebooker/session'
16
+ require 'facebooker/tag'
17
+ require 'facebooker/user'
18
+ require 'facebooker/version'
19
+ require 'facebooker/work_info'
20
+ require 'facebooker/event'
21
+ require 'facebooker/group'
22
+ module Facebooker
23
+ VERSION="0.9.5"
24
+ class << self
25
+ def path_prefix
26
+ @path_prefix
27
+ end
28
+
29
+ def facebook_path_prefix=(path)
30
+ @facebook_path_prefix = path
31
+ end
32
+
33
+ def facebook_path_prefix
34
+ "/" + (@facebook_path_prefix || ENV["FACEBOOK_CANVAS_PATH"] || ENV["FACEBOOKER_RELATIVE_URL_ROOT"])
35
+ end
36
+
37
+ # Set the asset path to the canvas path for just this one request
38
+ # by definition, we will make this a canvas request
39
+ def with_asset_path_for_canvas
40
+ original_asset_host = ActionController::Base.asset_host
41
+ begin
42
+ ActionController::Base.asset_host = "http://apps.facebook.com"
43
+ request_for_canvas(true) do
44
+ yield
45
+ end
46
+ ensure
47
+ ActionController::Base.asset_host = original_asset_host
48
+ end
49
+ end
50
+
51
+ # If this request is_canvas_request
52
+ # then use the application name as the url root
53
+ def request_for_canvas(is_canvas_request)
54
+ original_path_prefix = @path_prefix
55
+ begin
56
+ @path_prefix = facebook_path_prefix if is_canvas_request
57
+ yield
58
+ ensure
59
+ @path_prefix = original_path_prefix
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ require 'facebooker/model'
2
+ module Facebooker
3
+ ##
4
+ # Represents a user's affiliation, for example, which educational institutions
5
+ # the user is associated with.
6
+ class Affiliation
7
+ include Model
8
+ attr_accessor :name, :status, :type, :year, :nid
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'facebooker/model'
2
+ module Facebooker
3
+ ##
4
+ # A simple representation of a photo album.
5
+ class Album
6
+ include Model
7
+ attr_accessor :aid, :cover_pid, :owner, :name, :created,
8
+ :modified, :description, :location, :link, :size
9
+
10
+ end
11
+ end