Skip to content

Commit

Permalink
#1: Examples: get_collection.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mekras committed Sep 1, 2016
1 parent 7f835dc commit 21e9c0a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/examples/get_collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* This example should be executed in console
*
* Requires dev dependencies!
*/
namespace Comindware\Tracker\API\Examples;

use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Mekras\Atom\Document\FeedDocument;
use Mekras\OData\Client\OData;
use Mekras\OData\Client\URI\Uri;
use Mekras\OData\Client\URI\Filter as F;

require __DIR__ . '/../../vendor/autoload.php';

use Mekras\OData\Client\Service;

$service = new Service(
'http://services.odata.org/OData/OData.svc/',
HttpClientDiscovery::find(),
MessageFactoryDiscovery::find()
);

$uri = new Uri();
$uri->collection('Products');
$uri->options()
->filter(F::gte('Price', 15.5))
->top(5);

$document = $service->sendRequest(OData::GET, $uri);

if (!$document instanceof FeedDocument) {
die("Not a feed!\n");
}

$entries = $document->getFeed()->getEntries();
foreach ($entries as $entry) {
printf("Id: %s\nRelease: %s\n", $entry['ID'], $entry['Price']);
}

0 comments on commit 21e9c0a

Please sign in to comment.