Skip to content

Commit

Permalink
Merge pull request #11 from lamoda/feature/LC-659-implement-get-mappi…
Browse files Browse the repository at this point in the history
…ng-categories

LC-659 Implement get mapping categories method
  • Loading branch information
AntonTrekov authored May 13, 2020
2 parents 92abaa4 + 2f5ad10 commit 336886f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/HTTP/Client/LamodaB2BClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class LamodaB2BClient
const URI_API_V1_FULFILMENT_SHIPMENTS = '/api/v1/shipments/fulfilment';
const URI_API_V1_GET_STOCK_STATE = '/api/v1/stock/goods';
const URI_API_V1_ORDER_ITEMS = '/api/v1/orders/%s%s/items';
const URI_API_V1_MAPPING_CATEGORIES = '/api/v1/mapping/categories';

const EVENT_CONFIRM = 'confirm';
const EVENT_CANCEL = 'cancel';
Expand Down Expand Up @@ -258,6 +259,34 @@ public function getPackTracking($trackingId)
return $packTrackingResponse->getBody();
}

/**
* @param string $partnerCode
* @param array $params
*
* @return array
* @throws HttpRequestException
*/
public function getMappingCategories(string $partnerCode, array $params): array
{
$accessToken = $this->getAccessToken($partnerCode);

$response = $this->sender->sendRequest(
self::URI_API_V1_MAPPING_CATEGORIES,
Sender::METHOD_GET,
$this->getHeaders(
[
'Authorization' => $this->getAuthString($accessToken),
]
),
null,
$params
);

$this->parseResponse($response);

return $response->getBody();
}

/**
* @param string $partnerCode
* @param string $path
Expand Down
41 changes: 41 additions & 0 deletions src/Provider/MappingCategoriesDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace LamodaB2B\Provider;

use Exception;
use LamodaB2B\HTTP\Client\LamodaB2BClient;
use LamodaB2B\HTTP\ConstantMessage;

class MappingCategoriesDataProvider
{
/** @var LamodaB2BClient */
private $lamodaB2BClient;

/**
* @param LamodaB2BClient $lamodaB2BClient
*/
public function __construct(LamodaB2BClient $lamodaB2BClient)
{
$this->lamodaB2BClient = $lamodaB2BClient;
}

/**
* @param string $partnerCode
* @param array $params
*
* @throws Exception
*
* @return array
*/
public function getMappingCategories(string $partnerCode, array $params): array
{
$stockStateBody = $this->lamodaB2BClient->getMappingCategories($partnerCode, $params);
if (!isset($stockStateBody['_embedded']['category_mapping'])
|| !is_array($stockStateBody['_embedded']['category_mapping'])
) {
throw new Exception(ConstantMessage::UNEXPECTED_STRUCTURE_RESPONCE);
}

return $stockStateBody['_embedded']['category_mapping'];
}
}

0 comments on commit 336886f

Please sign in to comment.