qubitro-mqtt 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/qubitro-mqtt/client.rb +8 -8
- data/lib/qubitro-mqtt/packet.rb +14 -14
- data/lib/qubitro-mqtt/version.rb +1 -1
- data/spec/mqtt_client_spec.rb +12 -12
- data/spec/mqtt_packet_spec.rb +40 -40
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2e4b91db5fac6376f66460d1795edf045786007175bc20b8287969c7dceee3c
|
4
|
+
data.tar.gz: 5a0abdbea64055edc89b1ee60aa9ddbba72b9edeea4a88984a78aae6a4a6dc9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e48dc2860e57e06bac949dd445cad1ff3246fcf52fdbb3cf7a55535dffedcfae5f8d8ce4b6e4aedee3a5ac94a32e782028f18803579f7ba40f8562cf402aab8a
|
7
|
+
data.tar.gz: 4eda7f542d58438ec6cd799a7ea20b1f523f2515bbbefff65783cf8875d6ece23ba521ba22fdb7dc446d656ebf89d4f947205220265527ebd93e9ed94184944f
|
data/README.md
CHANGED
@@ -15,8 +15,8 @@ MQTT::Client.connect(
|
|
15
15
|
:host => host,
|
16
16
|
:port => 1883,
|
17
17
|
:client_id => deviceID,
|
18
|
-
:
|
19
|
-
:
|
18
|
+
:device_id => deviceID,
|
19
|
+
:device_token => device_token,
|
20
20
|
:ack_timeout => 15,
|
21
21
|
:will_topic => deviceID,
|
22
22
|
:will_payload => payload,
|
data/lib/qubitro-mqtt/client.rb
CHANGED
@@ -36,10 +36,10 @@ module MQTT
|
|
36
36
|
attr_accessor :ack_timeout
|
37
37
|
|
38
38
|
# Device ID to authenticate to the server with
|
39
|
-
attr_accessor :
|
39
|
+
attr_accessor :device_id
|
40
40
|
|
41
41
|
# Device Token to authenticate to the server with
|
42
|
-
attr_accessor :
|
42
|
+
attr_accessor :device_token
|
43
43
|
|
44
44
|
# The topic that the Will message is published to
|
45
45
|
attr_accessor :will_topic
|
@@ -68,8 +68,8 @@ module MQTT
|
|
68
68
|
:clean_session => true,
|
69
69
|
:client_id => nil,
|
70
70
|
:ack_timeout => 5,
|
71
|
-
:
|
72
|
-
:
|
71
|
+
:device_id => nil,
|
72
|
+
:device_token => nil,
|
73
73
|
:will_topic => nil,
|
74
74
|
:will_payload => nil,
|
75
75
|
:will_qos => 0,
|
@@ -252,8 +252,8 @@ module MQTT
|
|
252
252
|
:clean_session => @clean_session,
|
253
253
|
:keep_alive => @keep_alive,
|
254
254
|
:client_id => @client_id,
|
255
|
-
:
|
256
|
-
:
|
255
|
+
:device_id => @device_id,
|
256
|
+
:device_token => @device_token,
|
257
257
|
:will_topic => @will_topic,
|
258
258
|
:will_payload => @will_payload,
|
259
259
|
:will_qos => @will_qos,
|
@@ -579,8 +579,8 @@ module MQTT
|
|
579
579
|
{
|
580
580
|
:host => uri.host,
|
581
581
|
:port => uri.port || nil,
|
582
|
-
:
|
583
|
-
:
|
582
|
+
:device_id => uri.device_id ? URI.unescape(uri.device_id) : nil,
|
583
|
+
:device_token => uri.device_token ? URI.unescape(uri.device_token) : nil,
|
584
584
|
:ssl => ssl
|
585
585
|
}
|
586
586
|
end
|
data/lib/qubitro-mqtt/packet.rb
CHANGED
@@ -422,11 +422,11 @@ module MQTT
|
|
422
422
|
# The payload of the Will message
|
423
423
|
attr_accessor :will_payload
|
424
424
|
|
425
|
-
# The
|
426
|
-
attr_accessor :
|
425
|
+
# The device_id for authenticating with the server
|
426
|
+
attr_accessor :device_id
|
427
427
|
|
428
|
-
# The
|
429
|
-
attr_accessor :
|
428
|
+
# The device_token for authenticating with the server
|
429
|
+
attr_accessor :device_token
|
430
430
|
|
431
431
|
# Default attribute values
|
432
432
|
ATTR_DEFAULTS = {
|
@@ -438,8 +438,8 @@ module MQTT
|
|
438
438
|
:ack_timeout => 15,
|
439
439
|
:will_retain => false,
|
440
440
|
:will_payload => '',
|
441
|
-
:
|
442
|
-
:
|
441
|
+
:device_id => nil,
|
442
|
+
:device_token => nil
|
443
443
|
}
|
444
444
|
|
445
445
|
# Create a new Client Connect packet
|
@@ -479,8 +479,8 @@ module MQTT
|
|
479
479
|
@connect_flags |= 0x04 unless @will_topic.nil?
|
480
480
|
@connect_flags |= ((@will_qos & 0x03) << 3)
|
481
481
|
@connect_flags |= 0x20 if @will_retain
|
482
|
-
@connect_flags |= 0x40 unless @
|
483
|
-
@connect_flags |= 0x80 unless @
|
482
|
+
@connect_flags |= 0x40 unless @device_token.nil?
|
483
|
+
@connect_flags |= 0x80 unless @device_id.nil?
|
484
484
|
body += encode_bytes(@connect_flags)
|
485
485
|
|
486
486
|
body += encode_short(@keep_alive)
|
@@ -490,8 +490,8 @@ module MQTT
|
|
490
490
|
# The MQTT v3.1 specification says that the payload is a UTF-8 string
|
491
491
|
body += encode_string(@will_payload)
|
492
492
|
end
|
493
|
-
body += encode_string(@
|
494
|
-
body += encode_string(@
|
493
|
+
body += encode_string(@device_id) unless @device_id.nil?
|
494
|
+
body += encode_string(@device_token) unless @device_token.nil?
|
495
495
|
body
|
496
496
|
end
|
497
497
|
|
@@ -521,10 +521,10 @@ module MQTT
|
|
521
521
|
@will_payload = shift_string(buffer)
|
522
522
|
end
|
523
523
|
if ((@connect_flags & 0x80) >> 7) == 0x01 && buffer.bytesize > 0
|
524
|
-
@
|
524
|
+
@device_id = shift_string(buffer)
|
525
525
|
end
|
526
526
|
if ((@connect_flags & 0x40) >> 6) == 0x01 && buffer.bytesize > 0 # rubocop: disable Style/GuardClause
|
527
|
-
@
|
527
|
+
@device_token = shift_string(buffer)
|
528
528
|
end
|
529
529
|
end
|
530
530
|
|
@@ -534,8 +534,8 @@ module MQTT
|
|
534
534
|
"keep_alive=#{keep_alive}"
|
535
535
|
str += ', clean' if clean_session
|
536
536
|
str += ", client_id='#{client_id}'"
|
537
|
-
str += ",
|
538
|
-
str += ',
|
537
|
+
str += ", device_id='#{device_id}'" unless device_id.nil?
|
538
|
+
str += ', device_token=...' unless device_token.nil?
|
539
539
|
str + '>'
|
540
540
|
end
|
541
541
|
|
data/lib/qubitro-mqtt/version.rb
CHANGED
data/spec/mqtt_client_spec.rb
CHANGED
@@ -109,28 +109,28 @@ describe MQTT::Client do
|
|
109
109
|
expect(client.ssl).to be_truthy
|
110
110
|
end
|
111
111
|
|
112
|
-
it "with a URI containing a
|
112
|
+
it "with a URI containing a device_id and device_token" do
|
113
113
|
client = MQTT::Client.new(URI.parse('mqtt://auser:bpass@mqtt.example.com'))
|
114
114
|
expect(client.host).to eq('mqtt.example.com')
|
115
115
|
expect(client.port).to eq(1883)
|
116
|
-
expect(client.
|
117
|
-
expect(client.
|
116
|
+
expect(client.device_id).to eq('auser')
|
117
|
+
expect(client.device_token).to eq('bpass')
|
118
118
|
end
|
119
119
|
|
120
|
-
it "with a URI containing an escaped
|
120
|
+
it "with a URI containing an escaped device_id and device_token" do
|
121
121
|
client = MQTT::Client.new(URI.parse('mqtt://foo%20bar:%40123%2B%25@mqtt.example.com'))
|
122
122
|
expect(client.host).to eq('mqtt.example.com')
|
123
123
|
expect(client.port).to eq(1883)
|
124
|
-
expect(client.
|
125
|
-
expect(client.
|
124
|
+
expect(client.device_id).to eq('foo bar')
|
125
|
+
expect(client.device_token).to eq('@123+%')
|
126
126
|
end
|
127
127
|
|
128
|
-
it "with a URI containing a double escaped
|
128
|
+
it "with a URI containing a double escaped device_id and device_token" do
|
129
129
|
client = MQTT::Client.new(URI.parse('mqtt://foo%2520bar:123%2525@mqtt.example.com'))
|
130
130
|
expect(client.host).to eq('mqtt.example.com')
|
131
131
|
expect(client.port).to eq(1883)
|
132
|
-
expect(client.
|
133
|
-
expect(client.
|
132
|
+
expect(client.device_id).to eq('foo%20bar')
|
133
|
+
expect(client.device_token).to eq('123%25')
|
134
134
|
end
|
135
135
|
|
136
136
|
it "with a URI as a string" do
|
@@ -334,9 +334,9 @@ describe MQTT::Client do
|
|
334
334
|
client.connect('myclient')
|
335
335
|
end
|
336
336
|
|
337
|
-
it "should include the
|
338
|
-
client.
|
339
|
-
client.
|
337
|
+
it "should include the device_id and device_token for an authenticated connection" do
|
338
|
+
client.device_id = 'device_id'
|
339
|
+
client.device_token = 'device_token'
|
340
340
|
client.connect('myclient')
|
341
341
|
expect(socket.string).to eq(
|
342
342
|
"\x10\x28"+
|
data/spec/mqtt_packet_spec.rb
CHANGED
@@ -541,11 +541,11 @@ describe MQTT::Packet::Connect do
|
|
541
541
|
)
|
542
542
|
end
|
543
543
|
|
544
|
-
it "should output the correct bytes for a packet with a
|
544
|
+
it "should output the correct bytes for a packet with a device_id and device_token" do
|
545
545
|
packet = MQTT::Packet::Connect.new(
|
546
546
|
:client_id => 'myclient',
|
547
|
-
:
|
548
|
-
:
|
547
|
+
:device_id => 'device_id',
|
548
|
+
:device_token => 'device_token'
|
549
549
|
)
|
550
550
|
expect(packet.to_s).to eq(
|
551
551
|
"\x10\x2A"+
|
@@ -566,8 +566,8 @@ describe MQTT::Packet::Connect do
|
|
566
566
|
:will_retain => true,
|
567
567
|
:will_topic => 'will_topic',
|
568
568
|
:will_payload => 'will_message',
|
569
|
-
:
|
570
|
-
:
|
569
|
+
:device_id => 'user0123456789',
|
570
|
+
:device_token => 'pass0123456789'
|
571
571
|
)
|
572
572
|
expect(packet.to_s).to eq(
|
573
573
|
"\x10\x5F"+ # fixed header (2)
|
@@ -577,9 +577,9 @@ describe MQTT::Packet::Connect do
|
|
577
577
|
"\x00\x1712345678901234567890123"+ # client identifier (25)
|
578
578
|
"\x00\x0Awill_topic"+ # will topic (12)
|
579
579
|
"\x00\x0Cwill_message"+ # will message (14)
|
580
|
-
"\x00\x0Euser0123456789"+ #
|
580
|
+
"\x00\x0Euser0123456789"+ # device_id (16)
|
581
581
|
"\x00\x0Epass0123456789"
|
582
|
-
) #
|
582
|
+
) # device_token (16)
|
583
583
|
end
|
584
584
|
|
585
585
|
context 'protocol version 3.1.1' do
|
@@ -643,12 +643,12 @@ describe MQTT::Packet::Connect do
|
|
643
643
|
expect(packet.clean_session).to be_falsey
|
644
644
|
end
|
645
645
|
|
646
|
-
it "should set the the
|
647
|
-
expect(packet.
|
646
|
+
it "should set the the device_id field of the packet to nil" do
|
647
|
+
expect(packet.device_id).to be_nil
|
648
648
|
end
|
649
649
|
|
650
|
-
it "should set the the
|
651
|
-
expect(packet.
|
650
|
+
it "should set the the device_token field of the packet to nil" do
|
651
|
+
expect(packet.device_token).to be_nil
|
652
652
|
end
|
653
653
|
end
|
654
654
|
|
@@ -693,12 +693,12 @@ describe MQTT::Packet::Connect do
|
|
693
693
|
expect(packet.clean_session).to be_falsey
|
694
694
|
end
|
695
695
|
|
696
|
-
it "should set the the
|
697
|
-
expect(packet.
|
696
|
+
it "should set the the device_id field of the packet to nil" do
|
697
|
+
expect(packet.device_id).to be_nil
|
698
698
|
end
|
699
699
|
|
700
|
-
it "should set the the
|
701
|
-
expect(packet.
|
700
|
+
it "should set the the device_token field of the packet to nil" do
|
701
|
+
expect(packet.device_token).to be_nil
|
702
702
|
end
|
703
703
|
end
|
704
704
|
|
@@ -770,7 +770,7 @@ describe MQTT::Packet::Connect do
|
|
770
770
|
end
|
771
771
|
end
|
772
772
|
|
773
|
-
describe "when parsing a Connect packet with a
|
773
|
+
describe "when parsing a Connect packet with a device_id and device_token" do
|
774
774
|
let(:packet) do
|
775
775
|
MQTT::Packet.parse(
|
776
776
|
"\x10\x2A"+
|
@@ -813,17 +813,17 @@ describe MQTT::Packet::Connect do
|
|
813
813
|
end
|
814
814
|
|
815
815
|
it "should set the Device ID of the packet correctly" do
|
816
|
-
expect(packet.
|
817
|
-
expect(packet.
|
816
|
+
expect(packet.device_id).to eq('device_id')
|
817
|
+
expect(packet.device_id.encoding.to_s).to eq('UTF-8')
|
818
818
|
end
|
819
819
|
|
820
820
|
it "should set the Device ID of the packet correctly" do
|
821
|
-
expect(packet.
|
822
|
-
expect(packet.
|
821
|
+
expect(packet.device_token).to eq('device_token')
|
822
|
+
expect(packet.device_token.encoding.to_s).to eq('UTF-8')
|
823
823
|
end
|
824
824
|
end
|
825
825
|
|
826
|
-
describe "when parsing a Connect that has a
|
826
|
+
describe "when parsing a Connect that has a device_id but no device_token" do
|
827
827
|
let(:packet) do
|
828
828
|
MQTT::Packet.parse(
|
829
829
|
"\x10\x20\x00\x06MQIsdp\x03\x80\x00\x0a\x00\x08myclient\x00\x08deviceId"
|
@@ -831,16 +831,16 @@ describe MQTT::Packet::Connect do
|
|
831
831
|
end
|
832
832
|
|
833
833
|
it "should set the Device ID of the packet correctly" do
|
834
|
-
expect(packet.
|
835
|
-
expect(packet.
|
834
|
+
expect(packet.device_id).to eq('device_id')
|
835
|
+
expect(packet.device_id.encoding.to_s).to eq('UTF-8')
|
836
836
|
end
|
837
837
|
|
838
838
|
it "should set the Device ID of the packet correctly" do
|
839
|
-
expect(packet.
|
839
|
+
expect(packet.device_token).to be_nil
|
840
840
|
end
|
841
841
|
end
|
842
842
|
|
843
|
-
describe "when parsing a Connect that has a
|
843
|
+
describe "when parsing a Connect that has a device_token but no device_id" do
|
844
844
|
let(:packet) do
|
845
845
|
MQTT::Packet.parse(
|
846
846
|
"\x10\x20\x00\x06MQIsdp\x03\x40\x00\x0a\x00\x08myclient\x00\x08deviceToken"
|
@@ -848,16 +848,16 @@ describe MQTT::Packet::Connect do
|
|
848
848
|
end
|
849
849
|
|
850
850
|
it "should set the Device ID of the packet correctly" do
|
851
|
-
expect(packet.
|
851
|
+
expect(packet.device_id).to be_nil
|
852
852
|
end
|
853
853
|
|
854
854
|
it "should set the Device ID of the packet correctly" do
|
855
|
-
expect(packet.
|
856
|
-
expect(packet.
|
855
|
+
expect(packet.device_token).to eq('device_token')
|
856
|
+
expect(packet.device_token.encoding.to_s).to eq('UTF-8')
|
857
857
|
end
|
858
858
|
end
|
859
859
|
|
860
|
-
describe "when parsing a Connect packet has the
|
860
|
+
describe "when parsing a Connect packet has the device_id and device_token flags set but doesn't have the fields" do
|
861
861
|
let(:packet) do
|
862
862
|
MQTT::Packet.parse(
|
863
863
|
"\x10\x16\x00\x06MQIsdp\x03\xC0\x00\x0a\x00\x08myclient"
|
@@ -865,11 +865,11 @@ describe MQTT::Packet::Connect do
|
|
865
865
|
end
|
866
866
|
|
867
867
|
it "should set the Device ID of the packet correctly" do
|
868
|
-
expect(packet.
|
868
|
+
expect(packet.device_id).to be_nil
|
869
869
|
end
|
870
870
|
|
871
871
|
it "should set the Device ID of the packet correctly" do
|
872
|
-
expect(packet.
|
872
|
+
expect(packet.device_token).to be_nil
|
873
873
|
end
|
874
874
|
end
|
875
875
|
|
@@ -883,8 +883,8 @@ describe MQTT::Packet::Connect do
|
|
883
883
|
"\x00\x1712345678901234567890123"+ # client identifier (25)
|
884
884
|
"\x00\x0Awill_topic"+ # will topic (12)
|
885
885
|
"\x00\x0Cwill_message"+ # will message (14)
|
886
|
-
"\x00\x0Euser0123456789"+ #
|
887
|
-
"\x00\x0Epass0123456789" #
|
886
|
+
"\x00\x0Euser0123456789"+ # device_id (16)
|
887
|
+
"\x00\x0Epass0123456789" # device_token (16)
|
888
888
|
)
|
889
889
|
end
|
890
890
|
|
@@ -937,13 +937,13 @@ describe MQTT::Packet::Connect do
|
|
937
937
|
end
|
938
938
|
|
939
939
|
it "should set the Device ID of the packet correctly" do
|
940
|
-
expect(packet.
|
941
|
-
expect(packet.
|
940
|
+
expect(packet.device_id).to eq('user0123456789')
|
941
|
+
expect(packet.device_id.encoding.to_s).to eq('UTF-8')
|
942
942
|
end
|
943
943
|
|
944
944
|
it "should set the Device ID of the packet correctly" do
|
945
|
-
expect(packet.
|
946
|
-
expect(packet.
|
945
|
+
expect(packet.device_token).to eq('pass0123456789')
|
946
|
+
expect(packet.device_token.encoding.to_s).to eq('UTF-8')
|
947
947
|
end
|
948
948
|
end
|
949
949
|
|
@@ -997,9 +997,9 @@ describe MQTT::Packet::Connect do
|
|
997
997
|
:keep_alive => 10,
|
998
998
|
:client_id => 'c123',
|
999
999
|
:clean_session => false,
|
1000
|
-
:
|
1000
|
+
:device_id => 'foo'
|
1001
1001
|
)
|
1002
|
-
expect(packet.inspect).to eq("#<MQTT::Packet::Connect: keep_alive=10, client_id='c123',
|
1002
|
+
expect(packet.inspect).to eq("#<MQTT::Packet::Connect: keep_alive=10, client_id='c123', device_id='foo'>")
|
1003
1003
|
end
|
1004
1004
|
end
|
1005
1005
|
|
@@ -1167,7 +1167,7 @@ describe MQTT::Packet::Connack do
|
|
1167
1167
|
end
|
1168
1168
|
|
1169
1169
|
it "should set the return message of the packet correctly" do
|
1170
|
-
expect(packet.return_msg).to match(/bad user name or
|
1170
|
+
expect(packet.return_msg).to match(/bad user name or device_token/i)
|
1171
1171
|
end
|
1172
1172
|
end
|
1173
1173
|
|