Class: Verizon::ObservationRequest

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

Overview

Used to define callbacks including the device identity, the attribute names, corresponding attribute values and the date/timestamp of when the observation was made.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(account_name = nil, devices = nil, attributes = nil, frequency = SKIP, duration = SKIP) ⇒ ObservationRequest

Returns a new instance of ObservationRequest.



58
59
60
61
62
63
64
65
# File 'lib/verizon/models/observation_request.rb', line 58

def initialize( = nil, devices = nil, attributes = nil,
               frequency = SKIP, duration = SKIP)
  @account_name = 
  @devices = devices
  @attributes = attributes
  @frequency = frequency unless frequency == SKIP
  @duration = duration unless duration == SKIP
end

Instance Attribute Details

#account_nameString

Account identifier in “##########-#####”.

Returns:

  • (String)


16
17
18
# File 'lib/verizon/models/observation_request.rb', line 16

def 
  @account_name
end

#attributesArray[ObservationRequestAttribute]

Attributes are streaming RF parameters that you want to observe.

Returns:



24
25
26
# File 'lib/verizon/models/observation_request.rb', line 24

def attributes
  @attributes
end

#devicesArray[Device]

List of devices.

Returns:



20
21
22
# File 'lib/verizon/models/observation_request.rb', line 20

def devices
  @devices
end

#durationNumericalData

Describes value and unit of time.

Returns:



32
33
34
# File 'lib/verizon/models/observation_request.rb', line 32

def duration
  @duration
end

#frequencyNumericalData

Describes value and unit of time.

Returns:



28
29
30
# File 'lib/verizon/models/observation_request.rb', line 28

def frequency
  @frequency
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
93
94
95
96
97
98
99
100
101
102
# File 'lib/verizon/models/observation_request.rb', line 68

def self.from_hash(hash)
  return nil unless hash

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

  devices = nil unless hash.key?('devices')
  # Parameter is an array, so we need to iterate through it
  attributes = nil
  unless hash['attributes'].nil?
    attributes = []
    hash['attributes'].each do |structure|
      attributes << (ObservationRequestAttribute.from_hash(structure) if structure)
    end
  end

  attributes = nil unless hash.key?('attributes')
  frequency = NumericalData.from_hash(hash['frequency']) if hash['frequency']
  duration = NumericalData.from_hash(hash['duration']) if hash['duration']

  # Create object from extracted values.
  ObservationRequest.new(,
                         devices,
                         attributes,
                         frequency,
                         duration)
end

.namesObject

A mapping from model property names to API property names.



35
36
37
38
39
40
41
42
43
# File 'lib/verizon/models/observation_request.rb', line 35

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['account_name'] = 'accountName'
  @_hash['devices'] = 'devices'
  @_hash['attributes'] = 'attributes'
  @_hash['frequency'] = 'frequency'
  @_hash['duration'] = 'duration'
  @_hash
end

.nullablesObject

An array for nullable fields



54
55
56
# File 'lib/verizon/models/observation_request.rb', line 54

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    frequency
    duration
  ]
end