Module: Teleflow::Api::Topics

Included in:
Client
Defined in:
lib/teleflow/api/topics.rb

Overview

Module Teleflow::Api::Topics provides an API for managing topics in the Teleflow application.

This module includes methods for creating and retrieving and updating topic. It also includes methods for subscriber addition and removal.

For more information on the Teleflow API(api-teleflow.khulnasoft.com/api#/Topics), see docs.teleflow.khulnasoft.com/api/topic-creation/.

Instance Method Summary collapse

Instance Method Details

#add_subscribers(topic_key, body) ⇒ number

@bodyparams:

Parameters:

  • `subscribers` (Array)

    List of subscriber identifiers that will be associated to the topic

Returns:

  • (number)

    status - The status code. Returns 204 if successfully add subscribers to a topic by key.



47
48
49
# File 'lib/teleflow/api/topics.rb', line 47

def add_subscribers(topic_key, body)
  post("/topics/#{topic_key}/subscribers", body: body)
end

#create_topic(body) ⇒ number

Create a topic

@bodyparams:

Parameters:

  • `key` (String)

    User defined custom key and provided by the user that will be an unique identifier for the Topic created.

  • `name` (String)

    User defined custom name and provided by the user that will name the Topic created.

Returns:

  • (number)

    status - The status code. Returns 201 if the topic has been successfully created.



19
20
21
# File 'lib/teleflow/api/topics.rb', line 19

def create_topic(body)
  post("/topics", body: body)
end

#delete_topic(topic_key) ⇒ number

Delete topic Delete a topic by its topic key if it has no subscribers

Parameters:

  • `topic_key` (String)

Returns:

  • (number)

    status - The status code. Returns 204 if successfully deleted topic.



110
111
112
# File 'lib/teleflow/api/topics.rb', line 110

def delete_topic(topic_key)
  delete("/topics/#{topic_key}")
end

#remove_subscribers(topic_key, body) ⇒ number

@bodyparams:

Parameters:

  • `subscribers` (Array)

    List of subscriber identifiers that will be removed to the topic

Returns:

  • (number)

    status - The status code. Returns 204 if successfully remove subscribers to a topic by key.



60
61
62
# File 'lib/teleflow/api/topics.rb', line 60

def remove_subscribers(topic_key, body)
  post("/topics/#{topic_key}/subscribers/removal", body: body)
end

#rename_topic(topic_key, body) ⇒ Hash, number

Rename a topic by providing a new name

@bodyparams:

Parameters:

  • `topic_key` (String)
  • `name` (String)

    User defined custom name and provided by the user to rename the topic.

Returns:

  • (Hash)

    Updated topic enitiy.

  • (number)

    status

    • Returns 200 if successful



99
100
101
# File 'lib/teleflow/api/topics.rb', line 99

def rename_topic(topic_key, body)
  patch("/topics/#{topic_key}", body: body)
end

#subscriber_topic(topic_key, externalSubscriberId) ⇒ number

Check topic subsriber Check if a subscriber belongs to a certain topic

Parameters:

  • `topic_key` (String)
  • `externalSubscriberId` (String)

    The id of the subscriber created on ‘/subscribers` endpoint

Returns:

  • (number)

    status - The status code. Returns 200 if subscriber was added to the topic.



72
73
74
# File 'lib/teleflow/api/topics.rb', line 72

def subscriber_topic(topic_key, externalSubscriberId)
  get("/topics/#{topic_key}/subscribers/#{externalSubscriberId}")
end

#topic(topic_key) ⇒ Hash, number

Get a topic by its topic key

Parameters:

  • `topic_key` (String)

Returns:

  • (Hash)

    The retrieved topic.

  • (number)

    status

    • Returns 200 if successful



84
85
86
# File 'lib/teleflow/api/topics.rb', line 84

def topic(topic_key)
  get("/topics/#{topic_key}")
end

#topics(query = {}) ⇒ Hash, number

Returns a list of topics that can be paginated using the ‘page` query parameter and

filtered by the topic key with the `key` query parameter

@queryparams:

Parameters:

  • `page` (Integer(optional))

    Number of page for the pagination.

  • `pageSize` (Integer(optional))

    Size of page for the pagination.

  • `key` (String(optional))

    Topic key.

Returns:

  • (Hash)

    The list of topics that match the criteria of the query params are successfully returned.

  • (number)

    status

    • Returns 200 if successful



34
35
36
# File 'lib/teleflow/api/topics.rb', line 34

def topics(query = {})
  get("/topics", query: query)
end