此包已被 废弃 并不再维护。没有建议的替代包。

SND API v2 客户端

1.0.0 2016-10-19 14:04 UTC

This package is not auto-updated.

Last update: 2023-04-29 09:40:42 UTC


README

Build Status Scrutinizer Code Quality

这是一个由斯塔万格阿ftenblad团队构建的,针对Packagist友好的SND API客户端。API使用application/json内容类型,UTF-8字符集。每个方法都返回对结果的json_decode运行的结果。目前尚不可配置,但我们计划在不久的将来引入实体水化器(以及实体)。

客户端提供对API的控制台访问

bin/sndapi-console

控制台使用需要三个参数

Options:
 --key (-s)            SND API key
 --secret (-s)         SND API secret
 --publicationId (-p)  SND API publication id (common, sa, fvn, bt, ap)

要求

  • php >= 5.5
  • composer
  • node & npm

安装

要将库添加到您的项目,只需运行

composer require "Schibsted-Tech-Polska/php-sndapi"

开发

您可以自由地开发库的新部分,但请注意,它已完全使用PHP Unit测试,您应使用pull请求来合并您的代码。

新闻

该库使用v2 snd新闻API,详情请参阅 此处。身份验证需要有效的API密钥,每个API方法还需要publicationId。Publication ID可以是以下之一

  • common
  • ap
  • bt
  • fvn
  • sa

用法

使用以下方式初始化库

<?php

use Stp\SndApi\News\Client as NewsClient;

const API_KEY = 'mnbvcxzlkjhgfdsapoiuytrew';
const API_SECRET = 'qwertyuiopasdfghjklzxcvbn';
const PUBLICATION_ID = 'sa';

$newsClient = new NewsClient(API_KEY, API_SECRET, PUBLICATION_ID);

方法

getServiceDocument

返回服务文档。

http://developers.snd.no/doc/news/documentation/publication.

<?php

$newsClient->getServiceDocument();

控制台

bin/sndapi-console news:servicedocument [-s|--secret="..."] [-p|--publicationId="..."]

getImageVersions

$newsClient->getImageVersions();


Console:

```sh
bin/sndapi-console news:image:versions [-s|--secret="..."] [-p|--publicationId="..."]

#### getSectionsList

Returns sections list. 

[http://developers.snd.no/doc/news/documentation/section#listsections](http://developers.snd.no/doc/news/documentation/section#listsections)

```php
<?php

$newsClient->getSectionsList();

控制台

bin/sndapi-console news:sections:list [-s|--secret="..."] [-p|--publicationId="..."]

getSubsectionsList

返回子部分列表。

http://developers.snd.no/doc/news/documentation/section#listsections

<?php

$newsClient->getSubsectionsList(217);

getSectionByUniqueName

使用其唯一名称查找一个部分。

http://developers.snd.no/doc/news/documentation/section#getsection

<?php

$newsClient->getSectionByUniqueName('nyheter');

控制台

bin/sndapi-console news:section:uniquename [-s|--secret="..."] [-p|--publicationId="..."] name

getSectionById

类似于上一个,但使用其ID查找部分。

http://developers.snd.no/doc/news/documentation/section#getsection

<?php

$newsClient->getSectionById(217);

控制台

bin/sndapi-console news:section:id [-s|--secret="..."] [-p|--publicationId="..."] id

getArticlesBySectionId

使用部分ID或部分的唯一名称查找文章列表。

http://developers.snd.no/doc/news/documentation/article#listarticles

参数

数字参数

  • areaLimit
  • offset
  • limit

布尔值

  • includeSubsections
  • homeSectionOnly
<?php

$newsClient->getArticlesBySectionId(
	217, 
	'desked', 
	[
		'limit' => 50
	]
);

控制台

bin/sndapi-console news:section:articles [-s|--secret="..."] [-p|--publicationId="..."] id method [parameters1] ... [parametersN]

getArticle

检索一个文章,别名searchByInstance,但提供contentType为article。

http://developers.snd.no/doc/news/documentation/article#getarticle

<?php

$newsClient->getArticle(3687148);

控制台

bin/sndapi-console news:article:id [-s|--secret="..."] [-p|--publicationId="..."] id

searchByInstance

返回指定contentId和contentType的搜索结果。

http://developers.snd.no/doc/news/documentation/search#byinstance

<?php

$newsClient->searchByInstance(3687148, 'article');

控制台

bin/sndapi-console news:search:instance [-s|--secret="..."] [-p|--publicationId="..."] id contentType

按集合搜索

返回提供的content ids的搜索结果。

http://developers.snd.no/doc/news/documentation/search#bycollection

<?php

$newsClient->searchByInstance([123456, 789012]);

控制台

bin/sndapi-console news:search:collection [-s|--secret="..."] [-p|--publicationId="..."] ids1 ... [idsN]

尚未实现

searchResource

http://developers.snd.no/doc/news/documentation/search#searchres

按标签搜索

http://developers.snd.no/doc/news/documentation/search#bytags

按查询搜索

http://developers.snd.no/doc/news/documentation/search#byquery