registerToTopics static method

Future<void> registerToTopics(
  1. List<MPTopic> topics
)

Register the current device to an array of topics.

@param topics The array of topics you will register to. @returns A future that completes once the registration is successful.

Implementation

static Future<void> registerToTopics(List<MPTopic> topics) async {
  Map<String, String> apiParameters = {};
  apiParameters.addAll(await _defaultParameters());
  List<Map<String, dynamic>> topicsDictionaries =
      topics.map((t) => t.toApiDictionary()).toList();
  apiParameters['topics'] = json.encode(topicsDictionaries);

  String apiName = 'api/register';

  var requestBody = json.encode(apiParameters);

  Map<String, String> headers = _defaultHeaders(contentTypeJson: true);

  var uri = Uri.https(_endpoint, apiName);

  http.Response response = await http.post(
    uri,
    headers: headers,
    body: requestBody,
  );
  _checkResponse(response.body);
}