From eb75d18fb5813d915c25997240f84d308f53f435 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Tue, 18 Jun 2024 11:39:12 +0200 Subject: [PATCH] Support up to 50 cloud servers --- app/api/hetzner_cloud.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/api/hetzner_cloud.rb b/app/api/hetzner_cloud.rb index 0fc3f04..1680327 100644 --- a/app/api/hetzner_cloud.rb +++ b/app/api/hetzner_cloud.rb @@ -59,8 +59,9 @@ def self.ssh_keys end # https://docs.hetzner.cloud/#servers-get-all-servers + # NOTE: Since pagination isn't implemented here we only support up to 50 servers. def self.servers - get("servers").fetch("servers") + get("servers", per_page: 50).fetch("servers") end def self.server(id) @@ -79,10 +80,14 @@ def self.update_server(id, params) end def self.request(method, path, params = nil) + url = "#{BASE_URL}/#{path}" + url += "?#{Rack::Utils.build_query(params)}" if method == "get" && params.present? + body = params&.to_json unless method == "get" + response = Typhoeus.send( method.downcase, - "#{BASE_URL}/#{path}", - body: params&.to_json, + url, + body:, headers: { "Authorization" => "Bearer #{ENV.fetch('HETZNER_CLOUD_API_TOKEN')}", "Content-Type" => "application/json",