/** * Handle the GCM response. Remove, update or retry if appropriate. * * @param \HipsterJazzbo\Telegraph\Pushable $pushable * @param \HipsterJazzbo\Telegraph\Message $message * @param \ZendService\Google\Gcm\Response $response */ protected function handleResponse(Pushable $pushable, Message $message, $response) { $results = $response->getResults(); $result = $results[$pushable->getToken()]; if (isset($result['message_id']) && isset($result['registration_id'])) { call_user_func($this->updateCallback, $pushable, $result['registration_id']); } elseif (isset($result['error'])) { switch ($result['error']) { case 'Unavailable': $this->retry($pushable, $message); break; case 'NotRegistered': call_user_func($this->removeCallback, $pushable); break; default: throw new ServiceException('gcm', $result['error']); } } }
public function testResponse() { $responseArr = array('results' => array(array('message_id' => '1:234')), 'success' => 1, 'failure' => 0, 'canonical_ids' => 0, 'multicast_id' => '123'); $response = new Response(); $response->setResponse($responseArr); $this->assertEquals($responseArr, $response->getResponse()); $this->assertEquals(1, $response->getSuccessCount()); $this->assertEquals(0, $response->getFailureCount()); $this->assertEquals(0, $response->getCanonicalCount()); // test results non correlated $expected = array(array('message_id' => '1:234')); $this->assertEquals($expected, $response->getResults()); $expected = array(0 => '1:234'); $this->assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID)); $message = new Message(); $message->setRegistrationIds(array('ABCDEF')); $response->setMessage($message); $expected = array('ABCDEF' => '1:234'); $this->assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID)); }