Sha256: 0cab70719e9718f1e256a08e83d7b735ef2b069a88c9daf9ca5b1e22e36b8ebc

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

module Hcloud
  class FloatingIPResource < AbstractResource
    include Enumerable

    def all
      j = Oj.load(request("floating_ips").run.body)
      j["floating_ips"].map{|x| FloatingIP.new(x, self, client) }
    end

    def create(type:, server: nil, home_location: nil, description: nil)
      query = {}
      method(:create).parameters.inject(query) do |r,x| 
        (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
      end
      j = Oj.load(request("floating_ips", j: query, code: 200).run.body)
      [
        j.key?("action") ? Action.new(j["action"], self, client) : nil,
        FloatingIP.new(j["floating_ip"], self, client),
      ]
    end

    def find(id)
      FloatingIP.new(
        Oj.load(request("floating_ips/#{id}").run.body)["floating_ip"],
        self,
        client
      )
    end

    def [](arg)
      case arg
      when Integer
       begin
         find(arg)
       rescue Error::NotFound
       end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hcloud-0.1.1 lib/hcloud/floating_ip_resource.rb