This is a packagist-friendly SND API client built by Stavanger Aftenblad's team. The API uses application/json content type with UTF-8 charset. Each method returns result of json_decode
run on result. This is not configurable yet, however we plan to introduce entity hydrators (along with entities) in near future.
Client provides console access to the API:
bin/sndapi-console
Console usage requires three parameters:
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
In order to add the library to your project just run:
composer require "Schibsted-Tech-Polska/php-sndapi"
Feel free to develop new parts of the library, but have in mind that it's fully tested with PHP Unit and you should use pull requests in order to merge your code.
The library uses v2 snd news api described here. Authentication requires valid API secret, every API method also requires publicationId. Publication ID is one of the following:
- common
- ap
- bt
- fvn
- sa
Initialize the library with
<?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);
Returns service document.
http://developers.snd.no/doc/news/documentation/publication.
<?php
$newsClient->getServiceDocument();
Console:
bin/sndapi-console news:servicedocument [-s|--secret="..."] [-p|--publicationId="..."]
$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();
Console:
bin/sndapi-console news:sections:list [-s|--secret="..."] [-p|--publicationId="..."]
Returns subsections list.
http://developers.snd.no/doc/news/documentation/section#listsections
<?php
$newsClient->getSubsectionsList(217);
Finds a section using its unique name.
http://developers.snd.no/doc/news/documentation/section#getsection
<?php
$newsClient->getSectionByUniqueName('nyheter');
Console:
bin/sndapi-console news:section:uniquename [-s|--secret="..."] [-p|--publicationId="..."] name
Similar to previous one, but finds a section using its id.
http://developers.snd.no/doc/news/documentation/section#getsection
<?php
$newsClient->getSectionById(217);
Console:
bin/sndapi-console news:section:id [-s|--secret="..."] [-p|--publicationId="..."] id
Finds a list of articles using section id or section's unique name.
http://developers.snd.no/doc/news/documentation/article#listarticles
Numeric parameters
- areaLimit
- offset
- limit
Boolean values
- includeSubsections
- homeSectionOnly
<?php
$newsClient->getArticlesBySectionId(
217,
'desked',
[
'limit' => 50
]
);
Console:
bin/sndapi-console news:section:articles [-s|--secret="..."] [-p|--publicationId="..."] id method [parameters1] ... [parametersN]
Retrieves one article, alias to searchByInstance but with article provided as contentType.
http://developers.snd.no/doc/news/documentation/article#getarticle
<?php
$newsClient->getArticle(3687148);
Console:
bin/sndapi-console news:article:id [-s|--secret="..."] [-p|--publicationId="..."] id
Returns search result of a specified contentId and contentType.
http://developers.snd.no/doc/news/documentation/search#byinstance
<?php
$newsClient->searchByInstance(3687148, 'article');
Console:
bin/sndapi-console news:search:instance [-s|--secret="..."] [-p|--publicationId="..."] id contentType
Returns search results of provided content ids.
http://developers.snd.no/doc/news/documentation/search#bycollection
<?php
$newsClient->searchByInstance([123456, 789012]);
Console:
bin/sndapi-console news:search:collection [-s|--secret="..."] [-p|--publicationId="..."] ids1 ... [idsN]
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