streamPublishModel method

  1. @override
Stream<SDKPublishModel?> streamPublishModel({
  1. required String projectID,
  2. required PublishSource source,
})
override

Calls a cloud function that searches for the project associated with the given unique slug and returns a completely populated SDKPublishModel instance. Streams a given projectID's associated SDKPublishModel from the network with preferably live updates.

Implementation

@override
Stream<SDKPublishModel?> streamPublishModel({
  required String projectID,
  required PublishSource source,
}) async* {
  final Response result = await post(
    Uri.parse(
        '${config.firebaseCloudFunctionsBaseURL}/api/getPublishModelRequest'),
    headers: <String, String>{'Content-Type': 'application/json'},
    body: jsonEncode({
      'projectID': projectID,
      'source': source.serverPath,
    }),
  );

  if (result.statusCode != 200) {
    log('[WebDataRepo] Error downloading publish model.');
    log('[WebDataRepo] Status code: ${result.statusCode}');
    log('[WebDataRepo] Message: ${result.body}');
    throw CodelesslyException(
      'Error downloading publish model.',
      stacktrace: StackTrace.current,
    );
  }

  final Map<String, dynamic> modelDoc = jsonDecode(result.body);
  final SDKPublishModel model = SDKPublishModel.fromJson(modelDoc);

  yield model;
}