Skip to content

Commit

Permalink
Version 4.0.0. Read the changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Mar 26, 2021
1 parent 8265c41 commit f04f095
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 89 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Date format: DD/MM/YYYY

## 4.0.0 - [25/03/2021]

- **NEW** `IndustryIdentifier`
- **NEW** Tests

## 3.1.0 - [21/03/2021]

- **FIX** `publisherDate` wasn't found in google books api json. (Merged [#4](https://github.com/bdlukaa/books_finder/pull/4) from [JimTim](https://github.com/JimTim))
Expand Down
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,27 @@ If you already have a `Book` object, you can call `book.info` to get all the boo
final info = book.info;
```

| Parameter | Description |
| ------------------------------------- | ------------------------------------------- |
| title (`String`) | Title of the book |
| authors (`List<String>`) | All the authors names |
| publisher (`String`) | The publisher name |
| publishedDate (`DateTime`) | The date it was published |
| rawPublishedDate (`String`) | The date it was published in raw format |
| description (`String`) | Description of the book |
| pageCount (`int`) | The amount of pages |
| categories (`List<String>`) | The categories the book is in |
| averageRating (`double`) | The average rating of the book |
| ratingsCount (`int`) | The amount of people that rated it |
| maturityRating (`String`) | The maturity rating |
| contentVersion (`String`) | The version of the content |
| industryIdentifier (`List<IndustryIdentifier>`)| The identifiers of the book (isbn) |
| imageLinks (`List<Map<String, Uri>>`) | The links with the avaiable image resources |
| language (`String`) | The language code of the book |
| Parameter | Description |
| ----------------------------------------------- | ------------------------------------------- |
| title (`String`) | Title of the book |
| authors (`List<String>`) | All the authors names |
| publisher (`String`) | The publisher name |
| publishedDate (`DateTime`) | The date it was published |
| rawPublishedDate (`String`) | The date it was published in raw format |
| description (`String`) | Description of the book |
| pageCount (`int`) | The amount of pages |
| categories (`List<String>`) | The categories the book is in |
| averageRating (`double`) | The average rating of the book |
| ratingsCount (`int`) | The amount of people that rated it |
| maturityRating (`String`) | The maturity rating |
| contentVersion (`String`) | The version of the content |
| industryIdentifier (`List<IndustryIdentifier>`) | The identifiers of the book (isbn) |
| imageLinks (`List<Map<String, Uri>>`) | The links with the avaiable image resources |
| language (`String`) | The language code of the book |

## Acknowledgements

- [@JimTim](https://github.com/JimTim) for industry identifiers and tests

## Issues and feedback

Expand Down
79 changes: 39 additions & 40 deletions lib/src/scripts/books.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2020 Bruno D'Luka

import 'extensions.dart';

class Book {
Expand Down Expand Up @@ -36,7 +37,6 @@ class IndustryIdentifier {
final String type;
final String identifier;


const IndustryIdentifier({
required this.type,
required this.identifier,
Expand All @@ -47,8 +47,8 @@ class IndustryIdentifier {

static IndustryIdentifier fromJson(Map<String, dynamic> json) {
return IndustryIdentifier(
type: json['type']??'',
identifier: json['identifier']??'',
type: json['type'] ?? '',
identifier: json['identifier'] ?? '',
);
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ class BookInfo {
/// The original language of the book
final String language;

/// The industryIdentifiers of the book (isbn)
/// The industryIdentifiers of the book (ISBN)
final List<IndustryIdentifier> industryIdentifier;

const BookInfo({
Expand All @@ -121,64 +121,62 @@ class BookInfo {
final publishedDateArray =
((json['publishedDate'] as String?) ?? '0000-00-00').split('-');

// initialize date
int year = 0;
int month = 1;
int day = 1;

// now test the date string
if(publishedDateArray.length==1) {
// assume we have only the year
year = int.parse(publishedDateArray[0]);
}
if(publishedDateArray.length==2) {
// assume we have the year and maybe the month (this could be just a speculative case)
year = int.parse(publishedDateArray[0]);
month = int.parse(publishedDateArray[1]);
}
if(publishedDateArray.length==3) {
// assume we have year-month-day
year = int.parse(publishedDateArray[0]);
month = int.parse(publishedDateArray[1]);
day = int.parse(publishedDateArray[2]);
}

// initialize datetime variable
DateTime? publishedDate = null;
if(publishedDateArray.length>0) {
if (publishedDateArray.length > 0) {
// initialize date
int year = int.parse(publishedDateArray[0]);
int month = 1;
int day = 1;

// now test the date string
if (publishedDateArray.length == 1) {
// assume we have only the year
year = int.parse(publishedDateArray[0]);
}
if (publishedDateArray.length == 2) {
// assume we have the year and maybe the month (this could be just a speculative case)
year = int.parse(publishedDateArray[0]);
month = int.parse(publishedDateArray[1]);
}
if (publishedDateArray.length == 3) {
// assume we have year-month-day
year = int.parse(publishedDateArray[0]);
month = int.parse(publishedDateArray[1]);
day = int.parse(publishedDateArray[2]);
}
publishedDate = DateTime(year, month, day);
}


final imageLinks = <String, Uri>{};
final map = json['imageLinks'] as Map<String, dynamic>?;
map?.forEach((key, value) {
(json['imageLinks'] as Map<String, dynamic>?)?.forEach((key, value) {
imageLinks.addAll({key: Uri.parse(value.toString())});
});

return BookInfo(
title: json['title']??'',
title: json['title'] ?? '',
authors: ((json['authors'] as List<dynamic>?) ?? []).toStringList(),
publisher: json['publisher']??'',
publisher: json['publisher'] ?? '',
averageRating: ((json['averageRating'] ?? 0) as num).toDouble(),
categories: ((json['categories'] as List<dynamic>?) ?? []).toStringList(),
contentVersion: json['contentVersion']??'',
description: json['description']??'',
language: json['language']??'',
maturityRating: json['maturityRating'] ??'',
contentVersion: json['contentVersion'] ?? '',
description: json['description'] ?? '',
language: json['language'] ?? '',
maturityRating: json['maturityRating'] ?? '',
pageCount: json['pageCount'] ?? 0,
ratingsCount: json['ratingsCount'] ?? 0,
publishedDate: publishedDate,
rawPublishedDate: (json['publishedDate'] as String?) ?? '',
imageLinks: imageLinks,
industryIdentifier: ((json['industryIdentifiers']??[]) as List).map((industryIdentifier) => IndustryIdentifier.fromJson(industryIdentifier)).toList(),
industryIdentifier: ((json['industryIdentifiers'] ?? []) as List)
.map((i) => IndustryIdentifier.fromJson(i))
.toList(),
);
}

@override
String toString() {
return '''
title: $title
return '''title: $title
authors: $authors
publisher: $publisher
publishedDate: $publishedDate
Expand All @@ -191,6 +189,7 @@ class BookInfo {
maturityRating: $maturityRating
pageCount: $pageCount
ratingsCount: $ratingsCount
imageLinks: $imageLinks''';
imageLinks: $imageLinks
industryIdentifiers: $industryIdentifier''';
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: books_finder
description: A library to help on the search for books on google books api
version: 3.1.0
version: 4.0.0
repository: https://github.com/bdlukaa/books_finder

environment:
Expand Down
63 changes: 32 additions & 31 deletions test/test_book_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ void main() {

test('Get book with special id', () async {
final Book book = await getSpecificBook('eI0TEAAAQBAJ');
expect(book.info.title,'Twilight, Say Cheese!');
expect(book.info.publisher,'Simon and Schuster');
expect(book.info.publishedDate,DateTime(2021,02,09));
expect(book.info.rawPublishedDate,'2021-02-09');
expect(book.info.authors.length,1);
expect(book.info.authors[0],'Daisy Sunshine');
expect(book.info.categories.length,4);
expect(book.info.categories[0],'Juvenile Fiction / Animals / Dragons, Unicorns & Mythical');
expect(book.info.pageCount,112);
expect(book.info.language,'en');
expect(book.info.description.isNotEmpty,true);
expect(book.info.maturityRating,'NOT_MATURE');
expect(book.info.contentVersion,'preview-1.0.0');
expect(book.info.industryIdentifier[0].type,'ISBN_10');
expect(book.info.industryIdentifier[0].identifier,'1534461655');
expect(book.info.title, 'Twilight, Say Cheese!');
expect(book.info.publisher, 'Simon and Schuster');
expect(book.info.publishedDate, DateTime(2021, 02, 09));
expect(book.info.rawPublishedDate, '2021-02-09');
expect(book.info.authors.length, 1);
expect(book.info.authors[0], 'Daisy Sunshine');
expect(book.info.categories.length, 4);
expect(book.info.categories[0],
'Juvenile Fiction / Animals / Dragons, Unicorns & Mythical');
expect(book.info.pageCount, 112);
expect(book.info.language, 'en');
expect(book.info.description.isNotEmpty, true);
expect(book.info.maturityRating, 'NOT_MATURE');
expect(book.info.contentVersion, 'preview-1.0.0');
expect(book.info.industryIdentifier[0].type, 'ISBN_10');
expect(book.info.industryIdentifier[0].identifier, '1534461655');
});

test('Get magazines', () async {
Expand All @@ -44,20 +45,20 @@ void main() {

test('Get magazine with special id', () async {
final Book book = await getSpecificBook('OugCAAAAMBAJ');
expect(book.info.title,'New York Magazine');
expect(book.info.publisher,'New York Media, LLC');
expect(book.info.publishedDate,DateTime(1997,06,02));
expect(book.info.rawPublishedDate,'1997-06-02');
expect(book.info.authors.length,1);
expect(book.info.authors[0],'New York Media, LLC');
expect(book.info.categories.length,0);
expect(book.info.pageCount,142);
expect(book.info.language,'en');
expect(book.info.description.isNotEmpty,true);
expect(book.info.maturityRating,'NOT_MATURE');
expect(book.info.contentVersion,'0.0.2.0.preview.1');
expect(book.info.industryIdentifier.length,1);
expect(book.info.industryIdentifier[0].type,'ISSN');
expect(book.info.industryIdentifier[0].identifier,'00287369');
expect(book.info.title, 'New York Magazine');
expect(book.info.publisher, 'New York Media, LLC');
expect(book.info.publishedDate, DateTime(1997, 06, 02));
expect(book.info.rawPublishedDate, '1997-06-02');
expect(book.info.authors.length, 1);
expect(book.info.authors[0], 'New York Media, LLC');
expect(book.info.categories.length, 0);
expect(book.info.pageCount, 142);
expect(book.info.language, 'en');
expect(book.info.description.isNotEmpty, true);
expect(book.info.maturityRating, 'NOT_MATURE');
expect(book.info.contentVersion, '0.0.2.0.preview.1');
expect(book.info.industryIdentifier.length, 1);
expect(book.info.industryIdentifier[0].type, 'ISSN');
expect(book.info.industryIdentifier[0].identifier, '00287369');
});
}
}

0 comments on commit f04f095

Please sign in to comment.