doesfacebook 0.4.3 → 0.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,8 +3,8 @@
3
3
  The Awexome Labs rails plugin for handling Facebook application credentials and authentication.
4
4
  Also provides helpers and convenience methods for canvas applications.
5
5
 
6
- You may also be interested in accessing content on the Facebook Open Graph. For that, consider
7
- this gem's brother from the same mother, DoesOpenGraph
6
+ You may also be interested in accessing content on Facebooks Open Graph API. For that, consider
7
+ this gem's brother from the same mother, DoesOpenGraph[https://github.com/awexome/doesopengraph].
8
8
 
9
9
 
10
10
  == Installation
@@ -15,65 +15,86 @@ To install the gem, do the usual:
15
15
 
16
16
  If you plan on using DoesFacebook in a project with a Gemfile:
17
17
 
18
- gem "doesfacebook", ">=0.3.2"
18
+ gem "doesfacebook"
19
19
 
20
- You can live on the edge, too, if you like:
20
+ You can live on the edge, too:
21
21
 
22
- gem "doesfacebook", ">=0.3.2", :git=>"git://github.com/awexome/doesfacebook.git"
22
+ gem "doesfacebook", :git=>"git://github.com/awexome/doesfacebook.git"
23
23
 
24
24
 
25
25
  == Configuration
26
26
 
27
- You configure DoesFacebook in much the same way you'll configure other Facebook integration
28
- helper plugins. Add a "doesfacebook.yml" file to you config/ directory with the a config for
29
- each environment in the following format:
27
+ You can configure your Facebook applications for use in your Rails project by specifying them
28
+ within the "doesfacebook.yml" file under config/
30
29
 
31
- development:
30
+ To generate a boilerplate configuration file, run the generator:
31
+
32
+ rails generate does_facebook:config
33
+
34
+ The appropriate application configuration will be loaded for each request based on the callback
35
+ path of your application. The host of each incoming request will be compared against the callback_url
36
+ or ssl_callback_url fields of your app. A sample configuration looks like this:
37
+
38
+ my_sweet_facebook_app:
32
39
  app_id: 1234567890
33
- api_key: 1234567890abcdefghijklmnopqrsttuv
34
- secret_key: 1234567890abcdefghijklmnopqrsttuv
35
- canvas_name: your_canvas_name
36
- callback_url: http://your.dev.server.com/and/path
40
+ secret_key: a1b2c3d4e5f6g7h8i9j0k1l
41
+ canvas_name: my_sweet_canvas_name
42
+ callback_url: http://your.server.com/and/path
43
+ ssl_callback_url: https://your.secure.server.com/and/path
44
+
45
+ Top-level keys in this file are configuration names. This allows you to specify many different apps
46
+ which can be used within any environment, provided they have different callback patterns.
47
+
48
+ If you do have one app for each environment, however, naming an app after the corresponding Rails
49
+ environment ("development","production",etc.) will provide a fallback should the request host not
50
+ directly resolve to a callback_url
51
+
52
+ The typical configuration options are as follows:
53
+
54
+ * app_id: Facebook ID of your application
55
+ * secret_key: Facebook secret key of your application (used to parse and validate Facebook requests)
56
+ * canvas_name: The "myapp" from "http://apps.facebook.com/myapp" used frequently for link generation and redirection
57
+ * callback_url: The server callback URL for your app. Used to identify the proper configuration which should be loaded for each request.
58
+ * ssl_callback_url: The server callback for secure, HTTPS requests. Required for production apps. Can be different from your non-secure callback_url
37
59
 
38
60
  These parameters relate to settings in the Facebook Developers application configuration panel,
39
- and should be easy to copy and paste in as you need for each application.
61
+ which you can review at https://developers.facebook.com/apps and should be easy to copy and paste
62
+ in as you need for each application.
40
63
 
41
64
 
42
65
  == Usage
43
66
 
44
- To parse requests, add the following declaration to your controller:
67
+ To parse and validate requests from Facebook, simply add the following declaration to your controller:
45
68
 
46
69
  does_facebook
47
70
 
48
- Now, with each incoming request, DoesFacebook will parse the signed_request_parameter against your
71
+ Now, with each incoming request, DoesFacebook will parse the "signed_request" parameter against your
49
72
  application's keys, as described at http://developers.facebook.com/docs/authentication/signed_request
50
73
 
