Closed ghost closed 8 years ago
/offtopic @NicklasWallgren: You mean multiple requests in one envelope? I'd be really curious to see how you implement that, the solution I had for this was not so nice :laughing: :
class AbstractApiRequest implements ApiRequestInterface
{
/** @var array */
protected $requests;
/** @var array|Message[] */
protected $responsePrototypes;
/**
* ApiRequestInterface constructor.
*
* @param array $requestTypes Contents: \POGOProtos\Networking\Requests\RequestType objects/consts / \POGOProtos\Networking\Requests\Request objects
* @param array|\Protobuf\Message[] $responsePrototypes
*
* @see \POGOProtos\Networking\Requests\RequestType
* @see \POGOProtos\Networking\Requests\Request
*/
public function __construct(array $requestTypes, array $responsePrototypes)
{
$this->requests = $requestTypes;
$this->responsePrototypes = $responsePrototypes;
}
public function getRequestTypes():array
{
return $this->requests;
}
/**
* Get the Protobuf messages of this request's response.
*
* @param ResponseEnvelope $response
*
* @return array|\Protobuf\Message[]
*/
public function getResponses(ResponseEnvelope $responseEnvelope):array
{
$responses = [];
/** @var \Protobuf\Collection|\Protobuf\Stream[] $returns */
$returns = $responseEnvelope->getReturnsList();
$returnsCount = $returns->count();
for ($i = 0; $i < $returnsCount; ++$i) {
$responses[] = $this->responsePrototypes[$i]->fromStream($returns[$i]);
}
return $responses;
}
}
/**
* Send a request given by an ApiRequestInterface.
*
* @param ApiRequestInterface $request
*
* @return array|\Protobuf\Message[]
*/
public function sendRequest(ApiRequestInterface $request):array
{
return $request->getResponses($this->sendRequestRaw($request->getRequestTypes()));
}
After I saw your solution to persisting AccessTokens with events/listeners I'd expect to get surprised again :+1:
@DrDelay Exactly, let us see what I can come up with :)
Nice, it's probably better to update the inventory internally than updating via request.
I will improve the handling of multiple requests in a upcoming release.