getAuthorByOLID method

Future<OLAuthorBase> getAuthorByOLID({
  1. required String olid,
})

To fetch auther by his's OL UD number from OpenLibrary.org use getAuthorByOLID. Always check RuntimeType OLAuthorsBase type is -> OLAuthor / OLAuthorError provide olid as the openlibrary id for Authors

Implementation

Future<OLAuthorBase> getAuthorByOLID({required String olid}) async {
  final APIAuthorBase author =
      await _openLibraryApiService.getAuthorById(id: olid);
  // if we have a valid author
  if (author is APIAuthor) {
    final OLAuthor result = OLAuthor.fromJson(author.toJson());
    return result;
  }
  // in case of any error return the error instance
  return const OLAuthorError();
}