Class: K2Polling
- Inherits:
-
Object
- Object
- K2Polling
- Includes:
- K2Utilities, K2Validation
- Defined in:
- lib/k2-connect-ruby/k2_entity/k2_polling.rb
Overview
Class for Polling Service
Constant Summary
Constants included from K2Validation
K2Validation::ALL_EVENT_TYPES, K2Validation::TILL_SCOPE_EVENT_TYPES
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#k2_response_body ⇒ Object
readonly
Returns the value of attribute k2_response_body.
-
#location_url ⇒ Object
readonly
Returns the value of attribute location_url.
Instance Method Summary collapse
-
#initialize(access_token) ⇒ K2Polling
constructor
Initialize with access token.
- #poll(params) ⇒ Object
-
#query_resource(location_url = @location_url) ⇒ Object
Retrieve your newly created polling request by its resource location.
-
#query_resource_url(url) ⇒ Object
Retrieve your newly created polling request by specific resource location.
Methods included from K2Validation
#determine_scope_details, #incorrect_keys, #nil_values, #to_indifferent_access, #validate_email, #validate_hash, #validate_input, #validate_network, #validate_phone, #validate_settlement_method, #validate_till_number_prefix, #validate_url, #validate_webhook, #validate_webhook_input
Methods included from K2Utilities
Constructor Details
#initialize(access_token) ⇒ K2Polling
Initialize with access token
8 9 10 11 12 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 8 def initialize(access_token) raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank? @threads = [] @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 5 def access_token @access_token end |
#k2_response_body ⇒ Object (readonly)
Returns the value of attribute k2_response_body.
4 5 6 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 4 def k2_response_body @k2_response_body end |
#location_url ⇒ Object (readonly)
Returns the value of attribute location_url.
4 5 6 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 4 def location_url @location_url end |
Instance Method Details
#poll(params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 14 def poll(params) k2_request_body = { scope: params[:scope], scope_reference: params[:scope_reference], from_time: params[:from_time], to_time: params[:to_time], _links: { callback_url: params[:callback_url] } } poll_hash = make_hash(K2Config.path_url('poll'), 'post', @access_token,'Polling', k2_request_body) @location_url = K2Connect.make_request(poll_hash) end |
#query_resource(location_url = @location_url) ⇒ Object
Retrieve your newly created polling request by its resource location
27 28 29 30 31 32 33 34 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 27 def query_resource(location_url = @location_url) query_hash = make_hash(location_url, 'get', @access_token, 'Polling', nil) @threads << Thread.new do sleep 0.25 @k2_response_body = K2Connect.make_request(query_hash) end @threads.each(&:join) end |
#query_resource_url(url) ⇒ Object
Retrieve your newly created polling request by specific resource location
37 38 39 |
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 37 def query_resource_url(url) query_resource(url) end |