fbrails 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ lib/*.swp
6
+ *.swp
data/README ADDED
@@ -0,0 +1,20 @@
1
+ ## Developing ##
2
+
3
+ http://developers.facebook.com/docs/authentication/
4
+
5
+
6
+ auth = Fbrails::Auth.new(app_id,app_secret,app_url)
7
+
8
+
9
+ auth.redirect_url # get a redirect page to server-flow authorization
10
+
11
+ token = auth.token(code) # getting token from code which send back from facebook
12
+
13
+
14
+
15
+
16
+ @graph = Fbrails::Graph.new(token)
17
+
18
+ @graph.token_valid? # return true of false
19
+
20
+ @graph.me # return hash with your info or false
data/fbrails.gemspec CHANGED
@@ -2,6 +2,7 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "fbrails/version"
4
4
 
5
+
5
6
  Gem::Specification.new do |s|
6
7
  s.name = "fbrails"
7
8
  s.version = Fbrails::VERSION
@@ -1,3 +1,3 @@
1
1
  module Fbrails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/fbrails.rb CHANGED
@@ -1,7 +1,74 @@
1
1
  require "fbrails/version"
2
-
2
+ require 'net/https'
3
+ require 'json'
3
4
  module Fbrails
4
- def self.hello
5
- puts "hello"
5
+
6
+
7
+ class Auth
8
+ def initialize(app_id, secret, app_url)
9
+ @app_id = app_id
10
+ @app_url = app_url
11
+ @secret = secret
12
+ end
13
+
14
+ def token(code)
15
+ url = "https://graph.facebook.com/oauth/access_token?client_id=#{@app_id}&redirect_uri=#{@app_url}&client_secret=#{@secret}&code=#{code}"
16
+ resp = self.get(url)
17
+ if resp.include?("access_token=")
18
+ token = resp.body.gsub(/access_token=/, "").gsub(/&expires=\d+/,"")
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ def redirect_url
25
+ if !@app_id.blank? && !@app_url.blank?
26
+ "https://www.facebook.com/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{@app_url}"
27
+ else
28
+ ""
29
+ end
30
+ end
31
+ end
32
+
33
+ class Graph
34
+ def initialize(token)
35
+ @token = token
36
+ end
37
+
38
+
39
+ def token_valid?
40
+ url = "https://graph.facebook.com/me/?access_token=#{@token}"
41
+ result = Fbrails.get(url)
42
+ if result == false
43
+ return false
44
+ elsif result.has_key?("id")
45
+ return true
46
+ else
47
+ return nil
48
+ end
49
+
50
+ end
51
+
52
+ def me
53
+ url = "https://graph.facebook.com/me/?access_token=#{@token}"
54
+ Fbrails.get(url)
55
+ end
6
56
  end
57
+
58
+
59
+ def self.get(url)
60
+ uri = URI.parse(url)
61
+ http = Net::HTTP.new(uri.host,uri.port)
62
+ http.use_ssl = true
63
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
+ request = Net::HTTP::Get.new(uri.request_uri)
65
+ resp = http.request(request)
66
+ result = JSON.parse(resp.body)
67
+ if result.has_key?("error")
68
+ return false
69
+ else
70
+ return result
71
+ end
72
+ end
73
+
7
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -20,6 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
22
  - Gemfile
23
+ - README
23
24
  - Rakefile
24
25
  - fbrails.gemspec
25
26
  - lib/fbrails.rb