51
- This allows your application to verify requests from Facebook, properly handle Facebook POSTs via
52
- canvas and within page tabs.
53
-
54
- You also get helpers for your views that will make many aspects of developing on the Facebook platform
55
- easier:
74
+ This allows your application to verify and properly handle requests from Facebook, as well as view any
75
+ additional data and parameters your app is sent by Facebook, such as the current user ID, active
76
+ Facebook page, and more.
56
77
 
57
- app_id
58
- => The current application's id, parsed from doesfacebook.yml
78
+ Within your controllers which declare _does_facebook_ (or inherit from a controller which does), you
79
+ will now have access to the following niceties:
59
80
 
60
- app_callback_url
61
- => The current application's callback URL, parsed from doesfacebook.yml
81
+ * redirect_to_canvas: Generate a JS top frame redirection which keeps users inside your application's canvas as opposed to loading links only within your app's iframe
82
+ * @fbparams: This hash will be set with all keys and values Facebook provided to you for this request (things like user id, page id, logged in status, region, locale, etc.)
62
83
 
63
- app_canvas_name
64
- => The current application's canvas shortname, parsed from doesfacebook.yml
84
+ Within your views, you have access to a wealth of helpers that will make many aspects of developing
85
+ against the Facebook platform easier:
65
86
 
