Add a function called getExternalLinks in a new file called external.py
This function takes a Book object as an argument, and is responsible for making API calls to Librivox and Standard Ebooks and returning a dictionary of URLs to those sites' listings for the given book
All API responses are cached using the CacheControl library which has been added to the project dependencies in requirements.txt. This will prevent unnecessary API calls.
We also had to update to the latest version of the requests library because we were using a very old version which was not compatible with the CacheControl library.
Librivox API calls are made using the following logic:
Request all books with the matching author last name.
If any results have the exact matching Gutenberg ID in their url_text_source field, then return the URL to the Librivox listing for that result.
If there were no results with the Gutenberg ID, then check to see if any have the exact matching title.
If there are none, then there is no result.
Standard Ebooks does not have an API, but it does have an OPDS catalog which contains a list of all of their ebooks. The logic used for this is as follows:
Retrieve the entire XML document for the OPDS catalog
For each book entry, if it has a matching Gutenberg ID, return the URL to the Standard Ebooks listing for that book.
If there were no matching entries, then there is no result.
Add a view called ExternalLinkView
This view uses the getExternalLinks function described above to provide an endpoint for AJAX calls to retrieve the external links for a given Book ID.
The external links are returned in JSON format.
Add code to the Ebook Listing Pages to show the external links
The Ebook Listing Page performs an AJAX call to the ExternalLinkView to retrieve the links for the book.
When the request completes, the results are dynamically inserted into the "Other Ways to Read This Book" section of the page.
This PR implements the following changes
getExternalLinks
in a new file calledexternal.py
CacheControl
library which has been added to the project dependencies inrequirements.txt
. This will prevent unnecessary API calls.requests
library because we were using a very old version which was not compatible with theCacheControl
library.url_text_source
field, then return the URL to the Librivox listing for that result.ExternalLinkView
getExternalLinks
function described above to provide an endpoint for AJAX calls to retrieve the external links for a given Book ID.ExternalLinkView
to retrieve the links for the book.