Ejemplo n.º 1
0
 /**
  * @Route("/{endpoint}/")
  * @Route("/{endpoint}/{objectId}/")
  * @Method("GET")
  *
  * Index action for bridge controller
  *
  * @param Request     $request
  * @param string      $endpoint Endpoint of the api
  * @param string|null $objectId Identifier of object to retrieve
  *
  * @throws ContentApiException
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request, $endpoint, $objectId = null)
 {
     $data = [];
     $apiClient = $this->getClient();
     $sdk = $this->getSDK($apiClient);
     $parameters = $request->query->all();
     $requestParams = new RequestParameters();
     $requestParams->setQueryParameterArray($parameters);
     $endpointPath = sprintf('/%s', $endpoint);
     if ($this->isValidEndpoint($endpointPath)) {
         throw new ContentApiException(sprintf('Endpoint %s not supported.', $endpoint));
     }
     switch ($endpointPath) {
         case $sdk::SUPERDESK_ENDPOINT_ITEMS:
             if (!is_null($objectId)) {
                 $data = $sdk->getItem($objectId);
             } else {
                 $data = $sdk->getItems($requestParams);
             }
             break;
         case $sdk::SUPERDESK_ENDPOINT_PACKAGES:
             // TODO: Change this in the future to match the superdesk public api parameter name
             $resolve = isset($parameters['resolveItems']) && $parameters['resolveItems'] ? true : false;
             if (!is_null($objectId)) {
                 $data = $sdk->getPackage($objectId, $resolve);
             } else {
                 $data = $sdk->getPackages($requestParams, $resolve);
             }
             break;
     }
     return $this->render('SWPBridgeBundle:Default:data_dump.html.twig', ['data' => $data]);
 }
 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');
 }
 function let()
 {
     $requestParams = new RequestParameters();
     $requestParams->setQuery('text')->setMaxResults(10);
     $request = new Request('example.com', '/request/uri', $requestParams, 100);
     $request->setHeaders(array('Content-Type' => 'application/json'));
     $request->setOptions(array('some_options' => 'some value'));
     $this->beConstructedWith($request);
 }
Ejemplo n.º 4
0
use Superdesk\ContentApiSdk\Api\Request\RequestParameters;
/**
 * 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;
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getFullUrl()
 {
     return sprintf('%s/%s?%s', $this->getBaseUrl(), trim($this->uri, '/ '), $this->parameters->getAllParameters(true));
 }