NotionResponse.fromResponse constructor

NotionResponse.fromResponse(
  1. Response response
)

Map a new Notion response instance from a http response.

The class of the response parameter is the one in the http package.

Implementation

factory NotionResponse.fromResponse(Response response) {
  Map<String, dynamic> json = jsonDecode(response.body);

  NotionResponse _result = NotionResponse(
    status: json['status'] ?? response.statusCode,
    code: json['code'] ?? '',
    message: json['message'] ?? '',
  );

  _result.object = stringToObjectType(json['object']);
  if (_result.object == ObjectTypes.List) {
    _result.pagination = Pagination.fromJson(json);
  } else if (_result.object == ObjectTypes.Error) {
    _result.hasError = true;
    _result.isOk = false;
  } else if (_result.object == ObjectTypes.Database) {
    _result.database = Database.fromJson(json);
  } else if (_result.object == ObjectTypes.Page) {
    _result.page = Page.fromJson(json);
  }

  return _result;
}