Class: K2ConnectRuby::K2Entity::K2Polling

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ K2Polling

Initialize with access token

Raises:

  • (ArgumentError)


11
12
13
14
15
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 11

def initialize(access_token)
  raise ArgumentError, "Nil or Empty Access Token Given!" if access_token.blank?

  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#k2_response_bodyObject (readonly)

Returns the value of attribute k2_response_body.



7
8
9
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 7

def k2_response_body
  @k2_response_body
end

#location_urlObject (readonly)

Returns the value of attribute location_url.



7
8
9
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 7

def location_url
  @location_url
end

Instance Method Details

#poll(params) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 17

def poll(params)
  polling_request = K2ConnectRuby::K2Entity::K2FinancialEntities::Polling::PollingRequest.new(params)
  raise(ArgumentError, polling_request.errors.full_messages.first) unless polling_request.valid?

  result = K2ConnectRuby::K2Services::SendK2ConnectPostRequestService.call(
    access_token,
    polling_request.endpoint,
    polling_request.request_body,
  )
  @location_url = result.data[:response_headers][:location]
end

#query_resource(location_url = @location_url) ⇒ Object

Retrieve your newly created polling request by its resource location



30
31
32
33
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 30

def query_resource(location_url = @location_url)
  result = K2ConnectRuby::K2Services::SendK2ConnectGetRequestService.call(access_token, location_url)
  @k2_response_body = result.data[:response_body]
end

#query_resource_url(url) ⇒ Object

Retrieve your newly created polling request by specific resource location



36
37
38
# File 'lib/k2-connect-ruby/k2_entity/k2_polling.rb', line 36

def query_resource_url(url)
  query_resource(url)
end