Class: AstroPay::Curl

Inherits:
Object
  • Object
show all
Defined in:
lib/astro_pay/curl.rb

Class Method Summary collapse

Class Method Details

.enable_sslBoolean

Gets the configuration flag for SSL use with Astropay connections.

Returns:

  • (Boolean)


7
8
9
# File 'lib/astro_pay/curl.rb', line 7

def self.enable_ssl
  AstroPay.configuration.enable_ssl
end

.post(url, params_hash) ⇒ Hash

Note:

When SSL is enabled, no certificate is actually verified due to SSLv3 incompatibilities.

Performs a POST request to the given URL with the given parameters.

Parameters:

  • url (String)

    to where the request will be made.

  • params_hash (Hash)

    parameters to be sent with the request.

Returns:

  • (Hash)

    of the response or, if an error rises, [String] of the response content.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/astro_pay/curl.rb', line 18

def self.post(url, params_hash)
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)

  unless enable_ssl
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data(params_hash)
  response = http.request(request)

  begin
    JSON.parse(response.body)
  rescue
    response.body
  end
end