Sha256: a63d291ad358e58744a3ab5e5c8751254b57d770441262916596cf7d5eebd9cd

Contents?: true

Size: 719 Bytes

Versions: 2

Compression:

Stored size: 719 Bytes

Contents

module Hcloud
  class ActionResource < AbstractResource
    def all
      mj(base_path("actions")) do |j|
        j.flat_map{|x| x["actions"].map{ |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)
      mj(base_path("actions"), q: {status: status}) do |j|
        j.flat_map{|x| x["actions"].map{ |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

2 entries across 2 versions & 1 rubygems

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