lib/onering/plugins/devices.rb in onering-client-0.0.46 vs lib/onering/plugins/devices.rb in onering-client-0.0.50
- old
+ new
@@ -1,48 +1,48 @@
-
module Onering
- module API
- class Devices < Base
- class<<self
- def get(id)
- request("devices/#{id}")
- end
+ class API
+ class Devices < API
+ def show(id)
+ get("/devices/#{id}").parsed_response
+ end
- def get_field(id, field)
- request("devices/#{id}/get/#{field}")
- end
+ def get_field(id, field)
+ get("/devices/#{id}/get/#{field}").response.body
+ end
- def set_field(id, field, value)
- request("devices/#{id}/set/#{field}/#{value}")
- end
+ def set_field(id, field, value)
+ get("/devices/#{id}/set/#{field}/#{value}").response.body
+ end
- def list(field, options={
- :unique => true,
- :sort => true,
- :filter => nil
- })
- qs = {
- :q => make_filter(options[:filter])
- } if options[:filter]
+ def list(field, options={
+ :unique => true,
+ :sort => true,
+ :filter => nil
+ })
+ qs = {
+ :q => make_filter(options[:filter])
+ } if options[:filter]
- rv = request("devices/list/#{field}", {
- :fields => qs
- })
+ rv = get("/devices/list/#{field}", {
+ :query => qs
+ }).parsed_response
- rv = rv.uniq if options[:unique]
- rv = rv.sort if options[:sort]
+ rv = rv.uniq if options[:unique]
+ rv = rv.sort if options[:sort]
- rv
- end
+ return rv
+ end
- def find(filter, options={})
- request("devices/find/#{make_filter(filter)}")
- end
+ def find(filter, options={})
+ get("/devices/find/#{make_filter(filter)}").parsed_response
+ end
- def save(id, data)
- request("devices/#{id}", {
- :method => :post,
- :data => data
+ def save(id, data=nil, &block)
+ if block_given?
+ post("/devices/#{id}", {}, &block)
+ else
+ post("/devices/#{id}", {
+ :body => data
})
end
end
end
end