Class: CGIParty::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cgi_party/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



8
9
10
# File 'lib/cgi_party/client.rb', line 8

def initialize
  @savon_client = Savon.client(savon_opts)
end

Instance Attribute Details

#collect_responsesObject (readonly)

Returns the value of attribute collect_responses.



6
7
8
# File 'lib/cgi_party/client.rb', line 6

def collect_responses
  @collect_responses
end

#polling_started_atObject (readonly)

Returns the value of attribute polling_started_at.



6
7
8
# File 'lib/cgi_party/client.rb', line 6

def polling_started_at
  @polling_started_at
end

#savon_clientObject (readonly)

Returns the value of attribute savon_client.



6
7
8
# File 'lib/cgi_party/client.rb', line 6

def savon_client
  @savon_client
end

Instance Method Details

#authenticate(ssn, options: {}) ⇒ Object



27
28
29
# File 'lib/cgi_party/client.rb', line 27

def authenticate(ssn, options: {})
  CGIParty::AuthenticateRequest.new(@savon_client, ssn).execute
end

#collect(order_reference, transaction_id, options: {}) ⇒ Object



31
32
33
# File 'lib/cgi_party/client.rb', line 31

def collect(order_reference, transaction_id, options: {})
  CGIParty::CollectRequest.new(@savon_client, order_reference, transaction_id).execute
end

#poll_collect(order_ref, transaction_id = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/cgi_party/client.rb', line 12

def poll_collect(order_ref, transaction_id = nil)
  @polling_started_at = Time.now
  loop do
    collect_response = collect(order_ref, transaction_id)
    return collect_response if timeout_polling?
    yield(collect_response)
    return collect_response if collect_response.authentication_finished?
    sleep(CGIParty.config.collect_polling_delay)
  end
end

#polling_durationObject



23
24
25
# File 'lib/cgi_party/client.rb', line 23

def polling_duration
  Time.now - @polling_started_at
end