Module: FGraph::Rails::FGraphHelper
- Defined in:
- lib/fgraph/rails/fgraph_helper.rb
Instance Method Summary collapse
- #fgraph_access_token ⇒ Object
-
#fgraph_client ⇒ Object
Return FGraph::Client instance initialized with settings set in
fgraph.yml
. -
#fgraph_config ⇒ Object
Access FGraph.config initialized with values set in
[RAILS_ROOT]/config/fgraph.yml
. -
#fgraph_current_user ⇒ Object
Currently logged in facebook user.
- #fgraph_logged_in? ⇒ Boolean
-
#fgraph_picture_url(id, type = nil) ⇒ Object
Type Options *
square
- 50x50 (default) *small
- 50 pixels wide, variable height *normal
- 100 pixels wide, variable height *large
- 200 pixels wide, variable height. -
#fgraph_session(app_id = fgraph_config['app_id'], app_secret = fgraph_config['app_secret']) ⇒ Object
Return Facebook session, default to retrieve session from cookies.
-
#fgraph_session_cookies(app_id = fgraph_config['app_id'], app_secret = fgraph_config['app_secret']) ⇒ Object
Return Facebook session cookies.
-
#fgraph_user ⇒ Object
Alias for fgraph_current_user.
Instance Method Details
#fgraph_access_token ⇒ Object
53 54 55 56 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 53 def fgraph_access_token return unless fgraph_session fgraph_session['access_token'] end |
#fgraph_client ⇒ Object
Return FGraph::Client instance initialized with settings set in fgraph.yml
. Initialized with :access_token
as well if Facebook session exists.
75 76 77 78 79 80 81 82 83 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 75 def fgraph_client return @fgraph_client if @fgraph_client @fgraph_client = FGraph::Client.new( :client_id => fgraph_config['app_id'], :client_secret => fgraph_config['app_secret'], :access_token => fgraph_access_token ) end |
#fgraph_config ⇒ Object
Access FGraph.config initialized with values set in [RAILS_ROOT]/config/fgraph.yml
.
6 7 8 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 6 def fgraph_config FGraph.config || {} end |
#fgraph_current_user ⇒ Object
Currently logged in facebook user
63 64 65 66 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 63 def fgraph_current_user return @fgraph_current_user if @fgraph_current_user @fgraph_current_user = fgraph_client.me end |
#fgraph_logged_in? ⇒ Boolean
58 59 60 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 58 def fgraph_logged_in? return true if fgraph_session and fgraph_access_token end |
#fgraph_picture_url(id, type = nil) ⇒ Object
Type Options
-
square
- 50x50 (default) -
small
- 50 pixels wide, variable height -
normal
- 100 pixels wide, variable height -
large
- 200 pixels wide, variable height
93 94 95 96 97 98 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 93 def fgraph_picture_url(id, type=nil) id = FGraph.get_id(id) url = "http://graph.facebook.com/#{id}/picture" url += "?type=#{type}" if type url end |
#fgraph_session(app_id = fgraph_config['app_id'], app_secret = fgraph_config['app_secret']) ⇒ Object
Return Facebook session, default to retrieve session from cookies.
11 12 13 14 15 16 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 11 def fgraph_session(app_id = fgraph_config['app_id'], app_secret = fgraph_config['app_secret']) return @fgraph_session if @fgraph_session @fgraph_session = (app_id, app_secret) end |
#fgraph_session_cookies(app_id = fgraph_config['app_id'], app_secret = fgraph_config['app_secret']) ⇒ Object
Return Facebook session cookies.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 19 def (app_id = fgraph_config['app_id'], app_secret = fgraph_config['app_secret']) return @fgraph_session_cookies if @fgraph_session_cookies return if @fgraph_session_cookies == false # retrieve session from cookies = request.["fbs_#{app_id}"] if app_id.blank? or app_secret.blank? or .blank? return @fgraph_session_cookies = false end # Parse facebook cookies = CGI.parse(.gsub(/(^\"|\"$)/, '')) = {} .each do |key, value| [key] = value[0] end # Validate session cookies = '' = .sort .each do || += "#{[0]}=#{[1]}" if [0] != 'sig' end # Message digest does not match if Digest::MD5.hexdigest( + app_secret) != ['sig'] @fgraph_session_cookies = false end @fgraph_session_cookies = end |
#fgraph_user ⇒ Object
Alias for fgraph_current_user
69 70 71 |
# File 'lib/fgraph/rails/fgraph_helper.rb', line 69 def fgraph_user fgraph_current_user end |