/** * log a subscription request to the database * @param string $recipientEmail the email address of the recipient * @param string $recipientName the name of the recipient * @param array $fields set of fields (answers) to assign to the user record * @param string $listId unique identifier for the list * @param string $clientId unique identifier for the client making the request * @return null */ public function log($recipientEmail, $recipientName, $fields, $listId, $clientId) { $logged = $this->repo->store(["list_id" => $listId, "client_id" => $clientId, "recipient_email" => $recipientEmail, "recipient_name" => $recipientName, "fields" => json_encode($fields), "requested" => getDateTime()]); if (!$logged) { return apiErrorResponse('badRequest', ['errors' => "There was a problem with the request."]); } Event::fire('RequestWasLogged'); return apiSuccessResponse('ok'); }
/** * Request an individual user be subscribed to the email list * @return mixed */ public function subscribe(\App\V1\Lib\MailLogger $logger) { if (!isset($_POST['listId']) or !isset($_POST['userEmail']) or !isset($_POST['fields']) or !isset($_POST['userName'])) { return apiErrorResponse('badRequest'); } $listId = $_POST['listId']; # make sure supplied list ID is a valid list if (!$this->mailer->getList($listId)) { return apiErrorResponse('unprocessable', ['errors' => 'Unknown list ID']); } $userEmail = $_POST['userEmail']; $userName = $_POST['userName']; $fields = $_POST['fields']; # log the subscription request which we'll try and action later on return $logger->log($userEmail, $userName, $fields, $listId, getClientIdentifier()); }
/** * Update the details of a list with supplied data * @param array $updates the details * @return API response */ public function updateList(array $data) { if (!is_array($data) or !isset($data["listId"]) or !isset($data["listName"])) { return apiErrorResponse('failedDependency', []); } $lister = new Lister($this, $data["listId"]); # create the basic array needed by the campaign monitor API $listData = ["Title" => $data["listName"]]; # add in the default values for new lists as required by the CM API $core = array_merge($listData, $this->coreValues); # send it $response = $lister->updateList($core); if ($response->http_status_code == 200) { return apiSuccessResponse('ok', $response); } return apiErrorResponse('badRequest', ['errors' => $response->response->Message]); }
/** * create a new list * @return mixed */ public function createList() { # check to see if we have the required fields if (!isset($_POST['listName'])) { return apiErrorResponse('insufficientArguments'); } # make the call to create the form $result = $this->mailer->createList($_POST['listName']); # if we get a successful response back from the Mail API if ($result->http_status_code == 201) { return apiSuccessResponse('ok', ['listId' => $result->response]); } # otherwise its failed for some reason. So report it return apiErrorResponse('unprocessable', ['furtherResponseCode' => $result->response->Code, 'furtherResponseMsg' => $result->response->Message]); }