Class: Nwsdk::Timeline

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/nwsdk/timeline.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) ⇒ Timeline

Returns a new instance of Timeline.



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

def initialize(*args)
  Hash[*args].each {|k,v| self.send("%s="%k, v)}
  @limit ||= 10000
  @flags ||= %w{ size }
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



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

def condition
  @condition
end

#endpointObject

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#flagsObject

Returns the value of attribute flags.



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

def flags
  @flags
end

#limitObject

Returns the value of attribute limit.



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

def limit
  @limit
end

Instance Method Details

#build_paramsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nwsdk/timeline.rb', line 30

def build_params
  
  params={
    msg: 'timeline',
    time1: format_timestamp(condition.time1),
    time2: format_timestamp(condition.time2),
    size:  limit,
    timezone: 0,
    flags: flags.join(','),
  }
  if condition.where.nil?
    params
  else
    params.merge(where: condition.format(use_time: false))
  end
end

#build_requestObject



24
25
26
27
28
29
# File 'lib/nwsdk/timeline.rb', line 24

def build_request
  endpoint.get_request(
    path: 'sdk',
    params: build_params
  )
end

#requestObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/nwsdk/timeline.rb', line 13

def request
  result=build_request.execute
  if response_successful?(result)
    res=count_results(JSON.parse(result))
    keys=res.keys.map {|k| k - k.gmtoff}
    Hash[keys.zip(res.values)]
  else
    result
  end
end