Class: Verizon::SessionReport

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/verizon/models/session_report.rb

Overview

Session report for a device.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id = nil, txid = nil, sessions = SKIP) ⇒ SessionReport

Returns a new instance of SessionReport.



51
52
53
54
55
# File 'lib/verizon/models/session_report.rb', line 51

def initialize(id = nil, txid = nil, sessions = SKIP)
  @sessions = sessions unless sessions == SKIP
  @id = id
  @txid = txid
end

Instance Attribute Details

#idString

The 10-digit ID of the device.

Returns:

  • (String)


19
20
21
# File 'lib/verizon/models/session_report.rb', line 19

def id
  @id
end

#sessionsArray[DailyUsageItem]

An object containing the start and end time of the session with the amount of data transferred.

Returns:



15
16
17
# File 'lib/verizon/models/session_report.rb', line 15

def sessions
  @sessions
end

#txidString

A unique string that associates the request with the location report information that is sent in asynchronous callback message.ThingSpace will send a separate callback message for each device that was in the request. All of the callback messages will have the same txid.

Returns:

  • (String)


26
27
28
# File 'lib/verizon/models/session_report.rb', line 26

def txid
  @txid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/verizon/models/session_report.rb', line 58

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  txid = hash.key?('txid') ? hash['txid'] : nil
  # Parameter is an array, so we need to iterate through it
  sessions = nil
  unless hash['sessions'].nil?
    sessions = []
    hash['sessions'].each do |structure|
      sessions << (DailyUsageItem.from_hash(structure) if structure)
    end
  end

  sessions = SKIP unless hash.key?('sessions')

  # Create object from extracted values.
  SessionReport.new(id,
                    txid,
                    sessions)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
# File 'lib/verizon/models/session_report.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['sessions'] = 'sessions'
  @_hash['id'] = 'id'
  @_hash['txid'] = 'txid'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
48
49
# File 'lib/verizon/models/session_report.rb', line 45

def self.nullables
  %w[
    txid
  ]
end

.optionalsObject

An array for optional fields



38
39
40
41
42
# File 'lib/verizon/models/session_report.rb', line 38

def self.optionals
  %w[
    sessions
  ]
end