createFeedSubscription method

Future<FeedSubscription> createFeedSubscription({
  1. required String projectId,
  2. required String feedId,
  3. required String room,
  4. required String path,
  5. Map<String, String> annotations = const {},
})

Implementation

Future<FeedSubscription> createFeedSubscription({
  required String projectId,
  required String feedId,
  required String room,
  required String path,
  Map<String, String> annotations = const {},
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedFeedId = Uri.encodeComponent(feedId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/feeds/$encodedFeedId/subscriptions');
  final body = {'room': room, 'path': path, 'annotations': annotations};

  final response = await httpClient.post(uri, body: jsonEncode(body));
  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to create feed subscription. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  final data = jsonDecode(response.body) as Map<String, dynamic>;
  return FeedSubscription.fromJson(data['subscription'] as Map<String, dynamic>);
}