Class: SPOT::Resources::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/spot-gps/resources/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, response = nil) ⇒ Message

Returns a new instance of Message.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spot-gps/resources/message.rb', line 19

def initialize(object, response = nil)
  @id = object.fetch('id')
  @created_at = Time.at(object.fetch('unixTime'))
  @type = object.fetch('messageType')
  @latitude = object.fetch('latitude')
  @longitude = object.fetch('longitude')
  @battery_state = object.fetch('batteryState')
  @hidden = object.fetch('hidden') == 1
  @show_custom_message = object.fetch('showCustomMsg') == "Y"
  @content = object.fetch('messageContent', nil)
  @messenger_id = object.fetch('messengerId')
  @messenger_name = object.fetch('messengerName')
  @messenger_model = object.fetch('modelId')

  @object = object
  @response = response
end

Instance Attribute Details

#battery_stateObject (readonly)

Returns the value of attribute battery_state.



9
10
11
# File 'lib/spot-gps/resources/message.rb', line 9

def battery_state
  @battery_state
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/spot-gps/resources/message.rb', line 12

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/spot-gps/resources/message.rb', line 5

def created_at
  @created_at
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



10
11
12
# File 'lib/spot-gps/resources/message.rb', line 10

def hidden
  @hidden
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/spot-gps/resources/message.rb', line 4

def id
  @id
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



7
8
9
# File 'lib/spot-gps/resources/message.rb', line 7

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



8
9
10
# File 'lib/spot-gps/resources/message.rb', line 8

def longitude
  @longitude
end

#messenger_idObject (readonly)

Returns the value of attribute messenger_id.



13
14
15
# File 'lib/spot-gps/resources/message.rb', line 13

def messenger_id
  @messenger_id
end

#messenger_modelObject (readonly)

Returns the value of attribute messenger_model.



15
16
17
# File 'lib/spot-gps/resources/message.rb', line 15

def messenger_model
  @messenger_model
end

#messenger_nameObject (readonly)

Returns the value of attribute messenger_name.



14
15
16
# File 'lib/spot-gps/resources/message.rb', line 14

def messenger_name
  @messenger_name
end

#responseObject (readonly)

Returns the value of attribute response.



17
18
19
# File 'lib/spot-gps/resources/message.rb', line 17

def response
  @response
end

#show_custom_messageObject (readonly)

Returns the value of attribute show_custom_message.



11
12
13
# File 'lib/spot-gps/resources/message.rb', line 11

def show_custom_message
  @show_custom_message
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/spot-gps/resources/message.rb', line 6

def type
  @type
end

Instance Method Details

#inspectObject



53
54
55
56
57
58
# File 'lib/spot-gps/resources/message.rb', line 53

def inspect
  attr_list =
    to_h.map { |key, value| "#{key}: #{value.inspect}" }.join(', ')

  "#<#{self.class} #{attr_list}>"
end

#to_hObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/spot-gps/resources/message.rb', line 37

def to_h
  @hash ||=
    begin
      attribute_ivars =
        (instance_variables - [:@response, :@object, :@hash])

      attribute_ivars.each_with_object({}) do |ivar, hash|
        hash[ivar.to_s.delete('@').to_sym] = instance_variable_get(ivar)
      end
    end
end

#to_raw_hObject



49
50
51
# File 'lib/spot-gps/resources/message.rb', line 49

def to_raw_h
  @object
end