Class: Appwrite::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/appwrite/topic.rb

Overview

Helper to build MQTT topics for Push, level by level.

Topic.path(['user', user_id, 'notification']) # "user/123/notification"
Topic.path(['org', org_id]).path(['logs']) # "org/42/logs"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(levels) ⇒ Topic

Returns a new instance of Topic.



14
15
16
# File 'lib/appwrite/topic.rb', line 14

def initialize(levels)
    @levels = levels.freeze
end

Class Method Details

.path(levels) ⇒ Object

Start a topic with the given levels, e.g. Topic.path(['user', user_id]).



10
11
12
# File 'lib/appwrite/topic.rb', line 10

def self.path(levels)
    new([]).path(levels)
end

Instance Method Details

#path(levels) ⇒ Object

Append the given levels.



19
20
21
# File 'lib/appwrite/topic.rb', line 19

def path(levels)
    self.class.send(:new, @levels + self.class.send(:levels_of, levels))
end

#to_s ⇒ Object



23
24
25
# File 'lib/appwrite/topic.rb', line 23

def to_s
    @levels.join('/')
end