66
- app_canvas_url
67
- => The full URL to the application canvas (e.g., http://apps.facebook.com/your_canvas_name)
87
+ * app_id: The current application's id, parsed from doesfacebook.yml
88
+ * app_callback_url: The current application's callback URL, parsed from doesfacebook.yml
89
+ * app_canvas_name: The current application's canvas shortname, parsed from doesfacebook.yml
90
+ * app_canvas_url: The full URL to the application canvas (e.g., http://apps.facebook.com/myapp)
91
+ * url_for_canvas(url_opts={}): Like the standard url_for, but ensures the endpoint is in the Facebook canvas
92
+ * link_to_canvas(text, url_opts={}, html_opts={}): Use as you would the regular link_to helper; generates links to the canvas and properly targets the link to "_top" frame to keep app within canvas and not break into your iframe
68
93
 
69
- url_for_canvas(url_opts={})
70
- => Like the standard url_for, but ensures the endpoint is in the Facebook canvas
94
+ Other helpers and useful shortcuts being added regularly.
71
95
 
72
- link_to_canvas(text, url_opts={}, html_opts={})
73
- => Use as you would the regular link_to helper; generates links to the canvas and properly
74
- targets the link to "_top"
75
96
 
76
- Other helpers and useful shortcuts being added regularly.
97
+ Now, you are armed with the tools you need to build an app within the Facebook platform simply and quickly.
77
98
 
78
99
 
79
100
 
@@ -81,5 +102,8 @@ Other helpers and useful shortcuts being added regularly.
81
102
 
82
103
  == Copyright
83
104
 
84
- Copyright 2011 Awexome Labs, LLC http://awexomelabs.com
105
+ Copyright 2011-12 Awexome Labs, LLC
106
+ http://awexomelabs.com
107
+ http://facebook.com/AwexomeLabs
108
+ http://twitter.com/awexomelabs
85
109
 
@@ -10,11 +10,6 @@ module DoesFacebookHelper
10
10
  controller.send(:facebook_config)[:app_id]
11
11
  end
12
12
 
13
- # Return the API key of the current application to the view
14
- def api_key
15
- controller.send(:facebook_config)[:api_key]
16
- end
17
-
18
13
  # Return the current app callback URL
19
14
  def app_callback_url
20
15
  if request.ssl?
@@ -6,13 +6,35 @@ module DoesFacebook
6
6
 
7
7
  protected
8
8
 
9
- # Access the Facebook-specific configuration for the given environment:
9
+ # Load app configuration by Facebook callback path with a fallback to config
10
+ # defined with name matching our current environment:
10
11
  def facebook_config
11
- @@facebook_config ||= HashWithIndifferentAccess.new(all_facebook_config[Rails.env])
12
+ app_settings = all_facebook_config.find do |app_name, settings|
13
+ (settings["ssl_callback_url"] || settings["callback_url"]).match(/https?:\/\/#{request.host}/)
14
+ end
15
+ if app_settings
16
+ app_name, app_config = app_settings
17
+ if app_config
18
+ Rails.logger.debug(" Facebook configuration for app \"#{app_name}\" loaded via request to host #{request.host}")
19
+ return @@facebook_config = HashWithIndifferentAccess.new(app_config)
20
+ end
21
+ end
22
+
23
+ @@facebook_config = HashWithIndifferentAccess.new(all_facebook_config[Rails.env])
24
+ unless @@facebook_config.blank?
25
+ Rails.logger.debug(" Facebook configuration loaded for app based on environment \"#{Rails.env}\"")
26
+ else
27
+ Rails.logger.warn(" Facebook configuration could not be found. doesfacebook.yml has no app for host #{request.host}")
28
+ Rails.logger.warn(" Facebook configuration can be generated by running \"rails generate does_facebook:config\"")
29
+ end
30
+
31
+ return @@facebook_config
12
32
  end
13
33
 
34
+
14
35
  # Load configuration from YAML file for all environments:
15
36
  def all_facebook_config
37
+ return @@all_facebook_config if @all_facebook_config
16
38
  config_file = File.join(Rails.root, "config", "doesfacebook.yml")
17
39
  if File.exist?(config_file)
18
40
  return @@all_facebook_config ||= YAML.load(File.open( config_file ))
@@ -22,6 +22,8 @@ module DoesFacebook
22
22
  logger.info " Facebook Signed Request is not Valid. Ensure request is from Facebook."
23
23
  raise "DoesFacebook: Invalid Signed Request. Ensure request is from Facebook."
24
24
  end
25
+ else
26
+ logger.info " Facebook Signed Request cannot be verified without app configuration"
25
27
  end
26
28
  end
27
29
  end
@@ -0,0 +1,23 @@
1
+ # AWEXOME LABS
2
+ # DoesFacebook
3
+ #
4
+ # Middleware - Rack adapter for POST conversion, etc.
5
+
6
+ module DoesFacebook
7
+ class Middleware
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ request = Rack::Request.new(env)
15
+ if request.POST["signed_request"]
16
+ env["REQUEST_METHOD"] = "GET"
17
+ Rails.logger.info(" Facebook POST request converted to GET request")
18
+ end
19
+ @app.call(env)
20
+ end
21
+
22
+ end
23
+ end # DoesFacebook
data/lib/doesfacebook.rb CHANGED
@@ -9,6 +9,9 @@ require 'doesfacebook/config'
9
9
  require 'doesfacebook/filters'
10
10
  require 'doesfacebook/controls'
11
11
  require 'doesfacebook/session'
12
+ require 'doesfacebook/middleware'
13
+
14
+ require 'generators/doesfacebook/config/config_generator'
12
15
 
13
16
  module DoesFacebook
14
17
 
@@ -17,6 +20,13 @@ module DoesFacebook
17
20
  # engine_name :doesfacebook
18
21
  end
19
22
 
23
+ # Create a Railtie for Rack, config injection
24
+ class Railtie < Rails::Railtie
25
+ initializer "doesfacebook.init" do |app|
26
+ app.middleware.use DoesFacebook::Middleware
27
+ end
28
+ end
29
+
20
30
  # Return the current working version of DoesFacebook from VERSION file:
21
31
  def self.version
22
32
  @@version ||= File.open(File.join(File.dirname(__FILE__), "..", "VERSION"), "r").read
@@ -0,0 +1,21 @@
1
+ # AWEXOME LABS
2
+ # DoesFacebook Config Generator
3
+
4
+ require 'rails/generators'
5
+ require 'rails/generators/named_base'
6
+
7
+ module DoesFacebook
8
+ module Generators
9
+ class ConfigGenerator < ::Rails::Generators::Base
10
+
11
+ desc "Creates a boilerplate DoesFacebook configuration file at config/doesfacebook.yml"
12
+
13
+ source_root File.expand_path("../templates", __FILE__)
14
+
15
+ def create_config_file
16
+ template "doesfacebook.yml", File.join("config","doesfacebook.yml")
17
+ end
18
+
19
+ end
20
+ end #Generators
21
+ end #DoesFacebook
@@ -0,0 +1,32 @@
1
+ # AWEXOME LABS
2
+ # DoesFacebook Configuration File
3
+ #
4
+ # The appropriate application configuration will be loaded for each
5
+ # request based on the callback path of your application. The host
6
+ # of each incoming request will be compared against the callback_url
7
+ # or ssl_callback_url fields of your app.
8
+ #
9
+ # Top-level keys in this file are configuration names. If you have one
10
+ # app for each environment, however, naming an app after the corresponding
11
+ # Rails environment ("development","production",etc.) will provide a
12
+ # fallback should the request host not directly resolve to a callback_url
13
+ #
14
+
15
+ name_of_app:
16
+ app_id: 1234567890
17
+ secret_key: 1234567890abcdefghijklmnopqrsttuv
18
+ canvas_name: your_canvas_name
19
+ callback_url: http://your.dev.server.com/and/path
20
+
21
+ name_of_another_app:
22
+ app_id: 1234567890
23
+ secret_key: 1234567890abcdefghijklmnopqrsttuv
24
+ canvas_name: your_canvas_name
25
+ callback_url: http://your.dev.server.com/and/path
26
+
27
+ name_of_production_app:
28
+ app_id: 1234567890
29
+ secret_key: 1234567890abcdefghijklmnopqrsttuv
30
+ canvas_name: your_canvas_name
31
+ callback_url: http://your.server.com/and/path
32
+ ssl_callback_url: https://your.secure.server.com/and/path
metadata CHANGED
@@ -1,86 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: doesfacebook
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.4.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0.pre
5
+ prerelease: 6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - mccolin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-18 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: bundler
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2158889540 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
23
21
  version: 1.0.0
24
22
  type: :development
25
23
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *2158889540
25
+ - !ruby/object:Gem::Dependency
28
26
  name: jeweler
29
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &2158888940 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
34
32
  version: 1.5.1
35
33
  type: :development
36
34
  prerelease: false
37
- version_requirements: *id002
35
+ version_requirements: *2158888940
38
36
  description: Paper-thin Facebook validation and signed request parsing Rails plugin
39
37
  email: info@awexomelabs.com
40
38
  executables: []
41
-
42
39
  extensions: []
43
-
44
- extra_rdoc_files:
40
+ extra_rdoc_files:
45
41
  - LICENSE
46
42
  - README.rdoc
47
- files:
43
+ files:
48
44
  - app/helpers/does_facebook_helper.rb
49
- - config/doesfacebook.yml.example
50
45
  - lib/doesfacebook.rb
51
46
  - lib/doesfacebook/config.rb
52
47
  - lib/doesfacebook/controls.rb
53
48
  - lib/doesfacebook/filters.rb
49
+ - lib/doesfacebook/middleware.rb
54
50
  - lib/doesfacebook/session.rb
51
+ - lib/generators/doesfacebook/config/config_generator.rb
52
+ - lib/generators/doesfacebook/config/templates/doesfacebook.yml
55
53
  - LICENSE
56
54
  - README.rdoc
57
- has_rdoc: true
58
55
  homepage: http://awexomelabs.com/
59
56
  licenses: []
60
-
61
57
  post_install_message:
62
58
  rdoc_options: []
63
-
64
- require_paths:
59
+ require_paths:
65
60
  - lib
66
- required_ruby_version: !ruby/object:Gem::Requirement
61
+ required_ruby_version: !ruby/object:Gem::Requirement
67
62
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
68
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
69
+ requirements:
70
+ - - ! '>'
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.1
78
73
  requirements: []
79
-
80
74
  rubyforge_project:
81
- rubygems_version: 1.5.2
75
+ rubygems_version: 1.8.17
82
76
  signing_key:
83
77
  specification_version: 3
84
78
  summary: Paper-thin Facebook validation and signed request parsing Rails plugin
85
79
  test_files: []
86
-
@@ -1,26 +0,0 @@
1
- # AWEXOME LABS
2
- # Beyond12
3
- #
4
- # Example Facebook Configuration File
5
-
6
- development:
7
- app_id: 1234567890
8
- api_key: 1234567890abcdefghijklmnopqrsttuv
9
- secret_key: 1234567890abcdefghijklmnopqrsttuv
10
- canvas_name: your_canvas_name
11
- callback_url: http://your.dev.server.com/and/path
12
-
13
- staging:
14
- app_id: 1234567890
15
- api_key: 1234567890abcdefghijklmnopqrsttuv
16
- secret_key: 1234567890abcdefghijklmnopqrsttuv
17
- canvas_name: your_canvas_name
18
- callback_url: http://your.dev.server.com/and/path
19
-
20
- production:
21
- app_id: 1234567890
22
- api_key: 1234567890abcdefghijklmnopqrsttuv
23
- secret_key: 1234567890abcdefghijklmnopqrsttuv
24
- canvas_name: your_canvas_name
25
- callback_url: http://your.server.com/and/path
26
- ssl_callback_url: https://your.secure.server.com/and/path