Open Library search API
If nothing is found on the server, returns results from open library API. Clicking on a book imports it.
This commit is contained in:
29
internal/openlibrary/openlibrarysearch.go
Normal file
29
internal/openlibrary/openlibrarysearch.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package openlibrary
|
||||
|
||||
type OpenLibrarySearchResult struct {
|
||||
Books []OpenLibrarySearchBook `json:"docs"`
|
||||
NumFound int `json:"numFound"`
|
||||
}
|
||||
|
||||
type OpenLibrarySearchBook struct {
|
||||
Title string `json:"title"`
|
||||
Authors []string `json:"author_name"`
|
||||
OpenLibraryId string `json:"cover_edition_key"`
|
||||
}
|
||||
|
||||
func CallOpenLibrarySearch(searchterm string, limit int, offset int) (OpenLibrarySearchResult, error) {
|
||||
var queryResult OpenLibrarySearchResult
|
||||
u, err := computeOpenLibraryUrl("search.json")
|
||||
if err != nil {
|
||||
return queryResult, err
|
||||
}
|
||||
if limit != 0 {
|
||||
addQueryParamInt(u, "limit", limit)
|
||||
}
|
||||
if offset != 0 {
|
||||
addQueryParamInt(u, "offset", offset)
|
||||
}
|
||||
addQueryParam(u, "q", searchterm)
|
||||
err = fetchAndParseResult(u, &queryResult)
|
||||
return queryResult, err
|
||||
}
|
||||
Reference in New Issue
Block a user