class SCB::HTTP

Constants

HEADERS

Public Class Methods

get(uri) click to toggle source
# File lib/scb/http.rb, line 14
def get(uri)
  perform uri, Net::HTTP::Get.new(uri.request_uri, HEADERS)
end
post(uri, body) click to toggle source
# File lib/scb/http.rb, line 18
def post(uri, body)
  request = Net::HTTP::Post.new(uri.request_uri, HEADERS).tap do |r|
    r.body = body
  end

  perform(uri, request)
end

Private Class Methods

perform(uri, request) click to toggle source
# File lib/scb/http.rb, line 28
def perform(uri, request)
  Net::HTTP.start(uri.host, uri.port) do |http|
    http.read_timeout = 60
    response = http.request(request)
    http.finish

    if response.kind_of? Net::HTTPSuccess
      response
    else
      raise Exception, response
    end
  end
end