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

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

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

Returns a new instance of SessionReport.



52
53
54
55
56
57
58
59
60
# File 'lib/verizon/models/session_report.rb', line 52

def initialize(id:, txid:, sessions: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @sessions = sessions unless sessions == SKIP
  @id = id
  @txid = txid
  @additional_properties = additional_properties
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 (UUID) 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)


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

def txid
  @txid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/verizon/models/session_report.rb', line 63

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 a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

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

.namesObject

A mapping from model property names to API property names.



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

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

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    txid
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    sessions
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



102
103
104
105
106
# File 'lib/verizon/models/session_report.rb', line 102

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} sessions: #{@sessions.inspect}, id: #{@id.inspect}, txid: #{@txid.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



95
96
97
98
99
# File 'lib/verizon/models/session_report.rb', line 95

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} sessions: #{@sessions}, id: #{@id}, txid: #{@txid}, additional_properties:"\
  " #{@additional_properties}>"
end