Class: ShellEv::DataRetrieve

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/shell_ev/models/data_retrieve.rb

Overview

DataRetrieve Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id = SKIP, user_id = SKIP, ema_id = SKIP, evse_id = SKIP, last_updated = SKIP, started_at = SKIP, stopped_at = SKIP, session_state = SKIP) ⇒ DataRetrieve

Returns a new instance of DataRetrieve.



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/shell_ev/models/data_retrieve.rb', line 80

def initialize(id = SKIP, user_id = SKIP, ema_id = SKIP, evse_id = SKIP,
               last_updated = SKIP, started_at = SKIP, stopped_at = SKIP,
               session_state = SKIP)
  @id = id unless id == SKIP
  @user_id = user_id unless user_id == SKIP
  @ema_id = ema_id unless ema_id == SKIP
  @evse_id = evse_id unless evse_id == SKIP
  @last_updated = last_updated unless last_updated == SKIP
  @started_at = started_at unless started_at == SKIP
  @stopped_at = stopped_at unless stopped_at == SKIP
  @session_state = session_state unless session_state == SKIP
end

Instance Attribute Details

#ema_idString

Id of the evse that the user is charging

Returns:

  • (String)


23
24
25
# File 'lib/shell_ev/models/data_retrieve.rb', line 23

def ema_id
  @ema_id
end

#evse_idString

Ema-id of the charge token that is used

Returns:

  • (String)


27
28
29
# File 'lib/shell_ev/models/data_retrieve.rb', line 27

def evse_id
  @evse_id
end

#idUUID | String

Id of the session

Returns:

  • (UUID | String)


15
16
17
# File 'lib/shell_ev/models/data_retrieve.rb', line 15

def id
  @id
end

#last_updatedString

Last updated date

Returns:

  • (String)


31
32
33
# File 'lib/shell_ev/models/data_retrieve.rb', line 31

def last_updated
  @last_updated
end

#session_stateChargeRetrieveState

When the session is stopped

Returns:



43
44
45
# File 'lib/shell_ev/models/data_retrieve.rb', line 43

def session_state
  @session_state
end

#started_atDateTime

When the session is started

Returns:

  • (DateTime)


35
36
37
# File 'lib/shell_ev/models/data_retrieve.rb', line 35

def started_at
  @started_at
end

#stopped_atDateTime

When the session is stopped

Returns:

  • (DateTime)


39
40
41
# File 'lib/shell_ev/models/data_retrieve.rb', line 39

def stopped_at
  @stopped_at
end

#user_idString

Id of the user that started the session

Returns:

  • (String)


19
20
21
# File 'lib/shell_ev/models/data_retrieve.rb', line 19

def user_id
  @user_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/shell_ev/models/data_retrieve.rb', line 94

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  user_id = hash.key?('userId') ? hash['userId'] : SKIP
  ema_id = hash.key?('emaId') ? hash['emaId'] : SKIP
  evse_id = hash.key?('evseId') ? hash['evseId'] : SKIP
  last_updated = hash.key?('lastUpdated') ? hash['lastUpdated'] : SKIP
  started_at = if hash.key?('startedAt')
                 (DateTimeHelper.from_rfc3339(hash['startedAt']) if hash['startedAt'])
               else
                 SKIP
               end
  stopped_at = if hash.key?('stoppedAt')
                 (DateTimeHelper.from_rfc3339(hash['stoppedAt']) if hash['stoppedAt'])
               else
                 SKIP
               end
  session_state = ChargeRetrieveState.from_hash(hash['sessionState']) if hash['sessionState']

  # Create object from extracted values.
  DataRetrieve.new(id,
                   user_id,
                   ema_id,
                   evse_id,
                   last_updated,
                   started_at,
                   stopped_at,
                   session_state)
end

.namesObject

A mapping from model property names to API property names.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shell_ev/models/data_retrieve.rb', line 46

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['user_id'] = 'userId'
  @_hash['ema_id'] = 'emaId'
  @_hash['evse_id'] = 'evseId'
  @_hash['last_updated'] = 'lastUpdated'
  @_hash['started_at'] = 'startedAt'
  @_hash['stopped_at'] = 'stoppedAt'
  @_hash['session_state'] = 'sessionState'
  @_hash
end

.nullablesObject

An array for nullable fields



74
75
76
77
78
# File 'lib/shell_ev/models/data_retrieve.rb', line 74

def self.nullables
  %w[
    stopped_at
  ]
end

.optionalsObject

An array for optional fields



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/shell_ev/models/data_retrieve.rb', line 60

def self.optionals
  %w[
    id
    user_id
    ema_id
    evse_id
    last_updated
    started_at
    stopped_at
    session_state
  ]
end

Instance Method Details

#to_custom_started_atObject



126
127
128
# File 'lib/shell_ev/models/data_retrieve.rb', line 126

def to_custom_started_at
  DateTimeHelper.to_rfc3339(started_at)
end

#to_custom_stopped_atObject



130
131
132
# File 'lib/shell_ev/models/data_retrieve.rb', line 130

def to_custom_stopped_at
  DateTimeHelper.to_rfc3339(stopped_at)
end