public function testDeserialize()
 {
     $payloadResponse = ['apikey' => 'mock', 'success' => true, 'action' => 'mock.json', 'requestNumber' => 999, 'itemsCount' => 1];
     $mockResponseClass = 'Colada\\Europeana\\Tests\\Test\\Payload\\MockPayloadResponse';
     $serializedPayload = $this->payloadResponseSerializer->deserialize($payloadResponse, $mockResponseClass);
     $this->assertInstanceOf($mockResponseClass, $serializedPayload);
     $this->assertTrue($serializedPayload->isSuccess());
 }
예제 #2
0
 /**
  * @param PayloadInterface $payload The payload to send
  * @param string|null      $apiKey  Required API key to use during the API-call,
  *                                  defaults to the one configured during construction
  *
  * @throws EuropeanaException If the payload could not be sent
  *
  * @return PayloadResponseInterface Actual class depends on the payload used,
  *                                  e.g. chat.postMessage will return an instance of ChatPostMessagePayloadResponse
  */
 public function send(PayloadInterface $payload, $apiKey = null)
 {
     try {
         if ($apiKey === null && $this->apiKey === null) {
             throw new \InvalidArgumentException('You must supply an API key to send a payload, since you did not provide one during construction');
         }
         $responseData = $this->doSend($payload, $apiKey);
         return $this->payloadResponseSerializer->deserialize($responseData, $payload->getResponseClass());
     } catch (\Exception $e) {
         throw new EuropeanaException('Failed to send payload', null, $e);
     }
 }