Class: Fbrails::Auth
- Inherits:
-
Object
- Object
- Fbrails::Auth
- Defined in:
- lib/fbrails/auth.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app_id, secret, app_url) ⇒ Auth
constructor
A new instance of Auth.
- #redirect_url ⇒ Object
- #token(code) ⇒ Object
Constructor Details
#initialize(app_id, secret, app_url) ⇒ Auth
Returns a new instance of Auth.
3 4 5 6 7 |
# File 'lib/fbrails/auth.rb', line 3 def initialize(app_id, secret, app_url) @app_id = app_id @app_url = app_url @secret = secret end |
Class Method Details
.token_valid?(token, expires = false) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fbrails/auth.rb', line 31 def self.token_valid?(token,expires = false) if expires.class == Time && expires < Time.new return false end url = "https://graph.facebook.com/me/?access_token=#{token}" begin result = Fbrails.get(url) rescue return false end if result == false return false elsif result.has_key?("id") return true else return nil end end |
Instance Method Details
#redirect_url ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/fbrails/auth.rb', line 9 def redirect_url if !@app_id.blank? && !@app_url.blank? "https://www.facebook.com/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{@app_url}" else "" end end |
#token(code) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fbrails/auth.rb', line 17 def token(code) url = "https://graph.facebook.com/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@app_url}&client_secret=#{@secret}&code=#{code}" resp = Fbrails.get(url,true) if resp.include?("access_token=") hash = Hash.new expire = resp.scan(/\d+/).last.to_i hash[:expires] = Time.new + expire hash[:token] = resp.gsub(/access_token=/, "").gsub(/&expires=\d+/,"") return hash else nil end end |