/** * Send message. * * @throws Tiqr_Message_Exception_AuthFailure * @throws Tiqr_Message_Exception_SendFailure */ public function send() { $service = self::_getService($this->getOptions()); $data = $this->getCustomProperties(); $data['text'] = $this->getText(); $message = new Zend_Mobile_Push_Message_Gcm(); $message->addToken($this->getAddress()); $message->setId($this->getId()); // TODO: GCM equivalent needed? $message->setData($data); try { $response = $service->send($message); } catch (Zend_Htpp_Client_Exception $e) { throw new Tiqr_Message_Exception_SendFailure("HTTP client error", true, $e); } catch (Zend_Mobile_Push_Exception_ServerUnavailable $e) { throw new Tiqr_Message_Exception_SendFailure("Server unavailable", true, $e); } catch (Zend_Mobile_Push_Exception_InvalidAuthToken $e) { throw new Tiqr_Message_Exception_AuthFailure("Invalid token", $e); } catch (Zend_Mobile_Push_Exception_InvalidPayload $e) { throw new Tiqr_Message_Exception_SendFailure("Payload too large", $e); } catch (Zend_Mobile_Push_Exception $e) { throw new Tiqr_Message_Exception_SendFailure("General send error", false, $e); } // handle errors, ignoring registration_id's foreach ($response->getResults() as $k => $v) { if (isset($v['error'])) { throw new Tiqr_Message_Exception_SendFailure("error in GCM response: " . $v['error'], true); } } }
public function testToJsonIntCollapseKeyEncodedAsString() { $msg = new Zend_Mobile_Push_Message_Gcm(); $msg->setId(10); $this->assertEquals('{"collapse_key":"10"}', $msg->toJson()); }