Esempio n. 1
0
 public function testDeliverSendsJsonRecipients()
 {
     \Apostle::instance()->deliver = true;
     $queue = $this->getServiceBuilder()->get('queue');
     $mail1 = new Mail("slug-1", array("email" => "user1@example.org"));
     $mail2 = new Mail("slug-2", array("email" => "user2@example.org", "foo" => "bar"));
     $queue->add($mail1)->add($mail2);
     $this->setMockResponse($queue, "delivery_200.http");
     $this->assertEquals(true, $queue->deliver());
     $this->assertRequestJson(array("recipients" => array("user1@example.org" => array("data" => array(), "template_id" => "slug-1"), "user2@example.org" => array("data" => array("foo" => "bar"), "template_id" => "slug-2"))));
 }
Esempio n. 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();
 }
Esempio n. 3
0
 public function init()
 {
     \Apostle::setup($this->domainKey);
 }
Esempio n. 4
0
 public function setUp()
 {
     \Apostle::setup("abc", array("deliver" => false));
 }
Esempio n. 5
0
 /**
  * Resets the static Apostle instance
  */
 public static function reset($instance)
 {
     return self::$_instance = $instance;
 }