tenderlove-facebooker 1.0.16.20090319151701

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/CHANGELOG.rdoc +17 -0
  2. data/COPYING.rdoc +19 -0
  3. data/Manifest.txt +123 -0
  4. data/README.rdoc +103 -0
  5. data/Rakefile +86 -0
  6. data/TODO.rdoc +4 -0
  7. data/examples/desktop_login.rb +14 -0
  8. data/facebooker.gemspec +38 -0
  9. data/generators/facebook/facebook_generator.rb +14 -0
  10. data/generators/facebook/templates/config/facebooker.yml +46 -0
  11. data/generators/facebook/templates/public/javascripts/facebooker.js +99 -0
  12. data/generators/facebook_controller/USAGE +33 -0
  13. data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
  14. data/generators/facebook_controller/templates/controller.rb +7 -0
  15. data/generators/facebook_controller/templates/functional_test.rb +11 -0
  16. data/generators/facebook_controller/templates/helper.rb +2 -0
  17. data/generators/facebook_controller/templates/view.fbml.erb +2 -0
  18. data/generators/facebook_controller/templates/view.html.erb +2 -0
  19. data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
  20. data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
  21. data/generators/facebook_publisher/templates/publisher.rb +3 -0
  22. data/generators/facebook_scaffold/USAGE +27 -0
  23. data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
  24. data/generators/facebook_scaffold/templates/controller.rb +93 -0
  25. data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
  26. data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
  27. data/generators/facebook_scaffold/templates/helper.rb +2 -0
  28. data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
  29. data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
  30. data/generators/facebook_scaffold/templates/style.css +74 -0
  31. data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
  32. data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
  33. data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
  34. data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
  35. data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
  36. data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
  37. data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
  38. data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
  39. data/generators/publisher/publisher_generator.rb +14 -0
  40. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  41. data/generators/xd_receiver/xd_receiver_generator.rb +9 -0
  42. data/init.rb +72 -0
  43. data/install.rb +12 -0
  44. data/lib/facebooker/adapters/adapter_base.rb +87 -0
  45. data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
  46. data/lib/facebooker/adapters/facebook_adapter.rb +52 -0
  47. data/lib/facebooker/admin.rb +42 -0
  48. data/lib/facebooker/batch_request.rb +44 -0
  49. data/lib/facebooker/data.rb +57 -0
  50. data/lib/facebooker/feed.rb +78 -0
  51. data/lib/facebooker/logging.rb +51 -0
  52. data/lib/facebooker/mobile.rb +20 -0
  53. data/lib/facebooker/mock/service.rb +50 -0
  54. data/lib/facebooker/mock/session.rb +18 -0
  55. data/lib/facebooker/model.rb +135 -0
  56. data/lib/facebooker/models/affiliation.rb +10 -0
  57. data/lib/facebooker/models/album.rb +11 -0
  58. data/lib/facebooker/models/applicationproperties.rb +39 -0
  59. data/lib/facebooker/models/applicationrestrictions.rb +10 -0
  60. data/lib/facebooker/models/cookie.rb +10 -0
  61. data/lib/facebooker/models/education_info.rb +11 -0
  62. data/lib/facebooker/models/event.rb +28 -0
  63. data/lib/facebooker/models/friend_list.rb +16 -0
  64. data/lib/facebooker/models/group.rb +36 -0
  65. data/lib/facebooker/models/info_item.rb +10 -0
  66. data/lib/facebooker/models/info_section.rb +10 -0
  67. data/lib/facebooker/models/location.rb +8 -0
  68. data/lib/facebooker/models/notifications.rb +17 -0
  69. data/lib/facebooker/models/page.rb +27 -0
  70. data/lib/facebooker/models/photo.rb +12 -0
  71. data/lib/facebooker/models/tag.rb +12 -0
  72. data/lib/facebooker/models/user.rb +426 -0
  73. data/lib/facebooker/models/video.rb +9 -0
  74. data/lib/facebooker/models/work_info.rb +9 -0
  75. data/lib/facebooker/parser.rb +589 -0
  76. data/lib/facebooker/rails/controller.rb +304 -0
  77. data/lib/facebooker/rails/cucumber/world.rb +46 -0
  78. data/lib/facebooker/rails/cucumber.rb +28 -0
  79. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  80. data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
  81. data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
  82. data/lib/facebooker/rails/facebook_session_handling.rb +69 -0
  83. data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
  84. data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
  85. data/lib/facebooker/rails/helpers/fb_connect.rb +89 -0
  86. data/lib/facebooker/rails/helpers.rb +762 -0
  87. data/lib/facebooker/rails/integration_session.rb +38 -0
  88. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  89. data/lib/facebooker/rails/publisher.rb +526 -0
  90. data/lib/facebooker/rails/routing.rb +49 -0
  91. data/lib/facebooker/rails/test_helpers.rb +68 -0
  92. data/lib/facebooker/rails/utilities.rb +22 -0
  93. data/lib/facebooker/server_cache.rb +24 -0
  94. data/lib/facebooker/service.rb +94 -0
  95. data/lib/facebooker/session.rb +584 -0
  96. data/lib/facebooker/version.rb +9 -0
  97. data/lib/facebooker.rb +174 -0
  98. data/lib/net/http_multipart_post.rb +123 -0
  99. data/lib/tasks/facebooker.rake +18 -0
  100. data/lib/tasks/tunnel.rake +46 -0
  101. data/rails/init.rb +1 -0
  102. data/setup.rb +1585 -0
  103. data/templates/layout.erb +24 -0
  104. data/test/facebooker/adapters_test.rb +96 -0
  105. data/test/facebooker/admin_test.rb +102 -0
  106. data/test/facebooker/batch_request_test.rb +83 -0
  107. data/test/facebooker/data_test.rb +86 -0
  108. data/test/facebooker/logging_test.rb +43 -0
  109. data/test/facebooker/mobile_test.rb +45 -0
  110. data/test/facebooker/model_test.rb +123 -0
  111. data/test/facebooker/models/event_test.rb +15 -0
  112. data/test/facebooker/models/user_test.rb +295 -0
  113. data/test/facebooker/rails/publisher_test.rb +452 -0
  114. data/test/facebooker/rails_integration_test.rb +1312 -0
  115. data/test/facebooker/server_cache_test.rb +44 -0
  116. data/test/facebooker/session_test.rb +614 -0
  117. data/test/facebooker_test.rb +925 -0
  118. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  119. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  120. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  121. data/test/net/http_multipart_post_test.rb +52 -0
  122. data/test/rails_test_helper.rb +11 -0
  123. data/test/test_helper.rb +66 -0
  124. metadata +217 -0
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+ require File.dirname(__FILE__)+'/../../vendor/plugins/facebooker/lib/facebooker/rails/test_helpers.rb'
3
+
4
+ class <%= class_name %>ControllerTest < ActionController::TestCase
5
+ include Facebooker::Rails::TestHelpers
6
+
7
+ # Replace this with your real tests.
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ module <%= class_name %>Helper
2
+ end
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= action %></h1>
2
+ <p>Find me in <%= path %></p>
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= action %></h1>
2
+ <p>Find me in <%= path %></p>
@@ -0,0 +1,14 @@
1
+ class FacebookPublisherGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.directory "app/models"
5
+ m.template "publisher.rb", "app/models/#{file_name}_publisher.rb"
6
+ migration_file_name="create_facebook_templates"
7
+ # unless m.migration_exists?(migration_file_name)
8
+ # THis should work, but it doesn't. So we re-implement it instead
9
+ if Dir.glob(File.join(RAILS_ROOT,"db","migrate","[0-9]*_*.rb")).grep(/[0-9]+_create_facebook_templates.rb$/).blank?
10
+ m.migration_template "create_facebook_templates.rb", "db/migrate", :migration_file_name=>migration_file_name
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class CreateFacebookTemplates < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :facebook_templates, :force => true do |t|
4
+ t.string :template_name, :null => false
5
+ t.string :content_hash, :null => false
6
+ t.string :bundle_id, :null => true
7
+ end
8
+ add_index :facebook_templates, :template_name, :unique => true
9
+ end
10
+
11
+ def self.down
12
+ remove_index :facebook_templates, :template_name
13
+ drop_table :facebook_templates
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %>Publisher < Facebooker::Rails::Publisher
2
+
3
+ end
@@ -0,0 +1,27 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views, along with a full test suite. The resource is ready to use as a
4
+ starting point for your restful, resource-oriented application.
5
+
6
+ Pass the name of the model, either CamelCased or under_scored, as the first
7
+ argument, and an optional list of attribute pairs.
8
+
9
+ Attribute pairs are column_name:sql_type arguments specifying the
10
+ model's attributes. Timestamps are added by default, so you don't have to
11
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
12
+
13
+ You don't have to think up every attribute up front, but it helps to
14
+ sketch out a few so you can start working with the resource immediately.
15
+
16
+ For example, `scaffold post title:string body:text published:boolean`
17
+ gives you a model with those three attributes, a controller that handles
18
+ the create/show/update/destroy, forms to create and edit your posts, and
19
+ an index that lists them all, as well as a map.resources :posts
20
+ declaration in config/routes.rb.
21
+
22
+ Also, it creates Facebook view templates and functional tests.
23
+
24
+ Examples:
25
+ `./script/generate scaffold post` # no attributes, view will be anemic
26
+ `./script/generate scaffold post title:string body:text published:boolean`
27
+ `./script/generate scaffold purchase order_id:integer amount:decimal`
@@ -0,0 +1,118 @@
1
+ class Rails::Generator::Commands::Create
2
+ def register_fbml_mime_type_alias
3
+ path = destination_path('config/initializers/mime_types.rb')
4
+ content = "Mime::Type.register_alias 'text/html', :fbml"
5
+ unless File.read(path).match(Regexp.escape(content))
6
+ logger.register "text/html, :fbml"
7
+ File.open(path, 'a') { |file| file.write(content) }
8
+ end
9
+ end
10
+ end
11
+ class Rails::Generator::Commands::Destroy
12
+ def register_fbml_mime_type_alias
13
+ # do nothing
14
+ end
15
+ end
16
+
17
+ class FacebookScaffoldGenerator < Rails::Generator::NamedBase
18
+ default_options :skip_timestamps => false, :skip_migration => false
19
+
20
+ attr_reader :controller_name,
21
+ :controller_class_path,
22
+ :controller_file_path,
23
+ :controller_class_nesting,
24
+ :controller_class_nesting_depth,
25
+ :controller_class_name,
26
+ :controller_underscore_name,
27
+ :controller_singular_name,
28
+ :controller_plural_name
29
+ alias_method :controller_file_name, :controller_underscore_name
30
+ alias_method :controller_table_name, :controller_plural_name
31
+
32
+ def initialize(runtime_args, runtime_options = {})
33
+ super
34
+
35
+ @controller_name = @name.pluralize
36
+
37
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
38
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
39
+ @controller_singular_name=base_name.singularize
40
+ if @controller_class_nesting.empty?
41
+ @controller_class_name = @controller_class_name_without_nesting
42
+ else
43
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
44
+ end
45
+ end
46
+
47
+ def manifest
48
+ record do |m|
49
+ # Check for class naming collisions.
50
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
51
+ m.class_collisions(class_path, "#{class_name}")
52
+
53
+ # Controller, helper, views, test and stylesheets directories.
54
+ m.directory(File.join('app/models', class_path))
55
+ m.directory(File.join('app/controllers', controller_class_path))
56
+ m.directory(File.join('app/helpers', controller_class_path))
57
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
58
+ m.directory(File.join('app/views/layouts', controller_class_path))
59
+ m.directory(File.join('test/functional', controller_class_path))
60
+ m.directory(File.join('test/unit', class_path))
61
+ m.directory(File.join('public/stylesheets', class_path))
62
+
63
+ for action in scaffold_views
64
+ m.template(
65
+ "view_#{action}.html.erb",
66
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
67
+ )
68
+ m.template(
69
+ "view_#{action}.fbml.erb",
70
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.fbml.erb")
71
+ )
72
+ end
73
+
74
+ # Layout and stylesheet.
75
+ m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
76
+ m.template('layout.fbml.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.fbml.erb"))
77
+ m.template('style.css', 'public/stylesheets/scaffold.css')
78
+ m.template('facebook_style.css', 'public/stylesheets/facebook_scaffold.css')
79
+
80
+ m.template(
81
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
82
+ )
83
+
84
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
85
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
86
+
87
+ m.route_resources controller_file_name
88
+
89
+ m.dependency 'model', [name] + @args, :collision => :skip
90
+
91
+ m.register_fbml_mime_type_alias
92
+ end
93
+ end
94
+
95
+ protected
96
+ # Override with your own usage banner.
97
+ def banner
98
+ "Usage: #{$0} scaffold ModelName [field:type, field:type]"
99
+ end
100
+
101
+ def add_options!(opt)
102
+ opt.separator ''
103
+ opt.separator 'Options:'
104
+ opt.on("--skip-timestamps",
105
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
106
+ opt.on("--skip-migration",
107
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
108
+ end
109
+
110
+ def scaffold_views
111
+ %w[ index show new edit ]
112
+ end
113
+
114
+ def model_name
115
+ class_name.demodulize
116
+ end
117
+
118
+ end
@@ -0,0 +1,93 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ # GET /<%= table_name %>
3
+ # GET /<%= table_name %>.xml
4
+ def index
5
+ @<%= table_name %> = <%= class_name %>.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.fbml # index.fbml.erb
10
+ format.xml { render :xml => @<%= table_name %> }
11
+ end
12
+ end
13
+
14
+ # GET /<%= table_name %>/1
15
+ # GET /<%= table_name %>/1.xml
16
+ def show
17
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.fbml # show.fbml.erb
22
+ format.xml { render :xml => @<%= file_name %> }
23
+ end
24
+ end
25
+
26
+ # GET /<%= table_name %>/new
27
+ # GET /<%= table_name %>/new.xml
28
+ def new
29
+ @<%= file_name %> = <%= class_name %>.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.fbml # new.fbml.erb
34
+ format.xml { render :xml => @<%= file_name %> }
35
+ end
36
+ end
37
+
38
+ # GET /<%= table_name %>/1/edit
39
+ def edit
40
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
41
+ end
42
+
43
+ # POST /<%= table_name %>
44
+ # POST /<%= table_name %>.xml
45
+ def create
46
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
47
+
48
+ respond_to do |format|
49
+ if @<%= file_name %>.save
50
+ flash[:notice] = '<%= class_name %> was successfully created.'
51
+ format.html { redirect_to(@<%= file_name %>) }
52
+ format.fbml { redirect_to(@<%= file_name %>) }
53
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
54
+ else
55
+ format.html { render :action => "new" }
56
+ format.fbml { render :action => "new" }
57
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
58
+ end
59
+ end
60
+ end
61
+
62
+ # PUT /<%= table_name %>/1
63
+ # PUT /<%= table_name %>/1.xml
64
+ def update
65
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
66
+
67
+ respond_to do |format|
68
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
69
+ flash[:notice] = '<%= class_name %> was successfully updated.'
70
+ format.html { redirect_to(@<%= file_name %>) }
71
+ format.fbml { redirect_to(@<%= file_name %>) }
72
+ format.xml { head :ok }
73
+ else
74
+ format.html { render :action => "edit" }
75
+ format.fbml { render :action => "edit" }
76
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
77
+ end
78
+ end
79
+ end
80
+
81
+ # DELETE /<%= table_name %>/1
82
+ # DELETE /<%= table_name %>/1.xml
83
+ def destroy
84
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
85
+ @<%= file_name %>.destroy
86
+
87
+ respond_to do |format|
88
+ format.html { redirect_to(<%= table_name %>_url) }
89
+ format.fbml { redirect_to(<%= table_name %>_url) }
90
+ format.xml { head :ok }
91
+ end
92
+ end
93
+ end