Class: Onering::API::Assets
Constant Summary
Constants inherited
from Onering::API
DEFAULT_BASE, DEFAULT_CLIENT_KEY, DEFAULT_CLIENT_PEM, DEFAULT_PATH, DEFAULT_VALIDATION_PEM
Constants included
from Util
Util::HTTP_STATUS_CODES
Instance Attribute Summary
Attributes inherited from Onering::API
#url
Instance Method Summary
collapse
-
#find(filter, options = {}) ⇒ Object
-
#get_field(id, field, fallback = nil) ⇒ Object
-
#list(field, options = { :unique => true, :sort => true, :filter => nil }) ⇒ Object
-
#save(id, data = nil, &block) ⇒ Object
-
#set_field(id, field, value) ⇒ Object
-
#show(id) ⇒ Object
#_default_param, #_setup_auth, #_setup_auth_token, #connect, #delete, #get, #initialize, #method_missing, #post, #put, #request, #status
Methods included from Util
#fact, #gem_path, #http_status, #make_filter
Constructor Details
This class inherits a constructor from Onering::API
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Onering::API
Instance Method Details
#find(filter, options = {}) ⇒ Object
39
40
41
|
# File 'lib/onering/plugins/assets.rb', line 39
def find(filter, options={})
get("/devices/find/#{make_filter(filter)}").parsed_response
end
|
#get_field(id, field, fallback = nil) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/onering/plugins/assets.rb', line 8
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
|
#list(field, options = {
:unique => true,
:sort => true,
:filter => nil
}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/onering/plugins/assets.rb', line 20
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
|
#save(id, data = nil, &block) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/onering/plugins/assets.rb', line 43
def save(id, data=nil, &block)
if block_given?
post("/devices/#{id}", {}, &block)
else
post("/devices/#{id}", {
:body => data
})
end
end
|
#set_field(id, field, value) ⇒ Object
15
16
17
18
|
# File 'lib/onering/plugins/assets.rb', line 15
def set_field(id, field, value)
rv = get("/devices/#{id}/set/#{field}/#{value}")
rv.parsed_response rescue rv.response.body
end
|
#show(id) ⇒ Object
4
5
6
|
# File 'lib/onering/plugins/assets.rb', line 4
def show(id)
get("/devices/#{id}").parsed_response
end
|