Skip to content

Commit

Permalink
Support up to 50 cloud servers
Browse files Browse the repository at this point in the history
  • Loading branch information
dbackeus committed Jun 18, 2024
1 parent 2f66b3f commit eb75d18
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/api/hetzner_cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down

0 comments on commit eb75d18

Please sign in to comment.