public function send(Postmaster_TransportModel $model)
 {
     $response = new Postmaster_TransportResponseModel(array('model' => $model));
     $listIds = array_values(array_filter($this->settings->listIds));
     if (!empty($this->settings->listId)) {
         $listIds[] = $this->settings->listId;
     }
     foreach ($listIds as $listId) {
         if ($this->settings->action == 'createAndSend') {
             try {
                 $this->createAndSendCampaign(array('apiKey' => $this->settings->apiKey, 'type' => $this->settings->campaignType, 'listId' => $listId, 'subject' => $model->settings->subject, 'fromEmail' => $model->settings->fromEmail, 'fromName' => $model->settings->fromName, 'toName' => $model->settings->toName, 'title' => $this->settings->title, 'html' => $model->settings->htmlBody, 'text' => $model->settings->body, 'trackOpens' => (bool) $this->settings->trackOpens, 'trackHtmlClicks' => (bool) $this->settings->trackHtmlClicks, 'trackTextClicks' => (bool) $this->settings->trackTextClicks, 'googleAnalytics' => $this->settings->googleAnalytics));
             } catch (\Exception $e) {
                 $response->setSuccess(false);
                 try {
                     $errorResponse = json_decode($e->getResponse()->getBody());
                     $response->setCode($errorResponse->code);
                     $response->addError($errorResponse->error);
                 } catch (\Exception $e) {
                     $response->addError($e->getMessage());
                 }
             }
         } else {
             if ($this->settings->action == 'subscribe') {
                 try {
                     $this->subscribe(array('type' => $this->settings->subscriberType, 'apiKey' => $this->settings->apiKey, 'listId' => $listId, 'email' => !empty($this->settings->subscriberEmail) ? $this->settings->subscriberEmail : $model->settings->fromEmail, 'newEmail' => $this->settings->subscriberNewEmail, 'groupings' => array(), 'doubleOptin' => $this->settings->doubleOptin, 'updateExisting' => $this->settings->updateExisting, 'replaceInterests' => $this->settings->replaceInterests, 'sendWelcome' => $this->settings->sendWelcome, 'profileVars' => $this->settings->profileVars));
                 } catch (\Exception $e) {
                     $response->setSuccess(false);
                     try {
                         $errorResponse = json_decode($e->getResponse()->getBody());
                         $response->setCode($errorResponse->code);
                         $response->addError($errorResponse->error);
                     } catch (\Exception $e) {
                         $response->addError($e->getMessage());
                     }
                 }
             } else {
                 if ($this->settings->action == 'unsubscribe') {
                     try {
                         $this->unsubscribe(array('apiKey' => $this->settings->apiKey, 'listId' => $listId, 'email' => !empty($this->settings->subscriberEmail) ? $this->settings->subscriberEmail : $model->settings->fromEmail));
                     } catch (\Exception $e) {
                         $response->setSuccess(false);
                         try {
                             $errorResponse = json_decode($e->getResponse()->getBody());
                             $response->setCode($errorResponse->code);
                             $response->addError($errorResponse->error);
                         } catch (\Exception $e) {
                             $response->addError($e->getMessage());
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }
 public function send(Postmaster_TransportModel $model)
 {
     $response = new Postmaster_TransportResponseModel(array('model' => $model));
     $listIds = array_values(array_filter($this->settings->listIds));
     if (!empty($this->settings->listId)) {
         $listIds[] = $this->settings->listId;
     }
     if ($this->settings->action == 'createAndSend') {
         try {
             $segmentIds = array();
             foreach ($this->settings->segmentIds as $row) {
                 $segmentIds[] = $row['id'];
             }
             $this->createAndSendCampaign(array('name' => $this->settings->name, 'apiKey' => $this->settings->apiKey, 'clientId' => $this->settings->clientId, 'listIds' => $listIds, 'segmentIds' => $segmentIds, 'subject' => $model->settings->subject, 'fromEmail' => $model->settings->fromEmail, 'fromName' => $model->settings->fromName, 'replyTo' => $model->settings->replyTo, 'htmlBody' => $model->settings->htmlBody, 'body' => $model->settings->body, 'confirmationEmail' => $this->settings->confirmationEmail));
         } catch (\Exception $e) {
             $response->setSuccess(false);
             try {
                 $errorResponse = json_decode($e->getResponse()->getBody());
                 $response->setCode($errorResponse->Code);
                 $response->addError($errorResponse->Message);
             } catch (\Exception $e) {
                 $response->addError($e->getMessage());
             }
         }
     } else {
         if ($this->settings->action == 'subscribe') {
             foreach ($listIds as $listId) {
                 try {
                     $this->subscribe(array('apiKey' => $this->settings->apiKey, 'listId' => $listId, 'email' => !empty($this->settings->subscriberEmail) ? $this->settings->subscriberEmail : $model->settings->fromEmail, 'name' => !empty($this->settings->subscriberName) ? $this->settings->subscriberName : $model->settings->fromName, 'customFields' => $this->settings->customFields, 'resubscribe' => $this->settings->resubscribe));
                 } catch (\Exception $e) {
                     $response->setSuccess(false);
                     try {
                         $errorResponse = json_decode($e->getResponse()->getBody());
                         $response->setCode($errorResponse->Code);
                         $response->addError($errorResponse->Message);
                     } catch (\Exception $e) {
                         $response->addError($e->getMessage());
                     }
                 }
             }
         } else {
             if ($this->settings->action == 'unsubscribe') {
                 foreach ($listIds as $listId) {
                     try {
                         $this->unsubscribe(array('apiKey' => $this->settings->apiKey, 'listId' => $listId, 'email' => !empty($this->settings->subscriberEmail) ? $this->settings->subscriberEmail : $model->settings->fromEmail));
                     } catch (\Exception $e) {
                         $response->setSuccess(false);
                         try {
                             $errorResponse = json_decode($e->getResponse()->getBody());
                             $response->setCode($errorResponse->Code);
                             $response->addError($errorResponse->Message);
                         } catch (\Exception $e) {
                             $response->addError($e->getMessage());
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }