nino/google-books-search 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nino/google-books-search

最新稳定版本:2.0.0

Composer 安装命令:

composer require nino/google-books-search

包简介

Search volumes from Google Books API

README 文档

README

PHP package to search volumes from Google Books API.

Usage

Installation

composer require nino/google-books-search

Basic usage

use Nino\GoogleBooksSearch\GoogleBooksSearch;

$booksSearch = new GoogleBooksSearch();

$result = $booksSearch->search('quilting')->get();

foreach ($result->books as $book) {
    echo "<h1>" . $book->volumeInfo->title . "</h1>";
    echo "<p>" . $book->volumeInfo->description . "</p>";
};

Options

The search accept the following options :

  • maxResults : The maximum number of results to return, the maximum allowable value is 40.
  • printType : Restrict search to a specific print type (all, books, magazines)
  • projection : Get certain fields from the (lite) or all the fields (full)
  • sorting : Order of results (relevance, newest)

You can pass theses to the GoogleBooksSearch's constructor to set theses for all searches of this instance.

You can pass theses to the search method to overwrite instance's options.

public function __construct(array $options = []);
public function search(string $q, array $options = []): self;

Pagination

Auto pagination

The method autoPaginate() allow you to get a new page at each get().

use Nino\GoogleBooksSearch\GoogleBooksSearch;

$booksSearch = new GoogleBooksSearch();

$booksSearch->search('quilting')->autoPaginate();

$page1 = $booksSearch->get();
$page2 = $booksSearch->get();

Note : If you redefine a search query via the search() method the page count is reset.

Manual pagination

Set the page you want to get with the page() method prior to the get() call

use Nino\GoogleBooksSearch\GoogleBooksSearch;

$booksSearch = new GoogleBooksSearch();

$page4 = $booksSearch->search('quilting')->page(4)->get();
$page8 = $booksSearch->page(8)->get();

Is there a next page ?

If you want to know if there is a next page the result returned by the get() method have a property isLastPage

use Nino\GoogleBooksSearch\GoogleBooksSearch;

$booksSearch = new GoogleBooksSearch();

$result = $booksSearch->search('quilting')->page(4)->get();
if ($result->isLastPage) {
    echo "last page: 4";
};

Note that isLastPage() return true if you have requested a page greater than the actual last page.

Contributing

Merge requests, bug reports and suggestions are welcome.

License

This library is licensed under the GNU Affero General Public License v3.0 or later.

Please read the LICENSE file for details.

统计信息

  • 总下载量: 742
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: AGPL-3.0-or-later
  • 更新时间: 2020-01-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固