k2-connect-ruby 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/k2-connect-ruby/k2_financial_entity/k2_token.rb +28 -2
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +1 -1
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.yml +3 -0
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +4 -1
- data/lib/k2-connect-ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 813e08db1df91bfd2bc8129661251a50547dd412be8e3adf73e30601c96cfd96
|
4
|
+
data.tar.gz: e0152936b0c41216020713f4a9adc0b36f272f03dff49c2b5a334f7aa0bcff78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd9f054d341616ae35e76f056e719576f5b90f323022564cb74d3a50de13e1f416dca358fe4029bbc393149e49f29802a84260a0f7e5cba72e2b3131a202754a
|
7
|
+
data.tar.gz: e4de423af14eb8af838f9bbe40ecc93b7fd770fc241ea492e104585d30eda2d451a7b8342df0f3b394a413fdf59b64b1e5034b51ea2b145b9cd0f8efcdf36287
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Class for Gaining Access Token
|
2
2
|
class K2AccessToken
|
3
|
-
attr_reader :access_token
|
3
|
+
attr_reader :access_token, :token_response
|
4
4
|
|
5
5
|
def initialize(client_id, client_secret)
|
6
6
|
validate_client_credentials(client_id, client_secret)
|
@@ -8,7 +8,6 @@ class K2AccessToken
|
|
8
8
|
@client_secret = client_secret
|
9
9
|
end
|
10
10
|
|
11
|
-
# Method for sending the request to K2 sandbox or Mock Server (Receives the access_token)
|
12
11
|
def request_token
|
13
12
|
token_params = {
|
14
13
|
client_id: @client_id,
|
@@ -19,6 +18,33 @@ class K2AccessToken
|
|
19
18
|
@access_token = K2Connect.make_request(token_hash)
|
20
19
|
end
|
21
20
|
|
21
|
+
def revoke_token(access_token)
|
22
|
+
token_params = {
|
23
|
+
client_id: @client_id,
|
24
|
+
client_secret: @client_secret,
|
25
|
+
token: access_token
|
26
|
+
}
|
27
|
+
token_hash = K2AccessToken.make_hash(K2Config.path_url('revoke_token'), 'post', 'Access Token', token_params)
|
28
|
+
@token_response = K2Connect.make_request(token_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
def introspect_token(access_token)
|
32
|
+
token_params = {
|
33
|
+
client_id: @client_id,
|
34
|
+
client_secret: @client_secret,
|
35
|
+
token: access_token
|
36
|
+
}
|
37
|
+
token_hash = K2AccessToken.make_hash(K2Config.path_url('introspect_token'), 'post', 'Access Token', token_params)
|
38
|
+
@token_response = K2Connect.make_request(token_hash)
|
39
|
+
end
|
40
|
+
|
41
|
+
def token_info(access_token)
|
42
|
+
token_hash = K2AccessToken.make_hash(K2Config.path_url('token_info'), 'get', 'Access Token', nil)
|
43
|
+
|
44
|
+
token_hash[:access_token] = access_token
|
45
|
+
@token_response = K2Connect.make_request(token_hash)
|
46
|
+
end
|
47
|
+
|
22
48
|
def validate_client_credentials(client_id, client_secret)
|
23
49
|
raise ArgumentError, 'Nil or Empty Client Id or Secret!' if client_id.blank? || client_secret.blank?
|
24
50
|
end
|
@@ -3,6 +3,9 @@ version: v1
|
|
3
3
|
base_url: http://127.0.0.1:3000/
|
4
4
|
endpoints: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
5
5
|
oauth_token: oauth/token
|
6
|
+
revoke_token: oauth/revoke
|
7
|
+
introspect_token: oauth/introspect
|
8
|
+
token_info: oauth/token/info
|
6
9
|
webhook_subscriptions: webhook_subscriptions
|
7
10
|
pay_recipient: pay_recipients
|
8
11
|
payments: payments
|
@@ -12,7 +12,10 @@ module K2Connect
|
|
12
12
|
|
13
13
|
# Set up Headers
|
14
14
|
headers = { 'Content-Type': 'application/json', Accept: 'application/vnd.kopokopo.v1.hal+json', Authorization: "Bearer #{access_token}" }
|
15
|
-
|
15
|
+
# For access token request
|
16
|
+
if path_url.include?('oauth/token/info')
|
17
|
+
headers = { 'Content-Type': 'application/json', Accept: 'application/vnd.kopokopo.v1.hal+json', Authorization: "Bearer #{access_token}" }
|
18
|
+
elsif path_url.include?('oauth/')
|
16
19
|
headers = { 'Content-Type': 'application/json' }
|
17
20
|
end
|
18
21
|
|