コード例 #1
0
 /**
  * Adds an email address action to campaign.
  * @param integer $campaignId
  * @param string $email
  * @return Campaign|HttpResponse|null
  * @throws ErrorException
  */
 public function setCampaignEmailAddressAction($campaignId, $email)
 {
     $resource = "/campaigns/";
     if (is_null($campaignId)) {
         throw new ErrorException("Parameter 'campaignId' cannot be null");
     } elseif (!is_int($campaignId)) {
         throw new ErrorException("Parameter 'campaignId' must be an integer");
     }
     if (is_null($email)) {
         throw new ErrorException("Parameter 'email' cannot be null");
     } elseif (!is_string($email)) {
         throw new ErrorException("Parameter 'email' must be a string");
     } elseif (!CommonUtil::is_email($email, true)) {
         throw new ErrorException("Parameter 'email' must be a valid email address");
     }
     try {
         $params = array();
         $params["address"] = $email;
         $resource .= "/{$campaignId}/actions/email";
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Campaign($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }