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