Sha256: f57203143bb9de6794a64295c8e7fc20e089d12338ca135f0c8affc7f654750b
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
module Hcloud class ImageResource < AbstractResource include Enumerable def all Oj.load(request("images").run.body)["images"].map do |x| Image.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) Image.new( Oj.load(request("images/#{id.to_i}").run.body)["image"], self, client ) end def where(sort: nil, type: nil, bound_to: nil, name: nil) query = {} method(:where).parameters.inject(query) do |r,x| (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var) end Oj.load( request("images", q: query).run.body )["images"].map do |x| Image.new(x, self, client) end end def find_by(name:) j = Oj.load(request("images", q: {name: name}).run.body)["images"] return if j.none? j.each do |x| return Image.new(x, self, client) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hcloud-0.1.0.pre.alpha4 | lib/hcloud/image_resource.rb |
hcloud-0.1.0.pre.alpha3 | lib/hcloud/image_resource.rb |