Class: Tappay::Client

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

Direct Known Subclasses

PaymentBase, Refund

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(options = {})
  @options = options
  @timeout = options.fetch(:timeout, 25)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/tappay/client.rb', line 7

def options
  @options
end

Instance Method Details

#post(url, data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tappay/client.rb', line 14

def post(url, data)
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == 'https')
  http.open_timeout = timeout
  http.read_timeout = timeout

  request = Net::HTTP::Post.new(uri.request_uri, headers)
  request.body = data.to_json

  @response = http.request(request)
  validate_response
  Response.new(@response)
rescue Timeout::Error, Net::OpenTimeout, Net::ReadTimeout => e
  raise ConnectionError, "HTTP Request failed: #{e.message}"
end