account_kit 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df9220ff202d223bfa4ebf2745f498e9d7aae322
4
- data.tar.gz: af33464d5cc2077af36864c9417de00fce6c1e48
3
+ metadata.gz: 2b10c307c2b20139c94e06aff179ceb92c73857e
4
+ data.tar.gz: 26d2891da10923bd96a7b2cd7b49a4a0a6301506
5
5
  SHA512:
6
- metadata.gz: 3d03a0ea2e459c89f99778a6b04e8f9b545c508d301725befca814a92b03013ea11db67f255638da99e121567d437b808c2d180d7c0496b5e0ae86d0e55734b7
7
- data.tar.gz: a8fad37cb8b830905c7d633eb52983900e3d64136defdc081d6b4a6c67092e9d0beebbc2edf86a59af8e59da72d59d00b47cb8c498c0821fb168d10cfc9e198f
6
+ metadata.gz: fc80d794371579bdc2f9aed343690358b250a7b9351ee8a8ec2d2baa3194f18dc7fbd63085339f6af56176ae21fa3b8d0d886440a08400773448a9f0885450ed
7
+ data.tar.gz: f32fbd064b504d92892a9b1de800b5c95796692fe5c81f5338f641c8daa5c5166e3dcb31dfe6bc70ad5e4e98961921854b4c0b8b063c3d15f2484e474614d6ea
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # AccountKit
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/account_kit`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
2
+ A light-weight Ruby API client for [Facebook Account Kit](https://developers.facebook.com/docs/accountkit) with no dependency.
3
+ A demo of the Account Kit can be found [here](https://www.facebook.com/FacebookforDevelopers/videos/10153620979588553/).
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,39 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ### Configuration
24
+
25
+ To work with Account Kit API, you need to provide Facebook App ID, Account Kit App Secret. If you don't specify an api version, the gem will call v1.0. You can also specify which version you want to use:
26
+
27
+ ```
28
+ AccountKit.configure do |config|
29
+ config.app_id = '1234566789'
30
+ config.app_secret = 'abcdefghijklm'
31
+ config.api_version = 'v1.0'
32
+ end
33
+ ```
34
+
35
+ ### API
36
+
37
+ We currently only supports [Authorization Code Flow](https://developers.facebook.com/docs/accountkit/accesstokens). Support for Client Access Token Flow will come in later versions.
38
+
39
+ To get access token, you need to provide the authorization code you get after user authenticate with Account Kit:
40
+
41
+ ```
42
+ response = AccountKit.access_token(authorization_code)
43
+ json_response = JSON.parse(response)
44
+ access_token = json_response['access_token']
45
+ ```
46
+
47
+ The response contains user's access token, use this token to get user's email or phone number:
48
+
49
+ ```
50
+ response = AccountKit.me(access_token)
51
+ json_response = JSON.parse(response)
52
+ email = json_response[:email][:address]
53
+ phone_code = json_response[:phone][:country_prefix]
54
+ phone_number = json_response[:phone][:national_number]
55
+ ```
26
56
 
27
57
  ## Development
28
58
 
@@ -32,7 +62,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
62
 
33
63
  ## Contributing
34
64
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/account_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Coffa/account_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
66
 
37
67
 
38
68
  ## License
data/account_kit.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'account_kit/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "account_kit"
8
8
  spec.version = AccountKit::VERSION
9
- spec.authors = ["Duc Le", "Long Nguyen", "Quy Truong"]
9
+ spec.authors = ["Duc Le", "Long Nguyen", "Quy Truong", "Vu Minh Tan"]
10
10
  spec.email = ["leminhducktvn@gmail.com", "longkt90@gmail.com", "sugiacupit@gmail.com"]
11
11
 
12
12
  spec.homepage = "https://github.com/Coffa/account_kit"
@@ -0,0 +1,64 @@
1
+ module AccountKit
2
+ extend self
3
+
4
+ GRANT_TYPE = 'authorization_code'.freeze
5
+ DEFAULT_VERSION = 'v1.0'
6
+
7
+ def access_token(code)
8
+ uri = build_access_token_uri(code)
9
+ send_payload(uri)
10
+ end
11
+
12
+ def me(access_token)
13
+ uri = build_me_uri(access_token)
14
+ send_payload(uri)
15
+ end
16
+
17
+ private
18
+
19
+ def send_payload(uri)
20
+ http = Net::HTTP.new(uri.host, uri.port)
21
+ http.use_ssl = true
22
+
23
+ request = Net::HTTP::Get.new(uri.request_uri)
24
+ request.content_type = 'application/json'
25
+
26
+ http.request(request)
27
+ end
28
+
29
+ def build_access_token_uri(code)
30
+ uri = URI(access_token_url)
31
+ uri.query = URI.encode_www_form(access_token_params(code))
32
+ uri
33
+ end
34
+
35
+ def build_me_uri(access_token)
36
+ uri = URI(me_url)
37
+ uri.query = URI.encode_www_form(access_token: access_token)
38
+ uri
39
+ end
40
+
41
+ def access_token_params(code)
42
+ {
43
+ grant_type: GRANT_TYPE,
44
+ code: code,
45
+ access_token: app_access_token
46
+ }
47
+ end
48
+
49
+ def access_token_url
50
+ "https://graph.accountkit.com/#{api_version}/access_token"
51
+ end
52
+
53
+ def me_url
54
+ "https://graph.accountkit.com/#{api_version}/me"
55
+ end
56
+
57
+ def app_access_token
58
+ ['AA', Config.app_id, Config.app_secret].join('|')
59
+ end
60
+
61
+ def api_version
62
+ Config.api_version || DEFAULT_VERSION
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ module AccountKit
2
+ module Config
3
+ extend self
4
+
5
+ attr_accessor :app_id
6
+ attr_accessor :app_secret
7
+ attr_accessor :api_version
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module AccountKit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/account_kit.rb CHANGED
@@ -2,7 +2,13 @@ require 'net/http'
2
2
  require 'json'
3
3
 
4
4
  require 'account_kit/version'
5
- require 'account_kit/api'
5
+ require 'account_kit/base'
6
+ require 'account_kit/config'
6
7
 
7
8
  module AccountKit
9
+ extend self
10
+
11
+ def configure
12
+ yield Config
13
+ end
8
14
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: account_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duc Le
8
8
  - Long Nguyen
9
9
  - Quy Truong
10
+ - Vu Minh Tan
10
11
  autorequire:
11
12
  bindir: exe
12
13
  cert_chain: []
@@ -75,7 +76,8 @@ files:
75
76
  - bin/console
76
77
  - bin/setup
77
78
  - lib/account_kit.rb
78
- - lib/account_kit/api.rb
79
+ - lib/account_kit/base.rb
80
+ - lib/account_kit/config.rb
79
81
  - lib/account_kit/version.rb
80
82
  homepage: https://github.com/Coffa/account_kit
81
83
  licenses:
@@ -1,68 +0,0 @@
1
- module AccountKit
2
- class API
3
- ME_URL = "https://graph.accountkit.com/#{VERSION}/me".freeze
4
- GRANT_TYPE = 'authorization_code'.freeze
5
-
6
- attr_accessor :app_id, :app_secret, :version
7
-
8
- def initialize(options = {})
9
- @app_id = options[:app_id] || ENV['ACCOUNT_KIT_APP_ID']
10
- @app_secret = options[:app_secret] || ENV['ACCOUNT_KIT_APP_SECRET']
11
- @version = options[:version] || ENV['ACCOUNT_KIT_VERSION']
12
- end
13
-
14
- def access_token(code)
15
- uri = build_access_token_uri(code)
16
- send_payload(uri)
17
- end
18
-
19
- def me(access_token)
20
- uri = build_me_uri(access_token)
21
- send_payload(uri)
22
- end
23
-
24
- private
25
-
26
- def send_payload(uri)
27
- http = Net::HTTP.new(uri.host, uri.port)
28
- http.use_ssl = true
29
-
30
- request = Net::HTTP::Get.new(uri.request_uri)
31
- request.content_type = 'application/json'
32
-
33
- http.request(request)
34
- end
35
-
36
- def build_access_token_uri(code)
37
- uri = URI(access_token_url)
38
- uri.query = URI.encode_www_form(access_token_params(code))
39
- uri
40
- end
41
-
42
- def build_me_uri(access_token)
43
- uri = URI(me_url)
44
- uri.query = URI.encode_www_form(access_token: access_token)
45
- uri
46
- end
47
-
48
- def access_token_params(code)
49
- {
50
- grant_type: GRANT_TYPE,
51
- code: code,
52
- access_token: app_access_token
53
- }
54
- end
55
-
56
- def access_token_url
57
- "https://graph.accountkit.com/#{@version}/access_token"
58
- end
59
-
60
- def me_url
61
- "https://graph.accountkit.com/#{@version}/me"
62
- end
63
-
64
- def app_access_token
65
- ['AA', @app_id, @app_secret].join('|')
66
- end
67
- end
68
- end