Skip to content

Commit

Permalink
Add back publisher and publishedDate fields (#10)
Browse files Browse the repository at this point in the history
* Add back publisher

* Add back publishedDate

* Clean up

* Update README.md
  • Loading branch information
katydecorah authored May 16, 2024
1 parent 4470da0 commit 68c887f
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ information.

```json
{
"isbn": 9780374104092,
"title": "Annihilation",
"authors": ["Jeff VanderMeer"],
"description": "Describes the 12th expedition to “Area X,” a region cut off from the continent for decades, by a group of intrepid women scientists who try to ignore the high mortality rates of those on the previous 11 missions. Original. 75,000 first printing.",
"pageCount": 209,
"printType": "BOOK",
"categories": ["Fiction"],
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ"
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
"publisher": "Macmillan",
"publishedDate": "2014-02-04",
"isbn": "9780374104092"
}
```

Expand Down
18 changes: 14 additions & 4 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* @typedef {object} Book
* @property {string} isbn - The ISBN of the book.
* @property {string} title - The long title of the book.
* @property {string} title - The title of the book.
* @property {string[]} authors - The authors of the book.
* @property {string} description - The overview of the book.
* @property {number} pageCount - The number of pages in the book.
* @property {string} printType - The print type of the book. Always "BOOK" for this context.
* @property {string} printType - The print type of the book.
* @property {string[]} categories - The subjects or categories of the book.
* @property {string} publisher - The publisher of the book.
* @property {string} publishedDate - The date the book was published.
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
* @property {string} [link] - The link of the book.
*/
Expand Down Expand Up @@ -47,7 +49,7 @@ export type Book = {
*/
isbn: string;
/**
* - The long title of the book.
* - The title of the book.
*/
title: string;
/**
Expand All @@ -63,13 +65,21 @@ export type Book = {
*/
pageCount: number;
/**
* - The print type of the book. Always "BOOK" for this context.
* - The print type of the book.
*/
printType: string;
/**
* - The subjects or categories of the book.
*/
categories: string[];
/**
* - The publisher of the book.
*/
publisher: string;
/**
* - The date the book was published.
*/
publishedDate: string;
/**
* - The thumbnail image link of the book.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
/**
* @typedef {object} Book
* @property {string} isbn - The ISBN of the book.
* @property {string} title - The long title of the book.
* @property {string} title - The title of the book.
* @property {string[]} authors - The authors of the book.
* @property {string} description - The overview of the book.
* @property {number} pageCount - The number of pages in the book.
* @property {string} printType - The print type of the book. Always "BOOK" for this context.
* @property {string} printType - The print type of the book.
* @property {string[]} categories - The subjects or categories of the book.
* @property {string} publisher - The publisher of the book.
* @property {string} publishedDate - The date the book was published.
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
* @property {string} [link] - The link of the book.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/providers/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export function standardize(book, isbn) {
categories: book.categories,
thumbnail: getLargestThumbnail(book.imageLinks),
link: book.canonicalVolumeLink,
publisher: book.publisher,
publishedDate: book.publishedDate,
isbn,
};

Expand Down
2 changes: 2 additions & 0 deletions src/providers/isbndb.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ function standardize(book, isbn) {
printType: "BOOK",
categories: book.subjects,
thumbnail: book.image,
publisher: book.publisher,
publishedDate: book.date_published,
isbn,
};
}
2 changes: 2 additions & 0 deletions src/providers/open-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export async function standardize(book, isbn) {
link: book.key
? `${OPENLIBRARY_API_BASE}${book.key}`
: `${OPENLIBRARY_API_BASE}${OPENLIBRARY_API_BOOK}/${isbn}`,
publisher: book.publishers?.join(", "),
publishedDate: book.publish_date,
isbn,
};

Expand Down
6 changes: 6 additions & 0 deletions test/end-to-end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe("End to end", () => {
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
"pageCount": 209,
"printType": "BOOK",
"publishedDate": "2014-02-04",
"publisher": "Macmillan",
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
"title": "Annihilation",
}
Expand Down Expand Up @@ -86,6 +88,8 @@ describe("End to end", () => {
"link": "https://openlibrary.org/books/OL31444108M",
"pageCount": 208,
"printType": "BOOK",
"publishedDate": "2014",
"publisher": "Farrar, Straus and Giroux",
"thumbnail": "https://covers.openlibrary.org/b/id/10520611-L.jpg",
"title": "Annihilation",
}
Expand All @@ -107,6 +111,8 @@ describe("End to end", () => {
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
"pageCount": 209,
"printType": "BOOK",
"publishedDate": "2014-02-04",
"publisher": "Macmillan",
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
"title": "Annihilation",
}
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe("ISBN Resolver API", () => {
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
"pageCount": 209,
"printType": "BOOK",
"publishedDate": "2014-02-04",
"publisher": "Macmillan",
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
"title": "Annihilation",
}
Expand Down Expand Up @@ -83,6 +85,8 @@ describe("ISBN Resolver API", () => {
"link": "https://openlibrary.org/books/OL7353617M",
"pageCount": 96,
"printType": "BOOK",
"publishedDate": "October 1, 1988",
"publisher": "Puffin",
"thumbnail": "https://covers.openlibrary.org/b/id/8739161-L.jpg",
"title": "Fantastic Mr. Fox",
}
Expand Down Expand Up @@ -145,6 +149,8 @@ describe("ISBN Resolver API", () => {
"isbn": "9780374104092",
"pageCount": 174,
"printType": "BOOK",
"publishedDate": "1992-12-13",
"publisher": "Turtle Bay Books",
"thumbnail": "https://images.isbndb.com/covers/30/23/9781484233023.jpg",
"title": "Book Title",
}
Expand Down Expand Up @@ -236,6 +242,8 @@ describe("ISBN Resolver API", () => {
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
"pageCount": 209,
"printType": "BOOK",
"publishedDate": "2014-02-04",
"publisher": "Macmillan",
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
"title": "Annihilation",
}
Expand Down Expand Up @@ -268,6 +276,8 @@ describe("ISBN Resolver API", () => {
"link": "https://books.google.com/books/about/Annihilation.html?hl=&id=2cl7AgAAQBAJ",
"pageCount": 209,
"printType": "BOOK",
"publishedDate": "2014-02-04",
"publisher": "Macmillan",
"thumbnail": "http://books.google.com/books/content?id=2cl7AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
"title": "Annihilation",
}
Expand Down
2 changes: 2 additions & 0 deletions test/providers/google.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe("resolveGoogle", () => {
"link": undefined,
"pageCount": undefined,
"printType": undefined,
"publishedDate": undefined,
"publisher": undefined,
"thumbnail": undefined,
"title": "Test Book",
}
Expand Down
2 changes: 2 additions & 0 deletions test/providers/isbndb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe("resolveIsbnDb", () => {
"isbn": "1234567890",
"pageCount": 123,
"printType": "BOOK",
"publishedDate": "2022-01-01",
"publisher": "Test Publisher",
"thumbnail": "http://example.com/test.jpg",
"title": "Test Book",
}
Expand Down
12 changes: 8 additions & 4 deletions test/providers/open-library.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ describe("resolveOpenLibrary", () => {
"link": "https://openlibrary.org/books/OL7353617M",
"pageCount": 96,
"printType": "BOOK",
"publishedDate": "October 1, 1988",
"publisher": "Puffin",
"thumbnail": "https://covers.openlibrary.org/b/id/8739161-L.jpg",
"title": "Fantastic Mr. Fox",
}
Expand Down Expand Up @@ -111,6 +113,8 @@ describe("resolveOpenLibrary", () => {
"link": "https://openlibrary.org/isbn/9780374104092",
"pageCount": 96,
"printType": "BOOK",
"publishedDate": "October 1, 1988",
"publisher": undefined,
"thumbnail": "https://covers.openlibrary.org/b/id/8739161-L.jpg",
"title": "Fantastic Mr. Fox",
}
Expand All @@ -126,7 +130,7 @@ describe("resolveOpenLibrary", () => {
});

await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow(
`No books found with ISBN: ${isbn}`,
`No books found with ISBN: ${isbn}`
);
});

Expand All @@ -139,7 +143,7 @@ describe("resolveOpenLibrary", () => {
});

await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow(
"Wrong response code: 404",
"Wrong response code: 404"
);
});
});
Expand Down Expand Up @@ -181,7 +185,7 @@ describe("getAuthors", () => {
axios.get.mockResolvedValueOnce({ status: 404 });

await expect(getAuthors(rawAuthors)).rejects.toThrow(
"Unable to get author /authors/OL1A: 404",
"Unable to get author /authors/OL1A: 404"
);
});
});
Expand Down Expand Up @@ -258,7 +262,7 @@ describe("getWorks", () => {
axios.get.mockResolvedValueOnce({ status: 404 });

await expect(getWorks({ works })).rejects.toThrow(
"Unable to get /works/OL1A: 404",
"Unable to get /works/OL1A: 404"
);
});
});

0 comments on commit 68c887f

Please sign in to comment.