mqttopia 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mqttopia/serializers/live_location.rb +43 -0
- data/lib/mqttopia/subscriptions/redirect.rb +6 -3
- data/lib/mqttopia/subscriptions/services/base.rb +1 -0
- data/lib/mqttopia/subscriptions/services/live_locations.rb +44 -0
- data/lib/mqttopia/subscriptions/services/test_debug.rb +0 -1
- data/lib/mqttopia/subscriptions/services/trip_metrics.rb +0 -1
- data/lib/mqttopia/subscriptions/services/trip_points.rb +0 -1
- data/lib/mqttopia/topics/services.rb +6 -0
- data/lib/mqttopia/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1999a274eff111b5027805925f4c9053adfe992c6ecff4a4f45212d56477978f
|
4
|
+
data.tar.gz: 115798acdb489d407fafc0c53e9dc46624c422555c061b424a066d82d51c06c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2e463f81874aafb17370878bf95290f1a0ccd67a712814687820435f305ada601afa07b5b1431db03988effd8afb2df4b4ec31347b85865bc3913fc23465b1
|
7
|
+
data.tar.gz: 66bbeca571ae0dfdb159cea9c1c31767555a3ee52c5de8ac2ec73c5ed5213342e85edf68eed4230ff55a1ad85a3edf79c573c1cc4f68f1995907200850b9b4c7
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mqttopia
|
4
|
+
module Serializers
|
5
|
+
module LiveLocation
|
6
|
+
module_function
|
7
|
+
|
8
|
+
KEYS = %i[tid batt loc].freeze
|
9
|
+
|
10
|
+
def serialize(body)
|
11
|
+
return unless valid_live_location?(body[:live_location])
|
12
|
+
|
13
|
+
{
|
14
|
+
trip_id: body[:trip_id],
|
15
|
+
live_location: serialize_live_location(
|
16
|
+
body.dig(:live_location, :loc)&.merge!(batt: body.dig(:live_location, :batt))
|
17
|
+
),
|
18
|
+
logged_at: body.dig(:live_location, :loc, :ts)&.to_s,
|
19
|
+
received_at: current_timestamp
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def serialize_live_location(live_location)
|
24
|
+
{
|
25
|
+
latitude: live_location[:lat],
|
26
|
+
longitude: live_location[:lon],
|
27
|
+
accuracy: live_location[:acc],
|
28
|
+
altitude: live_location[:alt],
|
29
|
+
speed: live_location[:spd],
|
30
|
+
battery: live_location[:batt]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid_live_location?(live_location)
|
35
|
+
live_location.is_a?(Hash) && KEYS.all? { |key| live_location.key?(key) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_timestamp
|
39
|
+
DateTime.now.strftime("%Q")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "services/trip_metrics"
|
4
|
-
require_relative "services/test_debug"
|
5
|
-
require_relative "services/trip_points"
|
3
|
+
# require_relative "services/trip_metrics"
|
4
|
+
# require_relative "services/test_debug"
|
5
|
+
# require_relative "services/trip_points"
|
6
|
+
# require_relative "services/live_locations"
|
7
|
+
Dir[File.join(__dir__, "services", "*.rb")].sort.each { |file| require_relative file }
|
8
|
+
|
6
9
|
require_relative "../topics/services"
|
7
10
|
|
8
11
|
module Mqttopia
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../serializers/live_location"
|
4
|
+
require_relative "./base"
|
5
|
+
|
6
|
+
module Mqttopia
|
7
|
+
module Subscriptions
|
8
|
+
module Services
|
9
|
+
class LiveLocations < Mqttopia::Subscriptions::Services::Base
|
10
|
+
class LiveLocationsInvalidError < ArgumentError
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :trip_id, :live_location, :options, :user_id
|
14
|
+
|
15
|
+
validates :trip_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
16
|
+
validates :live_location, presence: true
|
17
|
+
# validate :live_location_json_format
|
18
|
+
|
19
|
+
def initialize(trip_id:, live_location:, options: {})
|
20
|
+
@trip_id = trip_id
|
21
|
+
@live_location = live_location
|
22
|
+
@options = options
|
23
|
+
@user_id = options[:user_id]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.call(topic, payload, options = {})
|
27
|
+
trip_id = payload[:tid]
|
28
|
+
options[:user_id] = topic.include?("user/") && topic.match(%r{user/[^/]+}) && extract_user_id(topic)
|
29
|
+
|
30
|
+
new(trip_id: trip_id, live_location: payload, options: options).process
|
31
|
+
end
|
32
|
+
|
33
|
+
def process
|
34
|
+
raise LiveLocationsInvalidError, errors.full_messages.to_sentence unless valid?
|
35
|
+
|
36
|
+
Mqttopia::Serializers::LiveLocation.serialize({
|
37
|
+
trip_id: trip_id,
|
38
|
+
live_location: live_location
|
39
|
+
})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -16,6 +16,12 @@ module Mqttopia
|
|
16
16
|
serializer: "Mqttopia::Serializers::TripPoint",
|
17
17
|
regex: %r{\Ailla/trips/(?<trip_id>\d+)/driver_trip_point/send(?:/user/(?<user_id>\d+))?\z}
|
18
18
|
},
|
19
|
+
live_location: {
|
20
|
+
topic_name: "illa/fleet/location/vehicle/:trip_id/user/:user_id",
|
21
|
+
service: "Mqttopia::Subscriptions::Services::LiveLocations",
|
22
|
+
serializer: "Mqttopia::Serializers::LiveLocation",
|
23
|
+
regex: %r{\Ailla/fleet/location/vehicle/(?<trip_id>\d+)(?:/user/(?<user_id>\d+))?\z}
|
24
|
+
},
|
19
25
|
test_debug: {
|
20
26
|
topic_name: "test",
|
21
27
|
service: "Mqttopia::Subscriptions::Services::TestDebug",
|
data/lib/mqttopia/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqttopia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Illa Tech
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -184,11 +184,13 @@ files:
|
|
184
184
|
- lib/mqttopia/client.rb
|
185
185
|
- lib/mqttopia/helpers/data_extractor.rb
|
186
186
|
- lib/mqttopia/logger.rb
|
187
|
+
- lib/mqttopia/serializers/live_location.rb
|
187
188
|
- lib/mqttopia/serializers/test_debug.rb
|
188
189
|
- lib/mqttopia/serializers/trip_metric.rb
|
189
190
|
- lib/mqttopia/serializers/trip_point.rb
|
190
191
|
- lib/mqttopia/subscriptions/redirect.rb
|
191
192
|
- lib/mqttopia/subscriptions/services/base.rb
|
193
|
+
- lib/mqttopia/subscriptions/services/live_locations.rb
|
192
194
|
- lib/mqttopia/subscriptions/services/test_debug.rb
|
193
195
|
- lib/mqttopia/subscriptions/services/trip_metrics.rb
|
194
196
|
- lib/mqttopia/subscriptions/services/trip_points.rb
|