/** * @param $requestName * @param callable $callback * @return mixed */ public function send($requestName, \Closure $callback = null) { $request = $this->requestFactory->create($requestName); if ($callback) { $callback($request); } // validate request $request->validateRequest(); $cacertUrl = __DIR__ . '/../cacert/' . $this->cacertFileName; $apiResponse = $this->sender->send($request, $cacertUrl); return $request->handleResponse($apiResponse); }
public function send() { $sender = new Sender($this->apiKey); $responseBody = $sender->send($this->message); $response = new Response($this->message, $responseBody); foreach ($response->getUpdate() as $oldId => $newId) { $this->updateRegistrationIds($oldId, $newId); } foreach ($response->getRemove() as $id) { $this->removeInvalidRegistrationId($id); } foreach ($response->getUnavailable() as $id) { $this->unavailableRegistration($id); } return $responseBody; }
/** * Tests creating an email with only Bcc recipients. */ public function testUndisclosedRecipients() { $email = new Email(); $email->setSubject('Test')->setFrom(new Email\Address('*****@*****.**', 'Blog.cz'))->setBody(new Email\Body('Test'))->addBcc(new Email\Address('*****@*****.**', 'Test Test')); $sender = new Sender(); $sender->setEmail($email); $result = $sender->send(Sender::MODE_NONE); $this->assertResult('sender-undisclosed-recipients.eml', $result); }
/** * @expectedException Exception * @covers Taxi\Sender::send */ public function testEmptyMessage() { $this->object->send("89129064863", ""); }
public function perform() { if (isset($this->args['delay'])) { $now = new \DateTime(); $delay = \DateTime::createFromFormat('U', $this->args['delay']); if ($delay > $now) { Client::enqueueFromJobArgs($this->args); return; } } $response = Sender::send(Message::fromArray($this->args['message']), $this->args['serverApiKey'], $this->args['gcmUrl'], isset($this->args['nextDelay']) ? $this->args['nextDelay'] : 1); /** * Response can be: * - DateTime: When to next retry sending the message. * - Response: Valid response that must be processed. * - Integer: Exponential Back off. */ if ($response instanceof \DateTime) { $this->args['delay'] = $response->format('U'); Client::enqueueFromJobArgs($this->args); } elseif ($response instanceof Response) { $failed = $response->getFailedIds(); foreach ($failed as $error => $group) { switch ($error) { case 'Unavailable': $message = $this->args['message']; $message['registration_ids'] = []; foreach ($group as $id => $item) { $message['registration_ids'][] = $id; } Client::enqueueFromJobArgs(['serverApiKey' => $this->args['serverApiKey'], 'gcmUrl' => $this->args['gcmUrl'], 'message' => $message]); break; case 'InternalServerError': foreach ($group as $item) { throw new PhpGcmQueueException('GCM\\DefaultSendJob->perform - Unknown Error: ' . $item, PhpGcmQueueException::UNKNOWN_ERROR); } break; default: /** * The following error messages should remove the Registration IDs from records. * - InvalidRegistration * - NotRegistered */ /** * The following error messages are malformed requests: * - MissingRegistration * - InvalidPackageName * - MismatchSenderId * - InvalidDataKey */ /** * The follow error messages are throttling (immediately stop sending, do not retry): * - DeviceMessageRate Exceeded * - TopicsMessageRate Exceeded */ /** * The follow error messages should never occur since they are explicitly tested for: * - MessageTooBig * - InvalidTtl */ break; } } $this->response = $response; } elseif (is_numeric($response)) { $this->args['delay'] = \DateTime::createFromFormat('U', strtotime('now +' . (int) $response . ' seconds'))->format('U'); $this->args['nextDelay'] = $response * 2; Client::enqueueFromJobArgs($this->args); } }