Example #1
0
 public function testDeliverSendsJsonRecipients()
 {
     \Apostle::instance()->deliver = true;
     $queue = $this->getServiceBuilder()->get('queue');
     $mail1 = new Mail("slug-1", array("email" => "*****@*****.**"));
     $mail2 = new Mail("slug-2", array("email" => "*****@*****.**", "foo" => "bar"));
     $queue->add($mail1)->add($mail2);
     $this->setMockResponse($queue, "delivery_200.http");
     $this->assertEquals(true, $queue->deliver());
     $this->assertRequestJson(array("recipients" => array("*****@*****.**" => array("data" => array(), "template_id" => "slug-1"), "*****@*****.**" => array("data" => array("foo" => "bar"), "template_id" => "slug-2"))));
 }
Example #2
0
 public function deliver(&$failures = null)
 {
     $recipients = array();
     $failures = array();
     $this->results = array("valid" => array(), "invalid" => array());
     foreach ($this->emails as $email) {
         if (!isset($email->email) || $email->email == '') {
             $failures[] = $email;
             $this->results["invalid"][] = $email;
             $email->setDeliveryError("No email provided");
             continue;
         }
         if (!isset($email->template) || $email->template == '') {
             $failures[] = $email;
             $this->results["invalid"][] = $email;
             $email->setDeliveryError("No template provided");
             continue;
         }
         $recipients[$email->email] = $email->toArray();
         $this->results["valid"][] = $email;
     }
     if (count($failures) > 0) {
         return false;
     }
     if (!\Apostle::instance()->deliver) {
         return true;
     }
     $body = array("recipients" => $recipients);
     $response = $this->post('/', array('ContentType' => 'application/json; charset=utf-8', 'Authorization' => 'Bearer ' . \Apostle::instance()->domainKey, 'Apostle-Client' => 'PHP/' . \Apostle::VERSION), json_encode($body))->send();
     if ($response->getStatusCode() == 401) {
         $data = $response->json();
         if ($data && isset($data["message"])) {
             $failures = $data["message"];
         } else {
             $failures = "401 Unauthorized";
         }
     }
     return $response->isSuccessful();
 }
Example #3
0
 public function init()
 {
     \Apostle::setup($this->domainKey);
 }
Example #4
0
 public function setUp()
 {
     \Apostle::setup("abc", array("deliver" => false));
 }
Example #5
0
 /**
  * Resets the static Apostle instance
  */
 public static function reset($instance)
 {
     return self::$_instance = $instance;
 }