Maileon PHP client  1.5.0
Easily integrate your PHP application with Maileon.
MailingsService.php
1 <?php
2 
10 {
11 
25  function createMailing($name, $subject, $deprecatedParameter = false, $type = "regular")
26  {
27  $queryParameters = array(
28  'name' => urlencode($name),
29  'subject' => urlencode($subject),
30  'type' => urlencode($type),
31  );
32 
33  return $this->post('mailings', "", $queryParameters);
34  }
35 
39  function getMailingIdByName($mailingName)
40  {
41  return $this->get('mailings/name/' . rawurlencode($mailingName));
42  }
43 
47  function checkIfMailingExistsByName($mailingName)
48  {
49  $response = $this->get('mailings/name/' . rawurlencode($mailingName));
50  return ($response->isSuccess());
51  }
52 
56  function disableQosChecks($mailingId)
57  {
58  return $this->put('mailings/' . $mailingId . '/settings/disableQosChecks');
59  }
60 
64  function setTriggerDispatchLogic($mailingId, $logic)
65  {
66  $queryParameters = array();
67  return $this->put('mailings/' . $mailingId . '/dispatching', $logic, $queryParameters);
68  }
69 
73  function setTriggerActive($mailingId)
74  {
75  return $this->post('mailings/' . $mailingId . '/dispatching/activate', "");
76  }
77 
85  function deleteActiveTriggerMailing($mailingId)
86  {
87  return $this->delete("mailings/" . $mailingId . "/dispatching");
88  }
89 
97  function deleteMailing($id)
98  {
99  return $this->delete("mailings/" . $id);
100  }
101 
118  function setHTMLContent($mailingId, $html, $doImageGrabbing = true, $doLinkTracking = false)
119  {
120  $queryParameters = array(
121  'doImageGrabbing' => ($doImageGrabbing == TRUE) ? "true" : "false",
122  'doLinkTracking' => ($doLinkTracking == TRUE) ? "true" : "false"
123  );
124  return $this->post('mailings/' . $mailingId . '/contents/html', $html, $queryParameters, "text/html");
125  }
126 
139  function setTextContent($mailingId, $text)
140  {
141  return $this->post('mailings/' . $mailingId . '/contents/text', $text, array(), "text/plain");
142  }
143 
155  function getHTMLContent($mailingId)
156  {
157  return $this->get('mailings/' . $mailingId . '/contents/html', null, "text/html");
158  }
159 
171  function getTextContent($mailingId)
172  {
173  return $this->get('mailings/' . $mailingId . '/contents/text', null, "text/plain");
174  }
175 
188  function setTargetGroupId($mailingId, $targetGroupId)
189  {
190  return $this->post('mailings/' . $mailingId . '/targetgroupid', "<targetgroupid>" . $targetGroupId . "</targetgroupid>");
191  }
192 
204  function getTargetGroupId($mailingId)
205  {
206  return $this->get('mailings/' . $mailingId . '/targetgroupid', null);
207  }
208 
222  function setSender($mailingId, $email)
223  {
224  return $this->post('mailings/' . $mailingId . '/contents/sender', "<sender>" . $email . "</sender>");
225  }
226 
238  function getSender($mailingId)
239  {
240  return $this->get('mailings/' . $mailingId . '/contents/sender');
241  }
242 
255  function setSubject($mailingId, $subject)
256  {
257  return $this->post('mailings/' . $mailingId . '/contents/subject', "<subject>" . $subject . "</subject>");
258  }
259 
271  function getSubject($mailingId)
272  {
273  return $this->get('mailings/' . $mailingId . '/contents/subject');
274  }
275 
288  function setPreviewText($mailingId, $previewText)
289  {
290  return $this->post('mailings/' . $mailingId . '/contents/previewtext', "<previewtext>" . $previewText . "</previewtext>");
291  }
292 
304  function getPreviewText($mailingId)
305  {
306  return $this->get('mailings/' . $mailingId . '/contents/previewtext');
307  }
308 
309 
310 
326  function setTemplate($mailingId, $template)
327  {
328  return $this->put('mailings/' . $mailingId . '/template', "<templateId>" . $template . "</templateId>");
329  }
330 
344  function getTemplate($mailingId)
345  {
346  return $this->get('mailings/' . $mailingId . '/template');
347  }
348 
349 
350 
362  function resetContentsToTemplate($mailingId)
363  {
364  return $this->put('mailings/' . $mailingId . '/contents/reset');
365  }
366 
379  function setSenderAlias($mailingId, $senderalias)
380  {
381  return $this->post('mailings/' . $mailingId . '/contents/senderalias', "<senderalias>" . $senderalias . "</senderalias>");
382  }
383 
396  function setRecipientAlias($mailingId, $recipientalias)
397  {
398  return $this->post('mailings/' . $mailingId . '/contents/recipientalias', "<recipientalias>" . $recipientalias . "</recipientalias>");
399  }
400 
412  function getReplyToAddress($mailingId)
413  {
414  return $this->get('mailings/' . $mailingId . '/settings/replyto');
415  }
416 
429  function setReplyToAddress($mailingId, $auto = true, $customEmail = null)
430  {
431  $queryParameters = array(
432  'auto' => ($auto == TRUE) ? "true" : "false",
433  'customEmail' => $customEmail
434  );
435 
436  return $this->post('mailings/' . $mailingId . '/settings/replyto', null, $queryParameters);
437  }
438 
461  function getMailingsBySchedulingTime($scheduleTime, $beforeSchedulingTime = true, $fields = array(), $page_index = 1, $page_size = 100, $orderBy = "id", $order = "DESC")
462  {
463  $queryParameters = array(
464  'page_index' => $page_index,
465  'page_size' => $page_size,
466  'scheduleTime' => urlencode($scheduleTime),
467  'beforeSchedulingTime' => ($beforeSchedulingTime == TRUE) ? "true" : "false",
468  'orderBy' => $orderBy,
469  'order' => $order
470  );
471 
472  $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
473 
474  return $this->get('mailings/filter/scheduletime', $queryParameters);
475  }
476 
493  function getMailingsByTypes($types, $fields = array(), $page_index = 1, $page_size = 100)
494  {
495  $queryParameters = array(
496  'page_index' => $page_index,
497  'page_size' => $page_size,
498  'order' => "DESC"
499  );
500 
501  $queryParameters = $this->appendArrayFields($queryParameters, "types", $types);
502  $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
503 
504  return $this->get('mailings/filter/types', $queryParameters);
505  }
506 
515  function sendMailingNow($mailingId)
516  {
517  return $this->post('mailings/' . $mailingId . '/sendnow');
518  }
519 
534  function setMailingSchedule($mailingId, $date, $hours, $minutes)
535  {
536  $queryParameters = array(
537  'date' => $date,
538  'hours' => $hours,
539  'minutes' => $minutes
540  );
541 
542  return $this->put('mailings/' . $mailingId . '/schedule', "", $queryParameters);
543  }
544 
559  function updateMailingSchedule($mailingId, $date, $hours, $minutes)
560  {
561  $queryParameters = array(
562  'date' => $date,
563  'hours' => $hours,
564  'minutes' => $minutes
565  );
566 
567  return $this->post('mailings/' . $mailingId . '/schedule', "", $queryParameters);
568  }
569 
570 
582  function getDoiMailingKey($mailingId)
583  {
584  return $this->get('mailings/' . $mailingId . '/settings/doi_key', null, "text/html");
585  }
586 
597  function setDoiMailingKey($mailingId, $doiKey)
598  {
599  return $this->post('mailings/' . $mailingId . '/settings/doi_key', "<doi_key>$doiKey</doi_key>");
600  }
601 
609  function deactivateTriggerMailing($mailingId)
610  {
611  return $this->delete("mailings/${mailingId}/dispatching");
612  }
613 
614 
622  function getTriggerDispatchLogic($mailingId)
623  {
624  return $this->get("mailings/${mailingId}/dispatching");
625  }
626 
627 
635  function getSchedule($mailingId)
636  {
637  return $this->get("mailings/${mailingId}/schedule");
638  }
639 
647  function getArchiveUrl($mailingId)
648  {
649  return $this->get("mailings/${mailingId}/archiveurl");
650  }
651 
659  function getReportUrl($mailingId)
660  {
661  return $this->get("mailings/${mailingId}/reporturl");
662  }
663 
676  function setName($mailingId, $name)
677  {
678  return $this->post('mailings/' . $mailingId . '/name', "<name>" . $name . "</name>");
679  }
680 
688  function getName($mailingId)
689  {
690  return $this->get("mailings/${mailingId}/name");
691  }
692 
705  function setTags($mailingId, $tags)
706  {
707  return $this->post('mailings/' . $mailingId . '/settings/tags', "<tags>" . join("#", $tags) . "</tags>");
708  }
709 
717  function getTags($mailingId)
718  {
719  return $this->get("mailings/${mailingId}/settings/tags");
720  }
721 
734  function setLocale($mailingId, $locale)
735  {
736  return $this->post('mailings/' . $mailingId . '/settings/locale', "<locale>$locale</locale>");
737  }
738 
746  function getLocale($mailingId)
747  {
748  return $this->get("mailings/${mailingId}/settings/locale");
749  }
750 
759  function fillRssSmartContentTags($mailingId)
760  {
761  return $this->post("mailings/${mailingId}/contents/smartmailing/rss");
762  }
763 
771  function copyMailing($mailingId)
772  {
773  return $this->post("mailings/${mailingId}/copy");
774  }
775 
787  function addAttachmentFromFile($mailingId, $filename, $contentType, $attachmentFileName = null)
788  {
789  $handle = fopen($filename, "rb");
790  if (FALSE === $filename) {
791  throw new com_maileon_api_MaileonAPIException("Cannot read file " . $filename . ".");
792  }
793  $contents = '';
794  while (!feof($handle)) {
795  $contents .= fread($handle, 8192);
796  }
797  fclose($handle);
798  if ($attachmentFileName === null) {
799  $attachmentFileName = basename($filename);
800  }
801 
802  return $this->addAttachment($mailingId, $attachmentFileName, $contentType, $contents);
803  }
804 
815  function addAttachment($mailingId, $filename, $contentType, $contents)
816  {
817  $queryParameters = array('filename' => $filename);
818  return $this->post("mailings/${mailingId}/attachments", $contents, $queryParameters, null, null, $contentType, strlen($contents));
819  }
820 
827  function getAttachments($mailingId)
828  {
829  return $this->get("mailings/${mailingId}/attachments");
830  }
831 
839  function getAttachment($mailingId, $attachmentId)
840  {
841  return $this->get("mailings/${mailingId}/attachments/${attachmentId}");
842  }
843 
850  function getAttachmentsCount($mailingId)
851  {
852  return $this->get("mailings/${mailingId}/attachments/count");
853  }
854 
861  function deleteAttachments($mailingId)
862  {
863  return $this->delete("mailings/${mailingId}/attachments/");
864  }
865 
875  function deleteAttachment($mailingId, $attachmentId)
876  {
877  if (empty($attachmentId)) {
878  throw new com_maileon_api_MaileonAPIException("no attachment id specified");
879  }
880 
881  return $this->delete("mailings/${mailingId}/attachments/${attachmentId}");
882  }
883 
891  function copyAttachments($mailingId, $srcMailingId)
892  {
893  $queryParameters = array('src_mailing_id' => $srcMailingId);
894 
895  return $this->put("mailings/${mailingId}/attachments", "", $queryParameters);
896  }
897 
904  function getCustomProperties($mailingId)
905  {
906  return $this->get("mailings/${mailingId}/settings/properties");
907  }
908 
909 
917  function addCustomProperties($mailingId, $properties)
918  {
919 
920  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><properties></properties>");
921 
922  if (is_array($properties)) {
923  foreach ($properties as $property) {
924  $this->sxml_append($xml, $property->toXML());
925  }
926  } else {
927  $this->sxml_append($xml, $properties->toXML());
928  }
929 
930  return $this->post("mailings/${mailingId}/settings/properties", $xml->asXML());
931  }
932 
933 
941  function updateCustomProperty($mailingId, $property)
942  {
943 
944  $queryParameters = array(
945  'name' => $property->key,
946  'value' => $property->value
947  );
948 
949  return $this->put("mailings/${mailingId}/settings/properties", "", $queryParameters);
950  }
951 
952 
960  function deleteCustomProperty($mailingId, $propertyName)
961  {
962 
963  $queryParameters = array(
964  'name' => $propertyName,
965  );
966 
967  return $this->delete("mailings/${mailingId}/settings/properties", $queryParameters);
968  }
969 
970 
981  function sendTestMail($mailingId, $email)
982  {
983  $queryParameters = array(
984  'email' => $email
985  );
986 
987  return $this->post("mailings/${mailingId}/sendtestemail", "", $queryParameters);
988  }
989 
997  function sendTestMailToTestTargetGroup($mailingId, $testTargetGroupId)
998  {
999  $queryParameters = array(
1000  'test_targetgroup_id' => $testTargetGroupId
1001  );
1002 
1003  return $this->post("mailings/${mailingId}/checks/testsendout", "", $queryParameters);
1004  }
1005 
1006  function sxml_append(SimpleXMLElement $to, SimpleXMLElement $from)
1007  {
1008  $toDom = dom_import_simplexml($to);
1009  $fromDom = dom_import_simplexml($from);
1010  $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
1011  }
1012 
1013 }
addCustomProperties($mailingId, $properties)
getAttachment($mailingId, $attachmentId)
deleteCustomProperty($mailingId, $propertyName)
setPreviewText($mailingId, $previewText)
setTargetGroupId($mailingId, $targetGroupId)
updateMailingSchedule($mailingId, $date, $hours, $minutes)
setMailingSchedule($mailingId, $date, $hours, $minutes)
getMailingsByTypes($types, $fields=array(), $page_index=1, $page_size=100)
createMailing($name, $subject, $deprecatedParameter=false, $type="regular")
deleteAttachment($mailingId, $attachmentId)
setSenderAlias($mailingId, $senderalias)
getMailingsBySchedulingTime($scheduleTime, $beforeSchedulingTime=true, $fields=array(), $page_index=1, $page_size=100, $orderBy="id", $order="DESC")
setHTMLContent($mailingId, $html, $doImageGrabbing=true, $doLinkTracking=false)
addAttachment($mailingId, $filename, $contentType, $contents)
copyAttachments($mailingId, $srcMailingId)
setRecipientAlias($mailingId, $recipientalias)
addAttachmentFromFile($mailingId, $filename, $contentType, $attachmentFileName=null)
sendTestMailToTestTargetGroup($mailingId, $testTargetGroupId)
post($resourcePath, $payload="", $queryParameters=array(), $mimeType= 'application/vnd.maileon.api+xml', $deserializationType=null, $contentType=null, $contentLength=null)
setReplyToAddress($mailingId, $auto=true, $customEmail=null)
put($resourcePath, $payload="", $queryParameters=array(), $mimeType= 'application/vnd.maileon.api+xml', $deserializationType=null)