account_kit 0.0.1 → 0.1.0

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: deaa212d30c1cb898d24bb6abdacb2213cab55fa
4
- data.tar.gz: f576b1d8a7d8cc33f140e1aee90cba658c061ab5
3
+ metadata.gz: df9220ff202d223bfa4ebf2745f498e9d7aae322
4
+ data.tar.gz: af33464d5cc2077af36864c9417de00fce6c1e48
5
5
  SHA512:
6
- metadata.gz: 9de6d85cefdc083c8ced8be69e52fa2791d5a47262008405752a77c9e5b0cd58d9e37fddc4634f7a2d8a464ee1aa5117cd17680855ac39f6aeec17c6ffea128c
7
- data.tar.gz: debd8cc912b78059f55c5fde16126e4afadc8ee9c617c1d2c08093629510985aa556b71df99561f059f084755f4870164a1ae16120a9fa55d55f800245ca10d8
6
+ metadata.gz: 3d03a0ea2e459c89f99778a6b04e8f9b545c508d301725befca814a92b03013ea11db67f255638da99e121567d437b808c2d180d7c0496b5e0ae86d0e55734b7
7
+ data.tar.gz: a8fad37cb8b830905c7d633eb52983900e3d64136defdc081d6b4a6c67092e9d0beebbc2edf86a59af8e59da72d59d00b47cb8c498c0821fb168d10cfc9e198f
@@ -0,0 +1,68 @@
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
@@ -1,3 +1,3 @@
1
1
  module AccountKit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/account_kit.rb CHANGED
@@ -1,5 +1,8 @@
1
- require "account_kit/version"
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ require 'account_kit/version'
5
+ require 'account_kit/api'
2
6
 
3
7
  module AccountKit
4
- # Your code goes here...
5
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: account_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duc Le
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2016-04-13 00:00:00.000000000 Z
13
+ date: 2016-04-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -75,6 +75,7 @@ files:
75
75
  - bin/console
76
76
  - bin/setup
77
77
  - lib/account_kit.rb
78
+ - lib/account_kit/api.rb
78
79
  - lib/account_kit/version.rb
79
80
  homepage: https://github.com/Coffa/account_kit
80
81
  licenses:
@@ -96,8 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  version: '0'
97
98
  requirements: []
98
99
  rubyforge_project:
99
- rubygems_version: 2.5.1
100
+ rubygems_version: 2.4.8
100
101
  signing_key:
101
102
  specification_version: 4
102
103
  summary: Gem for Facebook accountkit
103
104
  test_files: []
105
+ has_rdoc: