Sha256: ef9a4be9c59a70e9d1bd20f26a3fab54782691d8492de646baf85e21e9ae939b

Contents?: true

Size: 826 Bytes

Versions: 3

Compression:

Stored size: 826 Bytes

Contents

module Hcloud
  class ActionResource < AbstractResource
    include Enumerable

    def all(sort: nil)
      Oj.load(request(base_path("actions"), q: {sort: sort}).run.body)["actions"].map do |x|
        Action.new(x, self, client)
      end
    end
    
    def find(id)
      Action.new(
        Oj.load(request(base_path("actions/#{id.to_i}")).run.body)["action"], 
        self, 
        client
      )
    end

    def [](arg)
      find(arg)
    rescue Error::NotFound
    end

    def where(status: nil, sort: nil)
      Oj.load(
        request(base_path("actions"), 
                q: {status: status, sort: sort}).run.body
      )["actions"].map do |x|
        Action.new(x, self, client)
      end
    end

    private

    def base_path(ext)
      [@base_path, ext].reject(&:empty?).join('/')
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hcloud-0.1.0.pre.alpha4 lib/hcloud/action_resource.rb
hcloud-0.1.0.pre.alpha3 lib/hcloud/action_resource.rb
hcloud-0.1.0.pre.alpha2 lib/hcloud/action_resource.rb