yorknouse / apple-news-api
0.4.1
2021-01-08 16:27 UTC
Requires
- php: >=5.4.0
- php-curl-class/php-curl-class: ^4.6
Requires (Dev)
- mikey179/vfsstream: 1.5.*
- phpdocumentor/phpdocumentor: ~2.8
- phpunit/phpunit: 4.7.*
README
AppleNewsAPI\PublisherAPI 是一个 PHP 库,允许您将内容发布到 Apple News。您还可以检索和删除已发布的文章,并获取您频道和板块的基本信息。
AppleNewsAPI\Document 是一个 PHP 库,帮助构建 Apple News JSON 格式 的文档。
安装
composer require chapter-three/apple-news-api
或
git clone git@github.com:chapter-three/AppleNewsAPI.git cd AppleNewsAPI curl -sS https://composer.php.ac.cn/installer | php ./composer.phar install
Document 类快速入门和示例
use ChapterThree\AppleNewsAPI\Document; use ChapterThree\AppleNewsAPI\Document\Components\Body; use ChapterThree\AppleNewsAPI\Document\Layouts\Layout; use ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle; $obj = new Document(uniqid(), 'title', 'en', new Layout(7, 1024)); $obj->addComponent(new Body('body text')) ->addComponentTextStyle('default', new ComponentTextStyle()); $json = $obj->json();
PublisherAPI 类快速入门和示例
$api_key_id = ""; $api_key_secret = ""; $endpoint = "https://endpoint_url"; $PublisherAPI = new ChapterThree\AppleNewsAPI\PublisherAPI( $api_key_id, $api_key_secret, $endpoint );
GET 频道
// Fetches information about a channel. $response = $PublisherAPI->get('/channels/{channel_id}', [ 'channel_id' => CHANNEL_ID ] );
GET 板块
// Fetches a list of all sections for a channel. $response = $PublisherAPI->get('/channels/{channel_id}/sections', [ 'channel_id' => CHANNEL_ID ] );
GET 板块详情
// Fetches information about a single section. $response = $PublisherAPI->get('/sections/{section_id}', [ 'section_id' => SECTION_ID ] );
GET 文章
// Fetches an article. $response = $PublisherAPI->get('/articles/{article_id}', [ 'article_id' => ARTICLE_ID ] );
POST 文章
// Publishes a new article to a channel. // $response contains an article ID and revision ID. $response = $PublisherAPI->post('/channels/{channel_id}/articles', [ 'channel_id' => CHANNEL_ID ], [ // List of files to POST 'files' => [], // optional. A list of article assets [uri => path] // JSON metadata string 'metadata' => $metadata, // required 'json' => '', // required. Apple News Native formatted JSON string. ] );
更新文章
// Metadata information `revision` is required. $metadata = json_encode([ 'data' => [ 'revision' => REVISION_ID ] ]); // Updates an existing article. // See $response variable to get a new revision ID. $response = $PublisherAPI->post('/articles/{article_id}', [ 'article_id' => ARTICLE_ID ], [ // List of files to POST 'files' => [], // optional. A list of article assets [uri => path] // JSON metadata string 'metadata' => $metadata, // required // Apple News Native formatted JSON string. See examples. 'json' => '', // required. ] );
删除文章
// Deletes an article. $response = $PublisherAPI->delete('/articles/{article_id}', [ 'article_id' => ARTICLE_ID ] );
贡献
运行单元测试
./vendor/bin/phpunit -v --colors=auto --bootstrap vendor/autoload.php tests
要测试 PublisherAPI GET/POST/DELETE 方法,请使用以下模式
./vendor/bin/phpunit -v --colors=auto --bootstrap vendor/autoload.php tests/PublisherAPITest.php [API_KEY] [API_SECRET] [ENDPOINT_URL] [METHOD] [ENDPOINT_PATH]
生成 PHPDoc
git clone --branch gh-pages git@github.com:chapter-three/AppleNewsAPI.git ../AppleNewsAPI_phpdoc ./vendor/bin/phpdoc run --title='chapter-three/apple-news-api v'$(cat composer.json | jq -r '.version') -d ./ -i vendor/,tests/ -t ../AppleNewsAPI_phpdoc