Sha256: 76cfa0f173e88af49393bb68ad49287915ace77b5dfbf5cb798d4e19f28399ae

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

module Onering
  class API
    class Assets < API
      def show(id)
        get("/devices/#{id}").parsed_response
      end

      def get_field(id, field, fallback=nil)
        rv = get("/devices/#{id}/get/#{field}")
        rv = (rv.parsed_response rescue rv.response.body)
        return fallback if rv.nil? or (rv.is_a?(String) and rv.strip.chomp.empty?)
        return rv
      end

      def set_field(id, field, value)
        rv = get("/devices/#{id}/set/#{field}/#{value}")
        rv.parsed_response rescue rv.response.body
      end

      def list(field, options={
        :unique => true,
        :sort   => true,
        :filter => nil
      })
        qs = {
          :q => make_filter(options[:filter])
        } if options[:filter]

        rv = get("/devices/list/#{[*field].join('/')}", {
          :query => qs
        }).parsed_response

        rv = rv.uniq if options[:unique]
        rv = rv.sort if options[:sort]

        return rv
      end

      def find(filter, options={})
        get("/devices/find/#{make_filter(filter)}").parsed_response
      end

      def save(id, data=nil, &block)
        if block_given?
          post("/devices/#{id}", {}, &block)
        else
          post("/devices/#{id}", {
            :body => data
          })
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
onering-agent-0.4.4 lib/onering/plugins/assets.rb
onering-agent-0.4.3 lib/onering/plugins/assets.rb
onering-client-0.4.3 lib/onering/plugins/assets.rb
onering-client-0.4.2 lib/onering/plugins/assets.rb
onering-client-0.4.1 lib/onering/plugins/assets.rb
onering-client-0.4.0 lib/onering/plugins/assets.rb
onering-client-0.3.4 lib/onering/plugins/assets.rb
onering-client-0.3.3 lib/onering/plugins/assets.rb
onering-client-0.3.2 lib/onering/plugins/assets.rb
onering-client-0.3.1 lib/onering/plugins/assets.rb
onering-client-0.3.0 lib/onering/plugins/assets.rb
onering-client-0.2.4 lib/onering/plugins/assets.rb
onering-client-0.2.3 lib/onering/plugins/assets.rb