module Onering class API class Devices < API def show(id) get("/devices/#{id}").parsed_response end def get_field(id, field) rv = get("/devices/#{id}/get/#{field}") rv.parsed_response rescue rv.response.body 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}", { :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