Class: AtlanticNet::HttpTransport

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

Constant Summary collapse

API_URI =
"https://cloudapi.atlantic.net"

Instance Method Summary collapse

Instance Method Details

#send_request(data) ⇒ Object

Sends the request to the API endpoint

Parameters:

  • data (Hash)

    The Data to pass with the request



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/atlantic_net.rb', line 30

def send_request (data)
  uri = URI.parse(API_URI)
  uri.query = URI.encode_www_form(data)
  
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  
  response = http.get(uri.request_uri)

  unless response.code.to_i == 200
    fail AtlanticNetException.new(nil, {}, "The Atlantic.net api endpoint was unexpectedly unavailable. The HTTP Status code was #{response.code}")
  end

  JSON.parse(response.body)
end