예제 #1
0
func compositeISBNLookup(ctx ae.Context, country string, isbn isbn13.ISBN13) (resp *data.BookMetaData, err error) {
	// look in my own library first - if this fails badly, abort anything further
	if shelf, err := persistence.LookupBookshelf(ctx); err == nil {
		if book := shelf.LookupInfo(isbn); book != nil {
			return book, nil
		}
	} else {
		return nil, err
	}

	var errors ae.MultiError
	if book, err := persistence.LookupISBN(ctx, country, isbn); err == nil {
		return book, nil
	} else {
		errors = append(errors, err)
	}

	if r, err := googlebooks.LookupISBN(ctx, country, isbn); err == nil {
		persistence.StoreISBNResult(ctx, country, isbn, r)
		return r, nil
	} else {
		errors = append(errors, err)
	}

	return nil, errors
}
예제 #2
0
func getVolumeBulk(call *Call) (reply *data.LookupReply, err error) {
	var shelf *data.Bookshelf

	if shelf, err = persistence.LookupBookshelf(call.Context); err == nil {
		call.Context.Debugf("Bookshelf contains %d volumes", len(shelf.Books))

		infos := shelf.Books

		for _, str := range call.Request.URL.Query()["search"] {
			matches := shelf.Search(str)

			infos = make([]data.BookMetaData, len(matches))
			for i, ptr := range matches {
				infos[i] = *ptr
			}

			call.Context.Debugf("Filtered by \"%s\", down to %d entries: %v", str, len(infos), infos)
		}

		reply = &data.LookupReply{
			Count:     len(infos),
			BookInfos: shelf.Books,
		}
	}

	return
}