Switch from open library API to Inventaire API
This commit is contained in:
41
internal/inventaire/inventaire.go
Normal file
41
internal/inventaire/inventaire.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package inventaire
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/callapiutils"
|
||||
)
|
||||
|
||||
type InventaireSearchResult struct {
|
||||
Results []InventaireSearchBook `json:"results"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
type InventaireSearchBook struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func computeInventaireUrl(paths ...string) (*url.URL, error) {
|
||||
baseUrl := "https://inventaire.io/api"
|
||||
return callapiutils.ComputeUrl(baseUrl, paths...)
|
||||
}
|
||||
|
||||
func CallInventaireSearch(searchterm string, limit int, offset int) (InventaireSearchResult, error) {
|
||||
var queryResult InventaireSearchResult
|
||||
u, err := computeInventaireUrl("search")
|
||||
if err != nil {
|
||||
return queryResult, err
|
||||
}
|
||||
if limit != 0 {
|
||||
callapiutils.AddQueryParamInt(u, "limit", limit)
|
||||
}
|
||||
if offset != 0 {
|
||||
callapiutils.AddQueryParamInt(u, "offset", offset)
|
||||
}
|
||||
callapiutils.AddQueryParam(u, "types", "works")
|
||||
callapiutils.AddQueryParam(u, "search", searchterm)
|
||||
err = callapiutils.FetchAndParseResult(u, &queryResult)
|
||||
return queryResult, err
|
||||
}
|
||||
Reference in New Issue
Block a user