module Hcloud class LocationResource < AbstractResource include Enumerable def all j = Oj.load(request("locations").run.body) j["locations"].map{|x| Location.new(x, self, client) } end def find(id) Location.new( Oj.load(request("locations/#{id}").run.body)["location"], self, client ) end def find_by(name:) x = Oj.load(request("locations", q: {name: name}).run.body)["locations"] return nil if x.none? x.each do |s| return Location.new(s, 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 end end