downloadApi method

  1. @override
Future<HttpApiData?> downloadApi({
  1. required String projectID,
  2. required String apiId,
  3. required PublishSource source,
})
override

Fetches the relevant SDKPublishLayout from the server based on the configurations of the implementation.

Implementation

@override
Future<HttpApiData?> downloadApi({
  required String projectID,
  required String apiId,
  required PublishSource source,
}) {
  final apiDoc = firestore
      .collection(source.serverPath)
      .doc(projectID)
      .collection('apis')
      .doc(apiId);

  return apiDoc.get().then((value) {
    final Map<String, dynamic> data = value.data() ?? {};

    // Api does not exist or there's a network error.
    if (data.isEmpty) {
      throw CodelesslyException('Failed to download api [$apiId].');
    }

    final HttpApiData api = HttpApiData.fromJson(
      {...data, 'id': value.id},
    );
    return api;
  });
}