class Amaranth::Request

Public Class Methods

delete(path) click to toggle source
# File lib/amaranth/request.rb, line 24
def self.delete path
  result = request(Net::HTTP::Delete.new(path))
  result.code == "200" or raise Amaranth::RequestError, result.body
end
get(path) click to toggle source
# File lib/amaranth/request.rb, line 9
def self.get path
  result = request(Net::HTTP::Get.new(path))
  JSON.parse(result.body)
end
post(path, body) click to toggle source
# File lib/amaranth/request.rb, line 14
def self.post path, body
  result = request(Net::HTTP::Post.new(path), JSON.dump(body))
  result.code == "201" or raise Amaranth::RequestError, result.body
end
put(path, body) click to toggle source
# File lib/amaranth/request.rb, line 19
def self.put path, body
  result = request(Net::HTTP::Put.new(path), JSON.dump(body))
  result.code == "200" or raise Amaranth::RequestError, result.body
end
request(req, body = nil) click to toggle source
# File lib/amaranth/request.rb, line 29
def self.request req, body = nil
  Net::HTTP.start("amara.org", use_ssl: true) do |http|
    req["Content-Type"] = "application/json"
    req["X-api-username"] = Amaranth.api_username
    req["X-api-key"] = Amaranth.api_key
    req.body = body
    http.request(req)
  end
end