Class: Nwsdk::Values

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/nwsdk/values.rb

Constant Summary

Constants included from Helpers

Helpers::ATTACHMENT_FILENAME, Helpers::MULTIPART_BOUNDARY, Helpers::MULTIPART_END, Helpers::MULTIPART_PROLOGUE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#count_results, #decode_value, #each_multipart_response_entity, #format_timestamp, #get_boundary, #get_sessionids, #response_successful?

Constructor Details

#initialize(*args) ⇒ Values

Returns a new instance of Values.



7
8
9
10
11
12
# File 'lib/nwsdk/values.rb', line 7

def initialize(*args)
  Hash[*args].each {|k,v| self.send("%s="%k, v)}
  @flags    ||= %w{ sort-total sessions order-descending }
  @limit    ||= 10000
  @key_name ||= 'service'
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



5
6
7
# File 'lib/nwsdk/values.rb', line 5

def condition
  @condition
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/nwsdk/values.rb', line 5

def endpoint
  @endpoint
end

#flagsObject

Returns the value of attribute flags.



5
6
7
# File 'lib/nwsdk/values.rb', line 5

def flags
  @flags
end

#key_nameObject

Returns the value of attribute key_name.



5
6
7
# File 'lib/nwsdk/values.rb', line 5

def key_name
  @key_name
end

#limitObject

Returns the value of attribute limit.



5
6
7
# File 'lib/nwsdk/values.rb', line 5

def limit
  @limit
end

Instance Method Details

#build_requestObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nwsdk/values.rb', line 14

def build_request
  endpoint.get_request(
    path: 'sdk',
    params: {
      msg:       'values',
      where:     condition.format(use_time: false),
      time1:     format_timestamp(condition.time1.utc),
      time2:     format_timestamp(condition.time2.utc),
      size:      limit,
      flags:     flags.join(','),
      fieldName: key_name
    }
  )
end

#requestObject



29
30
31
32
33
34
35
36
# File 'lib/nwsdk/values.rb', line 29

def request
  result=build_request.execute
  if response_successful?(result)
    count_results(JSON.parse(result))
  else
    result
  end
end