Sha256: 71697956f3c09d9ec4b7883aa44c240ec13bfd21604cf305f7cbca4bda0aea4d

Contents?: true

Size: 714 Bytes

Versions: 2

Compression:

Stored size: 714 Bytes

Contents

module Hcloud
  class IsoResource < AbstractResource
    def all
      mj("isos") do |j|
        j.flat_map{|x| x["isos"].map{ |x| Iso.new(x, self, client) } }
      end
    end

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

    def find(id)
      Iso.new(
        Oj.load(request("isos/#{id.to_i}").run.body)["iso"],
        self,
        client
      )
    end

    def find_by(name:)
      j = Oj.load(request("isos", q: {name: name}).run.body)["isos"]
      return if j.none?
      j.each do |x|
        return Iso.new(x, self, client)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hcloud-0.1.1 lib/hcloud/iso_resource.rb
hcloud-0.1.0 lib/hcloud/iso_resource.rb