Class: SixSaferpay::Client

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

Direct Known Subclasses

SecurePayGateApi::Client

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/six_saferpay/client.rb', line 5

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/six_saferpay/client.rb', line 3

def object
  @object
end

#request=(value) ⇒ Object

Sets the attribute request

Parameters:

  • value

    the value to set the attribute request to.



3
4
5
# File 'lib/six_saferpay/client.rb', line 3

def request=(value)
  @request = value
end

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/six_saferpay/client.rb', line 3

def response
  @response
end

Class Method Details

.post(object) ⇒ Object



9
10
11
# File 'lib/six_saferpay/client.rb', line 9

def self.post(object)
  new(object).post
end

Instance Method Details

#postObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/six_saferpay/client.rb', line 13

def post
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  @response = https.request(request)
  hash = @response.body
  hash = JSON.parse(hash, symbolize_names: true)
  hash = transform_response_hash(hash)
  if @response.code == '200'
    @object.response_class.new(**hash)
  else
    raise SixSaferpay::Error.new(**hash)
  end
end