Class: Abrio::Request

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

Overview

Wrapper responsible for all requests.

Class Method Summary collapse

Class Method Details

.get(uri, parameters) ⇒ Object

Call get at uri with parameters.

uri

Complete url. Example: abr.io/api/links/shorten

parameters

Hash of parameters. Example: => “xml”, :version => “1.0”

Returns response body, a String.



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

def self.get(uri, parameters)
  params = build_parameters(parameters)

  begin
    url = URI.parse(uri)
    req = Net::HTTP::Get.new("#{url}?#{params}")
    res = Net::HTTP.start(url.host, url.port) do |http|
      http.request(req)
    end
    res.body
  rescue StandardError => e
    raise Abrio::Error.new(e)
  end
end