Class: Nwsdk::Query
Constant Summary
Constants included from Helpers
Helpers::ATTACHMENT_FILENAME, Helpers::MULTIPART_BOUNDARY, Helpers::MULTIPART_END, Helpers::MULTIPART_PROLOGUE
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#id1 ⇒ Object
Returns the value of attribute id1.
-
#id2 ⇒ Object
Returns the value of attribute id2.
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#limit ⇒ Object
Returns the value of attribute limit.
Instance Method Summary collapse
- #build_request ⇒ Object
- #format_select ⇒ Object
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #request ⇒ Object
- #unroll_result(result) ⇒ Object
- #width ⇒ Object
Methods included from Helpers
#count_results, #decode_value, #each_multipart_response_entity, #format_timestamp, #get_boundary, #get_sessionids, #response_successful?
Constructor Details
#initialize(*args) ⇒ Query
Returns a new instance of Query.
7 8 9 10 11 |
# File 'lib/nwsdk/query.rb', line 7 def initialize(*args) Hash[*args].each {|k,v| self.send("%s="%k, v)} @limit ||= 10000 @keys ||= %w{ * } end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
5 6 7 |
# File 'lib/nwsdk/query.rb', line 5 def condition @condition end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/nwsdk/query.rb', line 5 def endpoint @endpoint end |
#id1 ⇒ Object
Returns the value of attribute id1.
5 6 7 |
# File 'lib/nwsdk/query.rb', line 5 def id1 @id1 end |
#id2 ⇒ Object
Returns the value of attribute id2.
5 6 7 |
# File 'lib/nwsdk/query.rb', line 5 def id2 @id2 end |
#keys ⇒ Object
Returns the value of attribute keys.
5 6 7 |
# File 'lib/nwsdk/query.rb', line 5 def keys @keys end |
#limit ⇒ Object
Returns the value of attribute limit.
5 6 7 |
# File 'lib/nwsdk/query.rb', line 5 def limit @limit end |
Instance Method Details
#build_request ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nwsdk/query.rb', line 22 def build_request endpoint.get_request( path: 'sdk', params: { msg: 'query', query: format_select, size: limit * width } ) end |
#format_select ⇒ Object
41 42 43 |
# File 'lib/nwsdk/query.rb', line 41 def format_select sprintf("select %s where %s", keys.join(','), condition.format) end |
#request ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/nwsdk/query.rb', line 13 def request result=build_request.execute if response_successful?(result) unroll_result(JSON.parse(result)) else result end end |
#unroll_result(result) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nwsdk/query.rb', line 45 def unroll_result(result) grouped=result["results"]["fields"].group_by {|f| f["group"] } grouped.map do |gid,fields| report=Hash.new fields.each do |field| key = field["type"] val = decode_value(field) if report.has_key?(key) report[key]=[*report[key],val] else report[key]=val end end report end end |
#width ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/nwsdk/query.rb', line 33 def width if keys==["*"] 100 else keys.size end end |