class Hetzner::Client

Constants

BASE_URI

Attributes

token[R]

Public Class Methods

new(token:) click to toggle source
# File lib/hetzner/infra/client.rb, line 7
def initialize(token:)
  @token = token
end

Public Instance Methods

delete(path, id) click to toggle source
# File lib/hetzner/infra/client.rb, line 23
def delete(path, id)
  make_request do
    HTTP.headers(headers).delete(BASE_URI + path + "/" + id.to_s)
  end
end
get(path) click to toggle source
# File lib/hetzner/infra/client.rb, line 11
def get(path)
  make_request do
    JSON.parse HTTP.headers(headers).get(BASE_URI + path).body
  end
end
post(path, data) click to toggle source
# File lib/hetzner/infra/client.rb, line 17
def post(path, data)
  make_request do
    HTTP.headers(headers).post(BASE_URI + path, json: data)
  end
end

Private Instance Methods

headers() click to toggle source
# File lib/hetzner/infra/client.rb, line 31
def headers
  {
    "Authorization": "Bearer #{@token}",
    "Content-Type": "application/json"
  }
end
make_request(&block) click to toggle source
# File lib/hetzner/infra/client.rb, line 38
def make_request &block
  Timeout::timeout(5) do
    block.call
  end
rescue Timeout::Error
  retry
end