k2-connect-ruby 2.0.0 → 3.0.0
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/.ruby-version +1 -0
- data/Gemfile.lock +78 -64
- data/README.md +70 -49
- data/k2-connect-ruby.gemspec +12 -11
- data/lib/k2-connect-ruby/{k2_entity/entity.rb → entity.rb} +5 -0
- data/lib/k2-connect-ruby/k2_entity/k2_entity.rb +24 -26
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb +92 -98
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb +43 -44
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb +43 -44
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb +35 -36
- data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +34 -35
- data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +32 -34
- data/lib/k2-connect-ruby/k2_entity/k2_subscribe.rb +34 -36
- data/lib/k2-connect-ruby/k2_entity/k2_token.rb +58 -54
- data/lib/k2-connect-ruby/k2_errors.rb +64 -62
- data/lib/k2-connect-ruby/k2_services/k2_client.rb +27 -0
- data/lib/k2-connect-ruby/k2_services/payload_process.rb +10 -5
- data/lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb +52 -46
- data/lib/k2-connect-ruby/k2_services/payloads/k2_webhooks.rb +57 -51
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/incoming_payment.rb +50 -42
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment.rb +19 -11
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/transfer.rb +16 -8
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received.rb +18 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received.rb +13 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed.rb +13 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/customer_created.rb +20 -12
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb +40 -32
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +49 -46
- data/lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb +19 -0
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +39 -32
- data/lib/k2-connect-ruby/k2_utilities/k2_process_result.rb +42 -37
- data/lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb +51 -50
- data/lib/k2-connect-ruby/k2_utilities/k2_url_parse.rb +11 -6
- data/lib/k2-connect-ruby/k2_utilities/k2_validation.rb +104 -102
- data/lib/k2-connect-ruby/{utilities.rb → k2_utilities.rb} +8 -8
- data/lib/k2-connect-ruby/version.rb +1 -1
- data/lib/k2-connect-ruby.rb +7 -25
- metadata +56 -43
- data/lib/k2-connect-ruby/k2_services/client/k2_client.rb +0 -24
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_received.rb +0 -10
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_received.rb +0 -5
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_reversal.rb +0 -5
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/m2m_transaction.rb +0 -8
- data/lib/k2-connect-ruby/k2_utilities/k2_authorize.rb +0 -14
- data/lib/k2-connect-ruby/k2_utilities/spec_modules/spec_config.rb +0 -41
@@ -1,104 +1,98 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class K2Pay < K2Entity
|
4
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Pay < K2ConnectRuby::K2Entity::K2Entity
|
4
|
+
attr_reader :recipients_location_url, :payments_location_url
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
@recipients_location_url = K2Connect.make_request(pay_recipient_hash)
|
56
|
-
end
|
57
|
-
@threads.each(&:join)
|
58
|
-
end
|
6
|
+
# Adding PAY Recipients with either mobile_wallets or bank_accounts as destination of your payments.
|
7
|
+
def add_recipient(params)
|
8
|
+
params = params.with_indifferent_access
|
9
|
+
@exception_array += %w[type]
|
10
|
+
# In the case of mobile pay recipient
|
11
|
+
k2_request_pay_recipient = if params[:type].eql?('mobile_wallet')
|
12
|
+
params = validate_input(params, @exception_array += %w[first_name last_name phone_number email network])
|
13
|
+
{
|
14
|
+
first_name: params[:first_name],
|
15
|
+
last_name: params[:last_name],
|
16
|
+
phone_number: validate_phone(params[:phone_number]),
|
17
|
+
email: validate_email(params[:email]),
|
18
|
+
network: params[:network]
|
19
|
+
}
|
20
|
+
# In the case of bank pay recipient
|
21
|
+
elsif params[:type].eql?('bank_account')
|
22
|
+
params = validate_input(params, @exception_array += %w[account_name account_number bank_branch_ref settlement_method])
|
23
|
+
{
|
24
|
+
account_name: params[:account_name],
|
25
|
+
account_number: params[:account_number],
|
26
|
+
bank_branch_ref: params[:bank_branch_ref],
|
27
|
+
settlement_method: params[:settlement_method]
|
28
|
+
}
|
29
|
+
# In the case of till pay recipient
|
30
|
+
elsif params[:type].eql?('till')
|
31
|
+
params = validate_input(params, @exception_array += %w[till_name till_number])
|
32
|
+
{
|
33
|
+
till_name: params[:till_name],
|
34
|
+
till_number: params[:till_number]
|
35
|
+
}
|
36
|
+
# In the case of bank pay recipient
|
37
|
+
elsif params[:type].eql?('paybill')
|
38
|
+
params = validate_input(params, @exception_array += %w[paybill_name paybill_number paybill_account_number])
|
39
|
+
{
|
40
|
+
paybill_name: params[:paybill_name],
|
41
|
+
paybill_number: params[:paybill_number],
|
42
|
+
paybill_account_number: params[:paybill_account_number]
|
43
|
+
}
|
44
|
+
else
|
45
|
+
raise ArgumentError, 'Undefined Payment Method.'
|
46
|
+
end
|
47
|
+
recipients_body = {
|
48
|
+
type: params[:type],
|
49
|
+
#type: params['pay_type'],
|
50
|
+
pay_recipient: k2_request_pay_recipient
|
51
|
+
}
|
52
|
+
pay_recipient_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('pay_recipient'), 'post', @access_token, 'PAY', recipients_body)
|
53
|
+
@recipients_location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(pay_recipient_hash)
|
54
|
+
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
@payments_location_url = K2Connect.make_request(create_payment_hash)
|
87
|
-
end
|
88
|
-
@threads.each(&:join)
|
89
|
-
end
|
56
|
+
# Create an outgoing Payment to a third party.
|
57
|
+
def create_payment(params)
|
58
|
+
# Validation
|
59
|
+
params = validate_input(params, @exception_array += %w[destination_reference destination_type description category tags currency value callback_url metadata])
|
60
|
+
# The Request Body Parameters
|
61
|
+
k2_request_pay_amount = {
|
62
|
+
currency: params[:currency],
|
63
|
+
value: params[:value]
|
64
|
+
}
|
65
|
+
k2_request_pay_metadata = params[:metadata]
|
66
|
+
k2_request_links = {
|
67
|
+
callback_url: params[:callback_url]
|
68
|
+
}
|
69
|
+
create_payment_body = {
|
70
|
+
destination_reference: params[:destination_reference],
|
71
|
+
destination_type: params[:destination_type],
|
72
|
+
description: params[:description],
|
73
|
+
category: params[:category],
|
74
|
+
tags: params[:tags],
|
75
|
+
amount: k2_request_pay_amount,
|
76
|
+
meta_data: k2_request_pay_metadata,
|
77
|
+
_links: k2_request_links
|
78
|
+
}
|
79
|
+
create_payment_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('payments'), 'post', @access_token, 'PAY', create_payment_body)
|
80
|
+
@payments_location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(create_payment_hash)
|
81
|
+
end
|
90
82
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
83
|
+
# Query/Check the status of a previously initiated PAY Payment request
|
84
|
+
def query_status(method_type)
|
85
|
+
if method_type.eql?('recipients')
|
86
|
+
super('PAY', @recipients_location_url)
|
87
|
+
elsif method_type.eql?('payments')
|
88
|
+
super('PAY', @payments_location_url)
|
89
|
+
end
|
90
|
+
end
|
99
91
|
|
100
|
-
|
101
|
-
|
102
|
-
|
92
|
+
# Query Location URL
|
93
|
+
def query_resource(url)
|
94
|
+
super('PAY', url)
|
95
|
+
end
|
96
|
+
end
|
103
97
|
end
|
104
98
|
end
|
@@ -1,49 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Settlement < K2ConnectRuby::K2Entity::K2Entity
|
4
|
+
# Create a Verified Settlement Account via API (Mobile Wallet and Bank Account)
|
5
|
+
def add_settlement_account(params)
|
6
|
+
params=params.with_indifferent_access
|
7
|
+
the_path_url = ''
|
8
|
+
settlement_body = {}
|
9
|
+
@exception_array += %w[type]
|
10
|
+
# The Request Body Parameters
|
11
|
+
settlement_body = if params[:type].eql?('merchant_wallet')
|
12
|
+
params = validate_input(params, @exception_array += %w[first_name last_name phone_number network])
|
13
|
+
the_path_url = K2ConnectRuby::K2Utilities::Config::K2Config.path_url('settlement_mobile_wallet')
|
14
|
+
{
|
15
|
+
first_name: params[:first_name],
|
16
|
+
last_name: params[:last_name],
|
17
|
+
phone_number: validate_phone(params[:phone_number]),
|
18
|
+
network: params[:network]
|
19
|
+
}
|
20
|
+
elsif params[:type].eql?('merchant_bank_account')
|
21
|
+
params = validate_input(params, @exception_array += %w[account_name bank_ref bank_branch_ref account_number currency value, settlement_method])
|
22
|
+
the_path_url = K2ConnectRuby::K2Utilities::Config::K2Config.path_url('settlement_bank_account')
|
23
|
+
{
|
24
|
+
account_name: params[:account_name],
|
25
|
+
bank_branch_ref: params[:bank_branch_ref],
|
26
|
+
account_number: params[:account_number],
|
27
|
+
settlement_method: params[:settlement_method]
|
28
|
+
}
|
29
|
+
else
|
30
|
+
raise ArgumentError, 'Unknown Settlement Account'
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@location_url = K2Connect.make_request(settlement_hash)
|
36
|
-
end
|
37
|
-
@threads.each(&:join)
|
38
|
-
end
|
33
|
+
settlement_hash = make_hash(the_path_url, 'post', @access_token, 'Transfer', settlement_body)
|
34
|
+
@location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(settlement_hash)
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
# Check the status of a prior initiated Transfer. Make sure to add the id to the url
|
38
|
+
def query_status
|
39
|
+
super('Settlement', path_url=@location_url)
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
# Query Location URL
|
43
|
+
def query_resource(url)
|
44
|
+
super('Settlement', url)
|
45
|
+
end
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
@@ -1,48 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
@threads.each(&:join)
|
37
|
-
end
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Stk < K2ConnectRuby::K2Entity::K2Entity
|
4
|
+
# Receive payments from M-PESA users.
|
5
|
+
def receive_mpesa_payments(params)
|
6
|
+
# Validation
|
7
|
+
params = validate_input(params, @exception_array += %w[payment_channel till_number first_name last_name phone_number email currency value metadata callback_url])
|
8
|
+
# The Request Body Parameters
|
9
|
+
k2_request_subscriber = {
|
10
|
+
first_name: params[:first_name],
|
11
|
+
middle_name: params[:middle_name],
|
12
|
+
last_name: params[:last_name],
|
13
|
+
phone_number: validate_phone(params[:phone_number]),
|
14
|
+
email: validate_email(params[:email])
|
15
|
+
}
|
16
|
+
k2_request_amount = {
|
17
|
+
currency: 'KES',
|
18
|
+
value: params[:value]
|
19
|
+
}
|
20
|
+
k2_request_metadata = params[:metadata]
|
21
|
+
k2_request_links = {
|
22
|
+
callback_url: params[:callback_url]
|
23
|
+
}
|
24
|
+
receive_body = {
|
25
|
+
payment_channel: params[:payment_channel],
|
26
|
+
till_number: validate_till_number_prefix(params[:till_number]),
|
27
|
+
subscriber: k2_request_subscriber,
|
28
|
+
amount: k2_request_amount,
|
29
|
+
meta_data: k2_request_metadata,
|
30
|
+
_links: k2_request_links
|
31
|
+
}
|
32
|
+
receive_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('incoming_payments'), 'post', @access_token, 'STK', receive_body)
|
33
|
+
@location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(receive_hash)
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
# Query/Check STK Payment Request Status
|
37
|
+
def query_status
|
38
|
+
super('STK', path_url=@location_url)
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
# Query Location URL
|
42
|
+
def query_resource(url)
|
43
|
+
super('STK', url)
|
44
|
+
end
|
45
|
+
end
|
47
46
|
end
|
48
47
|
end
|
@@ -1,45 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Transfer < K2ConnectRuby::K2Entity::K2Entity
|
4
|
+
# Create a either a 'blind' transfer, for when destination is specified, and a 'targeted' transfer which has a specified destination.
|
5
|
+
def transfer_funds(params)
|
6
|
+
# Validation
|
7
|
+
unless params["destination_reference"].blank? && params["destination_type"].blank?
|
8
|
+
params = validate_input(params, @exception_array += %w[destination_reference destination_type callback_url metadata])
|
9
|
+
end
|
10
|
+
params = params.with_indifferent_access
|
11
|
+
# The Request Body Parameters
|
12
|
+
k2_request_transfer = {
|
13
|
+
destination_reference: params[:destination_reference],
|
14
|
+
destination_type: params[:destination_type],
|
15
|
+
amount: {
|
15
16
|
currency: params[:currency],
|
16
17
|
value: params[:value]
|
18
|
+
}
|
17
19
|
}
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
{
|
20
|
+
metadata = params[:metadata]
|
21
|
+
transfer_body = k2_request_transfer.merge(
|
22
|
+
{
|
22
23
|
_links:
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
{
|
25
|
+
callback_url: params[:callback_url]
|
26
|
+
},
|
26
27
|
metadata: metadata
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@location_url = K2Connect.make_request(transfer_hash)
|
32
|
-
end
|
33
|
-
@threads.each(&:join)
|
34
|
-
end
|
28
|
+
})
|
29
|
+
transfer_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('transfers'), 'post', @access_token, 'Transfer', transfer_body)
|
30
|
+
@location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(transfer_hash)
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
# Check the status of a prior initiated Transfer. Make sure to add the id to the url
|
34
|
+
def query_status
|
35
|
+
super('Transfer', path_url=@location_url)
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
# Query Location URL
|
39
|
+
def query_resource(url)
|
40
|
+
super('Transfer', url)
|
41
|
+
end
|
42
|
+
end
|
44
43
|
end
|
45
44
|
end
|
@@ -1,41 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Notification
|
4
|
+
include K2ConnectRuby::K2Utilities::K2Validation, K2ConnectRuby::K2Utilities
|
5
|
+
attr_reader :location_url, :k2_response_body
|
6
|
+
attr_accessor :access_token
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
# Initialize with access_token
|
9
|
+
def initialize(access_token)
|
10
|
+
raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
|
11
|
+
@access_token = access_token
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
# Sends transaction notifications via SMS
|
15
|
+
def send_sms_transaction_notification(params)
|
16
|
+
k2_request_links = {
|
17
|
+
callback_url: params[:callback_url]
|
18
|
+
}
|
19
|
+
k2_request_body = {
|
20
|
+
webhook_event_reference: params[:webhook_event_reference],
|
21
|
+
message: params[:message],
|
22
|
+
_links: k2_request_links,
|
23
|
+
}
|
24
|
+
subscribe_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('transaction_sms_notifications'), 'post', @access_token,'Notification', k2_request_body)
|
25
|
+
@location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(subscribe_hash)
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@k2_response_body = K2Connect.make_request(query_hash)
|
33
|
-
end
|
34
|
-
@threads.each(&:join)
|
35
|
-
end
|
28
|
+
# Query Recent Webhook
|
29
|
+
def query_resource(location_url = @location_url)
|
30
|
+
query_hash = make_hash(location_url, 'get', @access_token, 'Notification', nil)
|
31
|
+
@k2_response_body = K2ConnectRuby::K2Utilities::K2Connection.make_request(query_hash)
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
# Query Specific Webhook URL
|
35
|
+
def query_resource_url(url)
|
36
|
+
query_resource(url)
|
37
|
+
end
|
38
|
+
end
|
40
39
|
end
|
41
40
|
end
|
@@ -1,40 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Polling
|
4
|
+
include K2ConnectRuby::K2Utilities::K2Validation, K2ConnectRuby::K2Utilities
|
5
|
+
attr_reader :location_url, :k2_response_body
|
6
|
+
attr_accessor :access_token
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
8
|
+
# Initialize with access token
|
9
|
+
def initialize(access_token)
|
10
|
+
raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
|
11
|
+
@access_token = access_token
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
def poll(params)
|
15
|
+
k2_request_body = {
|
16
|
+
scope: params[:scope],
|
17
|
+
scope_reference: params[:scope_reference],
|
18
|
+
from_time: params[:from_time],
|
19
|
+
to_time: params[:to_time],
|
20
|
+
_links: { callback_url: params[:callback_url] }
|
21
|
+
}
|
22
|
+
poll_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('poll'), 'post', @access_token,'Polling', k2_request_body)
|
23
|
+
@location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(poll_hash)
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@k2_response_body = K2Connect.make_request(query_hash)
|
32
|
-
end
|
33
|
-
@threads.each(&:join)
|
34
|
-
end
|
26
|
+
# Retrieve your newly created polling request by its resource location
|
27
|
+
def query_resource(location_url = @location_url)
|
28
|
+
query_hash = make_hash(location_url, 'get', @access_token, 'Polling', nil)
|
29
|
+
@k2_response_body = K2ConnectRuby::K2Utilities::K2Connection.make_request(query_hash)
|
30
|
+
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
# Retrieve your newly created polling request by specific resource location
|
33
|
+
def query_resource_url(url)
|
34
|
+
query_resource(url)
|
35
|
+
end
|
36
|
+
end
|
39
37
|
end
|
40
38
|
end
|