Class: Mqttopia::Subscriptions::Services::LiveLocations
- Defined in:
- lib/mqttopia/subscriptions/services/live_locations.rb
Defined Under Namespace
Classes: LiveLocationsInvalidError
Instance Attribute Summary collapse
-
#live_location ⇒ Object
readonly
Returns the value of attribute live_location.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#trip_id ⇒ Object
readonly
Returns the value of attribute trip_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(trip_id:, live_location:, options: {}) ⇒ LiveLocations
constructor
validate :live_location_json_format.
- #process ⇒ Object
Methods included from Helpers::DataExtractor
#extract_trip_id, #extract_user_id
Constructor Details
#initialize(trip_id:, live_location:, options: {}) ⇒ LiveLocations
validate :live_location_json_format
19 20 21 22 23 24 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 19 def initialize(trip_id:, live_location:, options: {}) @trip_id = trip_id @live_location = live_location = @user_id = [:user_id] end |
Instance Attribute Details
#live_location ⇒ Object (readonly)
Returns the value of attribute live_location.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 13 def live_location @live_location end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 13 def end |
#trip_id ⇒ Object (readonly)
Returns the value of attribute trip_id.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 13 def trip_id @trip_id end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
13 14 15 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 13 def user_id @user_id end |
Class Method Details
.call(topic, payload, options = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 26 def self.call(topic, payload, = {}) trip_id = payload[:tid] [:user_id] = topic.include?("user/") && topic.match(%r{user/[^/]+}) && extract_user_id(topic) new(trip_id: trip_id, live_location: payload, options: ).process end |
Instance Method Details
#process ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/mqttopia/subscriptions/services/live_locations.rb', line 33 def process raise LiveLocationsInvalidError, errors..to_sentence unless valid? Mqttopia::Serializers::LiveLocation.serialize({ trip_id: trip_id, live_location: live_location }) end |