Skip to content

Commit

Permalink
APIS-3384 PHP-SDK добавить метод для получения доп.услуг
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaksv committed Feb 4, 2022
1 parent 4fd004c commit 6c7ac86
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/Api/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Apiship\Api;

use Apiship\Entity\Response\ListsPointsResponse;
use Apiship\Entity\Response\Part\ListsPointTypesResponse;
use Apiship\Entity\Response\ListsProvidersResponse;
use Apiship\Entity\Response\ListsServicesResponse;
use Apiship\Entity\Response\Part\Lists\Point;
use Apiship\Entity\Response\Part\Lists\PointType;
use Apiship\Entity\Response\Part\Lists\Provider;
use Apiship\Entity\Response\Part\Lists\Service;
use Apiship\Entity\Response\Part\ListsPointTypesResponse;
use Exception;

class Lists extends AbstractApi
{
Expand Down Expand Up @@ -47,7 +50,7 @@ public function getProviders($limit = 20, $offset = 0, $filter = '')
foreach ($provider as $key => $value) {
try {
$providerResult->$key = $value;
} catch (\Exception $e) {
} catch (Exception $e) {
continue;
}
}
Expand Down Expand Up @@ -99,7 +102,7 @@ public function getPoints($limit = 20, $offset = 0, $filter = '', $stateCheckOff
foreach ($point as $key => $value) {
try {
$pointResult->$key = $value;
} catch (\Exception $e) {
} catch (Exception $e) {
continue;
}
}
Expand Down Expand Up @@ -128,7 +131,7 @@ public function getPointTypes()
foreach ($data as $key => $datum) {
try {
$pointType->$key = $datum;
} catch (\Exception $e) {
} catch (Exception $e) {
continue;
}
}
Expand All @@ -139,4 +142,34 @@ public function getPointTypes()

return $response;
}


/**
* Получение списка дополнительных услуг службы доставки
* @param string|null $providerKey Если не указано, то возвращается список доп.услуг по всем службам доставки
* @return ListsServicesResponse
*/
public function getServices($providerKey = null)
{
$resultJson = $this->adapter->get('lists/services', [], ['providerKey' => $providerKey]);
$result = json_decode($resultJson, true);

$response = (new ListsServicesResponse())->setOriginJson($resultJson);
if (!empty($result)) {
foreach ($result as $row) {
$service = new Service();
foreach ($row as $key => $value) {
try {
$service->$key = $value;
} catch (Exception $e) {
continue;
}
}

$response->addResult($service);
}
}

return $response;
}
}
47 changes: 47 additions & 0 deletions src/Entity/Response/ListsServicesResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Apiship\Entity\Response;

use Apiship\Entity\AbstractResponse;
use Apiship\Entity\Response\Part\Lists\Service;

class ListsServicesResponse extends AbstractResponse
{
/**
* @var Service[] Массив результатов
*/
protected $results = [];

/**
* @return Service[]|null
*/
public function getResults()
{
return $this->results;
}

/**
* @param Service[] $results
*
* @return ListsServicesResponse
*/
public function setResults($results)
{
foreach ($results as $result) {
$this->addResult($result);
}

return $this;
}

/**
* @param Service $result
*
* @return ListsServicesResponse
*/
public function addResult($result)
{
$this->results[] = $result;
return $this;
}
}
137 changes: 137 additions & 0 deletions src/Entity/Response/Part/Lists/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* @author Serge Rodovnichenko <serge@syrnik.com>
* @copyright Serge Rodovnichenko, 2020
*/

namespace Apiship\Entity\Response\Part\Lists;

use Apiship\Entity\AbstractResponsePart;

/**
* Class Service
* @package Apiship\Entity\Response\Part\Lists
*/
class Service extends AbstractResponsePart
{
/** @var string */
protected $providerKey = '';
/** @var string */
protected $name = '';
/** @var string */
protected $extraParamName = '';
/** @var string */
protected $valueType = '';
/** @var string */
protected $valueDescription = '';
/** @var string */
protected $description = '';

/**
* @return string
*/
public function getProviderKey()
{
return $this->providerKey;
}

/**
* @param string $providerKey
* @return Service
*/
public function setProviderKey($providerKey)
{
$this->providerKey = $providerKey;
return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $name
* @return Service
*/
public function setName($name)
{
$this->name = $name;
return $this;
}

/**
* @return string
*/
public function getExtraParamName()
{
return $this->extraParamName;
}

/**
* @param string $extraParamName
* @return Service
*/
public function setExtraParamName($extraParamName)
{
$this->extraParamName = $extraParamName;
return $this;
}

/**
* @return string
*/
public function getValueType()
{
return $this->valueType;
}

/**
* @param string $valueType
* @return Service
*/
public function setValueType($valueType)
{
$this->valueType = $valueType;
return $this;
}

/**
* @return string
*/
public function getValueDescription()
{
return $this->valueDescription;
}

/**
* @param string $valueDescription
* @return Service
*/
public function setValueDescription($valueDescription)
{
$this->valueDescription = $valueDescription;
return $this;
}

/**
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* @param string $description
* @return Service
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
}

0 comments on commit 6c7ac86

Please sign in to comment.