Class: Xively::SearchResult
Constant Summary
collapse
- ALLOWED_KEYS =
%w(totalResults startIndex itemsPerPage results)
- @@feed_class =
Xively::Feed
Instance Method Summary
collapse
#from_json
#from_json
Methods included from Helpers
#join_tags, #parse_tag_string
#generate_xml
#generate_json
Constructor Details
#initialize(input = {}) ⇒ SearchResult
Returns a new instance of SearchResult.
12
13
14
15
16
17
18
|
# File 'lib/xively-rb/search_result.rb', line 12
def initialize(input = {})
if input.is_a?(Hash)
self.attributes = input
else
self.attributes = from_json(input)
end
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
52
53
54
55
|
# File 'lib/xively-rb/search_result.rb', line 52
def as_json(options = {})
options[:version] ||= "1.0.0"
generate_json(options[:version])
end
|
#attributes ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/xively-rb/search_result.rb', line 20
def attributes
h = {}
ALLOWED_KEYS.each do |key|
value = self.send(key)
h[key] = value unless value.nil?
end
return h
end
|
#attributes=(input) ⇒ Object
29
30
31
32
33
|
# File 'lib/xively-rb/search_result.rb', line 29
def attributes=(input)
return if input.nil?
ALLOWED_KEYS.each { |key| self.send("#{key}=", input[key]) }
return attributes
end
|
47
48
49
50
|
# File 'lib/xively-rb/search_result.rb', line 47
def results
return [] if @results.nil?
@results
end
|
#results=(array) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/xively-rb/search_result.rb', line 35
def results=(array)
return unless array.is_a?(Array)
@results = []
array.each do |feed|
if feed.is_a?(@@feed_class)
@results << feed
elsif feed.is_a?(Hash)
@results << @@feed_class.new(feed)
end
end
end
|
#to_json(options = {}) ⇒ Object
57
58
59
|
# File 'lib/xively-rb/search_result.rb', line 57
def to_json(options = {})
MultiJson.dump as_json(options)
end
|
#to_xml(options = {}) ⇒ Object
61
62
63
64
|
# File 'lib/xively-rb/search_result.rb', line 61
def to_xml(options = {})
options[:version] ||= "0.5.1"
generate_xml(options[:version])
end
|