Skip to content

Commit

Permalink
Merge pull request #7 from quintype/support-for-new-cached-bulk-api
Browse files Browse the repository at this point in the history
Support for the new cached Bulk
  • Loading branch information
anagh-p committed Oct 28, 2017
2 parents c3c27fe + 10df888 commit 6e6e25b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/Quintype/Api.php
Expand Up @@ -40,6 +40,11 @@ public function executeBulk()
return $this->bulk->executeBulk();
}

public function executeBulkCached()
{
return $this->bulk->executeBulkCached();
}

public function getBulkResponse($name, $showAltInPage = '')
{
return $this->bulk->getBulkResponse($name, $showAltInPage);
Expand Down Expand Up @@ -185,6 +190,11 @@ public function bulkCollections($requestPayload) {
return $this->collections->bulkCollections($requestPayload);
}

public function bulkCollectionsCached($requestPayload)
{
return $this->collections->bulkCollectionsCached($requestPayload);
}

//Version 1.12.0 onwards
public function getEntity($entityId = '', $params = []) {
return $this->entities->getEntity($entityId, $params);
Expand Down
8 changes: 8 additions & 0 deletions src/Quintype/Api/BaseFunctions.php
Expand Up @@ -69,4 +69,12 @@ public function removeDateFromSlug($storySlug){
return $storySlug;
}
}

public function reorderKeys($arr, $order) {
$output = [];
foreach($order as $key => $val) {
$output[$key] = $arr[$key];
}
return $output;
}
}
18 changes: 13 additions & 5 deletions src/Quintype/Api/Bulk.php
Expand Up @@ -19,20 +19,30 @@ public function addBulkRequest($name, $request, $params)
return $this;
}

public function executeBulk()
private function doExecuteBulk($path)
{
$requests = [];
foreach ($this->requests as $key => $value) {
$requests[$key] = $value->toBulkRequest();
}
$apiResponse = $this->getStories($requests);
$apiResponse = $this->getStories($requests, $path);
$responses = [];
foreach ($this->requests as $key => $value) {
$responses[$key] = $value->fromBulkResponse($apiResponse[$key]);
}
$this->responses = $responses;
}

public function executeBulk()
{
return $this->doExecuteBulk('/api/v1/bulk');
}

public function executeBulkCached()
{
return $this->doExecuteBulk('/api/v1/bulk-request');
}

public function getBulkResponse($name, $showAltInPage = '')
{
if ($showAltInPage === '') {
Expand All @@ -42,11 +52,9 @@ public function getBulkResponse($name, $showAltInPage = '')
}
}

private function getStories($requestPayload)
private function getStories($requestPayload, $query)
{
$query = '/api/v1/bulk';
$response = $this->base->postRequest($query, ['requests' => $requestPayload]);

return $response['results'];
}

Expand Down
5 changes: 5 additions & 0 deletions src/Quintype/Api/Collections.php
Expand Up @@ -44,4 +44,9 @@ public function bulkCollections($requestPayload)

return $response['results'];
}

public function bulkCollectionsCached($requestPayload) {
$response = $this->base->postRequest('/api/v1/bulk-request', ['requests' => $requestPayload]);
return $this->base->reorderKeys($response['results'], $requestPayload);
}
}

0 comments on commit 6e6e25b

Please sign in to comment.