lib/qubitro-mqtt/packet.rb in qubitro-mqtt-0.0.7 vs lib/qubitro-mqtt/packet.rb in qubitro-mqtt-0.0.8
- old
+ new
@@ -420,15 +420,15 @@
attr_accessor :will_retain
# The payload of the Will message
attr_accessor :will_payload
- # The deviceId for authenticating with the server
- attr_accessor :deviceId
+ # The device_id for authenticating with the server
+ attr_accessor :device_id
- # The deviceToken for authenticating with the server
- attr_accessor :deviceToken
+ # The device_token for authenticating with the server
+ attr_accessor :device_token
# Default attribute values
ATTR_DEFAULTS = {
:client_id => nil,
:clean_session => true,
@@ -436,12 +436,12 @@
:will_topic => nil,
:will_qos => 0,
:ack_timeout => 15,
:will_retain => false,
:will_payload => '',
- :deviceId => nil,
- :deviceToken => nil
+ :device_id => nil,
+ :device_token => nil
}
# Create a new Client Connect packet
def initialize(args = {})
super(ATTR_DEFAULTS.merge(args))
@@ -477,23 +477,23 @@
@connect_flags = 0
@connect_flags |= 0x02 if @clean_session
@connect_flags |= 0x04 unless @will_topic.nil?
@connect_flags |= ((@will_qos & 0x03) << 3)
@connect_flags |= 0x20 if @will_retain
- @connect_flags |= 0x40 unless @deviceToken.nil?
- @connect_flags |= 0x80 unless @deviceId.nil?
+ @connect_flags |= 0x40 unless @device_token.nil?
+ @connect_flags |= 0x80 unless @device_id.nil?
body += encode_bytes(@connect_flags)
body += encode_short(@keep_alive)
body += encode_string(@client_id)
unless will_topic.nil?
body += encode_string(@will_topic)
# The MQTT v3.1 specification says that the payload is a UTF-8 string
body += encode_string(@will_payload)
end
- body += encode_string(@deviceId) unless @deviceId.nil?
- body += encode_string(@deviceToken) unless @deviceToken.nil?
+ body += encode_string(@device_id) unless @device_id.nil?
+ body += encode_string(@device_token) unless @device_token.nil?
body
end
# Parse the body (variable header and payload) of a Connect packet
def parse_body(buffer)
@@ -519,24 +519,24 @@
@will_topic = shift_string(buffer)
# The MQTT v3.1 specification says that the payload is a UTF-8 string
@will_payload = shift_string(buffer)
end
if ((@connect_flags & 0x80) >> 7) == 0x01 && buffer.bytesize > 0
- @deviceId = shift_string(buffer)
+ @device_id = shift_string(buffer)
end
if ((@connect_flags & 0x40) >> 6) == 0x01 && buffer.bytesize > 0 # rubocop: disable Style/GuardClause
- @deviceToken = shift_string(buffer)
+ @device_token = shift_string(buffer)
end
end
# Returns a human readable string, summarising the properties of the packet
def inspect
str = "\#<#{self.class}: " \
"keep_alive=#{keep_alive}"
str += ', clean' if clean_session
str += ", client_id='#{client_id}'"
- str += ", deviceId='#{deviceId}'" unless deviceId.nil?
- str += ', deviceToken=...' unless deviceToken.nil?
+ str += ", device_id='#{device_id}'" unless device_id.nil?
+ str += ', device_token=...' unless device_token.nil?
str + '>'
end
# ---- Deprecated attributes and methods ---- #
\ No newline at end of file