fbk 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -17
- data/lib/fbk.rb +32 -13
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be4d53c3664aa08a1456e7576dd54cd28738815
|
4
|
+
data.tar.gz: 0784b66698e16e4e5205a8034c3933060bf2eb3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c7c5f7b0ce66b40d2cf631d5daf6c8d9ed0fea52d1493fab63228fed6ebb688c3fe155b641d4a44c2d94df3537f5c4fe48099f7e81571c316260e7f0fc874a2
|
7
|
+
data.tar.gz: 3e78182652ac7ab705bb3affa50605baa4c86dd53a2bed3d5108eefd6ad9c0e91e5aa0d37f4cb3205a2e5470fc400d3b202a45e1cede1bf4cdb7c3857862de35
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# FBK
|
2
2
|
|
3
|
-
|
3
|
+
You can use this library to implement Facebook login in your Ruby application.
|
4
4
|
|
5
5
|
We use this at [Chicisimo](https://github.com/chicisimo).
|
6
6
|
|
@@ -10,25 +10,22 @@ We use this at [Chicisimo](https://github.com/chicisimo).
|
|
10
10
|
require "sinatra"
|
11
11
|
require "fbk"
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
REDIRECT_URI = "https://something.com/login/fb/token"
|
14
|
+
|
15
|
+
FBK.configure do |config|
|
16
|
+
config.client_id = "xxx"
|
17
|
+
config.client_secret = "xxx"
|
18
|
+
end
|
16
19
|
|
17
|
-
|
20
|
+
get "/login/fb" do
|
21
|
+
redirect to(FBK.authorize_uri(redirect_uri: REDIRECT_URI, scope: %w{public_profile}))
|
18
22
|
end
|
19
23
|
|
20
24
|
get "/login/fb/token" do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
token = FBK.get_access_token(
|
27
|
-
client_id: client_id,
|
28
|
-
client_secret: client_secret,
|
29
|
-
redirect_uri: redirect_uri,
|
30
|
-
code: code) # => "H3UUnvsoymXtinqyofZtHqpqmTNkbJ7x5bpQFeFDGcmAy2THf9pfug2Eyx2ZSTnrqfMcDrUguzaytn4OZHCOyC6RsjEEM2MwHGWGVMwpzuSjWcjE1aS0dVPCTRrNm4bf6YmgVDS7JuUDb3Lxt0AoI0ucTmPdvnbrnkmunszoa0Y9KMJXyh2Nkf4PFgOo2bmjo6rVKzTY"
|
31
|
-
|
32
|
-
user = FBK.get_user_info(token) # => {:id=>"xxxx", :first_name=>"Pedro", :gender=>"male", :last_name=>"Giménez", :link=>"https://www.facebook.com/pedrotgimenez", :locale=>"en_US", :name=>"Pedro Giménez", :timezone=>1, :updated_time=>"1955-02-24T00:00:00+0000", :username=>"pedrotgimenez", :verified=>true}
|
25
|
+
code = params[:code]
|
26
|
+
|
27
|
+
access_token = FBK.get_access_token(redirect_uri: REDIRECT_URI, code: code) # => "H3UUnvsoymXtinqyofZtHqpqmTNkbJ7x5bpQFeFDGcmAy2THf9pfug2Eyx2ZSTnrqfMcDrUguzaytn4OZHCOyC6RsjEEM2MwHGWGVMwpzuSjWcjE1aS0dVPCTRrNm4bf6YmgVDS7JuUDb3Lxt0AoI0ucTmPdvnbrnkmunszoa0Y9KMJXyh2Nkf4PFgOo2bmjo6rVKzTY"
|
28
|
+
|
29
|
+
user = FBK.get_user_info(access_token) # => {:id=>"xxxx", :first_name=>"Pedro", :gender=>"male", :last_name=>"Giménez", :link=>"https://www.facebook.com/pedrotgimenez", :locale=>"en_US", :name=>"Pedro Giménez", :timezone=>1, :updated_time=>"1955-02-24T00:00:00+0000", :username=>"pedrotgimenez", :verified=>true}
|
33
30
|
end
|
34
31
|
```
|
data/lib/fbk.rb
CHANGED
@@ -1,35 +1,54 @@
|
|
1
1
|
require "json"
|
2
2
|
require "nestful"
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module FBK
|
5
|
+
extend self
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
FACEBOOK_URL = "https://facebook.com"
|
8
|
+
FACEBOOK_GRAPH_URL = "https://graph.facebook.com/v2.0"
|
9
9
|
|
10
|
-
|
10
|
+
attr_writer :client_id, :client_secret
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
|
16
|
+
def authorize_uri(params)
|
17
|
+
params[:client_id] = @client_id
|
18
|
+
params[:scope] = params[:scope].join(",")
|
19
|
+
|
20
|
+
query_string = params_to_query_string(params)
|
21
|
+
|
22
|
+
"#{FACEBOOK_URL}/dialog/oauth?#{query_string}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_access_token(params)
|
26
|
+
params[:client_id] = @client_id
|
27
|
+
params[:client_secret] = @client_secret
|
28
|
+
|
29
|
+
query_string = params_to_query_string(params)
|
30
|
+
|
31
|
+
response = Nestful.get("#{FACEBOOK_GRAPH_URL}/oauth/access_token?#{query_string}").body
|
11
32
|
response = parse_response(response)
|
12
33
|
|
13
34
|
response[:access_token]
|
14
35
|
end
|
15
36
|
|
16
|
-
def
|
17
|
-
response = Nestful.get("#{
|
18
|
-
JSON.parse(response
|
37
|
+
def get_user_info(token)
|
38
|
+
response = Nestful.get("#{FACEBOOK_GRAPH_URL}/me?access_token=#{token}").body
|
39
|
+
JSON.parse(response, symbolize_names: true)
|
19
40
|
end
|
20
41
|
|
21
42
|
private
|
22
43
|
|
23
|
-
def
|
24
|
-
params.
|
44
|
+
def params_to_query_string(params)
|
45
|
+
params.map { |k,v| "#{k}=#{v}" }.join("&")
|
25
46
|
end
|
26
47
|
|
27
|
-
def
|
48
|
+
def parse_response(response)
|
28
49
|
response.split("&").each_with_object({}) do |parameter, hash|
|
29
50
|
key, value = parameter.split("=")
|
30
51
|
hash[key.to_sym] = value
|
31
52
|
end
|
32
53
|
end
|
33
|
-
|
34
|
-
private_class_method :parse_params, :parse_response
|
35
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Gimenez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nestful
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
-
description: Interacts with
|
41
|
+
description: Interacts with Facebook's Graph API.
|
42
42
|
email:
|
43
43
|
- pedro@chicisimo.com
|
44
44
|
executables: []
|
@@ -71,5 +71,5 @@ rubyforge_project:
|
|
71
71
|
rubygems_version: 2.2.0
|
72
72
|
signing_key:
|
73
73
|
specification_version: 4
|
74
|
-
summary: Interacts with
|
74
|
+
summary: Interacts with Facebook's Graph API.
|
75
75
|
test_files: []
|