-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the batch create and update endpoints for Channel Currency …
…Assignments #53
- Loading branch information
Showing
4 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\Api\Generic; | ||
|
||
use BigCommerce\ApiV3\Client; | ||
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse; | ||
use GuzzleHttp\RequestOptions; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
trait BatchCreateResource | ||
{ | ||
abstract public function batchCreate(array $resources): PaginatedResponse; | ||
abstract protected function multipleResourcesEndpoint(): string; | ||
abstract public function getClient(): Client; | ||
|
||
protected function maxCreateBatchSize(): int | ||
{ | ||
return 10; | ||
} | ||
|
||
/** | ||
* @param array $resources | ||
* @return ResponseInterface[] | ||
*/ | ||
protected function batchCreateResource(array $resources): array | ||
{ | ||
$chunks = array_chunk($resources, $this->maxCreateBatchSize()); | ||
$responses = []; | ||
foreach ($chunks as $chunk) { | ||
$responses[] = $this->getClient()->getRestClient()->post( | ||
$this->multipleResourcesEndpoint(), | ||
[ | ||
RequestOptions::JSON => $chunk, | ||
] | ||
); | ||
} | ||
|
||
return $responses; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters