muglug/github-api

GitHub API v3 客户端


README

Build Status StyleCI Latest Stable Version Total Downloads Latest Unstable Version Monthly Downloads Daily Downloads

一个简单的 GitHub API 对象封装,使用 PHP 编写。

使用 GitHub API v3 并支持 GitHub API v4。对象 API (v3) 与 RESTful API 非常相似。

特性

  • 由于 API 类的懒加载,轻量且快速
  • 经过广泛测试和文档化

要求

安装

通过 Composer

$ composer require knplabs/github-api php-http/guzzle6-adapter "^1.1"

为什么是 php-http/guzzle6-adapter? 我们通过 HTTPlug 与任何 HTTP 消息客户端解耦。在我们的 文档 中了解有关客户端的更多信息。

使用 Laravel 吗?

Graham CampbellLaravel GitHub 可能会吸引你。

php-github-api 客户端的基本使用

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Github\Client();
$repositories = $client->api('user')->repositories('ornicar');

$client 对象中,你可以访问 GitHub 的所有内容。

缓存使用

此示例使用 PSR6 缓存池 redis-adapter。有关替代方案,请参阅 http://www.php-cache.com/

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

use Cache\Adapter\Redis\RedisCachePool;

$client = new \Redis();
$client->connect('127.0.0.1', 6379);
// Create a PSR6 cache pool
$pool = new RedisCachePool($client);

$client = new \Github\Client();
$client->addCache($pool);

// Do some request

// Stop using cache
$client->removeCache();

使用缓存,如果资源自上次以来没有更改,则客户端将获取缓存响应,无需 达到 GitHub 施加的 X-Rate-Limit

文档

有关更详细的文档,请参阅 doc 目录

许可

php-github-api 根据 MIT 许可证授权 - 有关详细信息,请参阅 LICENSE 文件

鸣谢

赞助商

KnpLabs Team

贡献者

感谢 GitHub 提供高质量的 API 和文档。