Class: K2Entity

Inherits:
Object
  • Object
show all
Includes:
K2Utilities, K2Validation
Defined in:
lib/k2-connect-ruby/k2_entity/k2_entity.rb

Overview

Common Class Behaviours for stk, pay and transfers

Direct Known Subclasses

K2Pay, K2Settlement, K2Stk, K2Transfer

Constant Summary

Constants included from K2Validation

K2Validation::ALL_EVENT_TYPES, K2Validation::TILL_SCOPE_EVENT_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#make_hash

Constructor Details

#initialize(access_token) ⇒ K2Entity

Initialize with access token from Subscriber Class



8
9
10
11
12
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 8

def initialize(access_token)
  @access_token = access_token
  @threads = []
  @exception_array = %w[authenticity_token]
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



3
4
5
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 3

def access_token
  @access_token
end

#k2_response_bodyObject (readonly)

Returns the value of attribute k2_response_body.



4
5
6
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 4

def k2_response_body
  @k2_response_body
end

#location_urlObject (readonly)

Returns the value of attribute location_url.



4
5
6
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 4

def location_url
  @location_url
end

#query_hashObject (readonly)

Returns the value of attribute query_hash.



4
5
6
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 4

def query_hash
  @query_hash
end

#the_arrayObject

Returns the value of attribute the_array.



3
4
5
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 3

def the_array
  @the_array
end

Instance Method Details

#query(class_type, path_url) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 24

def query(class_type, path_url)
  # TODO: Add back the validation to ensure only https location urls are returned
  # path_url = validate_url(@location_url)
  query_hash = make_hash(path_url, 'get', @access_token, class_type, nil)
  @threads << Thread.new do
    sleep 0.25
    @k2_response_body = K2Connect.make_request(query_hash)
  end
  @threads.each(&:join)
end

#query_resource(class_type, url) ⇒ Object

Query Location URL



20
21
22
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 20

def query_resource(class_type, url)
  query(class_type, url)
end

#query_status(class_type, path_url) ⇒ Object

Query/Check the status of a previously initiated request



15
16
17
# File 'lib/k2-connect-ruby/k2_entity/k2_entity.rb', line 15

def query_status(class_type, path_url)
  query(class_type, path_url)
end