コード例 #1
0
 function its_method_get_packges_should_return_a_resource_collection(ApiClientInterface $client, Request $request)
 {
     $parameters = new RequestParameters();
     $parameters->setStartDate('1970-01-01');
     $request = $this->getNewRequest(ContentApiSdk::SUPERDESK_ENDPOINT_PACKAGES, $parameters);
     $client->makeApiCall($request)->willReturn('{ "_links": { "parent": { "title": "home", "href": "/" }, "self": { "title": "items", "href": "items?start_date=2015-08-01" } }, "_items": [], "_meta": { "page": 1, "total": 0, "max_results": 25 } }');
     $this->getPackages($parameters)->shouldReturnAnInstanceOf('Superdesk\\ContentApiSdk\\Api\\Pagerfanta\\ResourceCollection');
 }
コード例 #2
0
/**
 * Configure Below
 *
 * Please fill in the correct value of your Content API instance.
 */
define('API_HOST', '');
define('API_PORT', 80);
define('API_PROTOCOL', null);
define('API_CLIENT_ID', '');
define('API_USERNAME', '');
define('API_PASSWORD', '');
/**
 * End of configuration
 */
$parameters = new RequestParameters();
$parameters->setStartDate(date('Y-m-d', strtotime('-1 year')))->setPage(1)->setMaxResults(1);
$genericClient = new CurlClient();
$authentication = new OAuthPasswordAuthentication($genericClient);
$authentication->setClientId(API_CLIENT_ID)->setUsername(API_USERNAME)->setPassword(API_PASSWORD);
$apiClient = new DefaultApiClient($genericClient, $authentication);
$contentApi = new ContentApiSdk($apiClient, API_HOST, API_PORT, API_PROTOCOL);
echo ".:  Getting items  :.\n\n";
$items = $contentApi->getItems($parameters);
$items->setMaxPerPage($parameters->getMaxResults());
$items->setCurrentPage($parameters->getPage());
echo "Total items: {$items->getNbResults()}\n";
echo "Items per page: {$items->getMaxPerPage()}\n";
echo "Total pages: {$items->getNbPages()}\n\n";
// Some limit, so we dont accicentally get every item
$maxPages = $items->getNbPages() < 10 ? $items->getNbPages() : 10;
if ($items->haveToPaginate()) {