Maileon PHP client  1.3.2
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/' . urlencode($mailingName));
42  }
43 
47  function checkIfMailingExistsByName($mailingName)
48  {
49  $response = $this->get('mailings/name/' . urlencode($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 setSenderAlias($mailingId, $senderalias)
289  {
290  return $this->post('mailings/' . $mailingId . '/contents/senderalias', "<senderalias>" . $senderalias . "</senderalias>");
291  }
292 
305  function setRecipientAlias($mailingId, $recipientalias)
306  {
307  return $this->post('mailings/' . $mailingId . '/contents/recipientalias', "<recipientalias>" . $recipientalias . "</recipientalias>");
308  }
309 
321  function getReplyToAddress($mailingId)
322  {
323  return $this->get('mailings/' . $mailingId . '/settings/replyto');
324  }
325 
338  function setReplyToAddress($mailingId, $auto = true, $customEmail = null)
339  {
340  $queryParameters = array(
341  'auto' => ($auto == TRUE) ? "true" : "false",
342  'customEmail' => $customEmail
343  );
344 
345  return $this->post('mailings/' . $mailingId . '/settings/replyto', null, $queryParameters);
346  }
347 
370  function getMailingsBySchedulingTime($scheduleTime, $beforeSchedulingTime = true, $fields = array(), $page_index = 1, $page_size = 100, $orderBy = "id", $order = "DESC")
371  {
372  $queryParameters = array(
373  'page_index' => $page_index,
374  'page_size' => $page_size,
375  'scheduleTime' => urlencode($scheduleTime),
376  'beforeSchedulingTime' => ($beforeSchedulingTime == TRUE) ? "true" : "false",
377  'orderBy' => $orderBy,
378  'order' => $order
379  );
380 
381  $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
382 
383  return $this->get('mailings/filter/scheduletime', $queryParameters);
384  }
385 
402  function getMailingsByTypes($types, $fields = array(), $page_index = 1, $page_size = 100)
403  {
404  $queryParameters = array(
405  'page_index' => $page_index,
406  'page_size' => $page_size,
407  'order' => "DESC"
408  );
409 
410  $queryParameters = $this->appendArrayFields($queryParameters, "types", $types);
411  $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
412 
413  return $this->get('mailings/filter/types', $queryParameters);
414  }
415 
424  function sendMailingNow($mailingId)
425  {
426  return $this->post('mailings/' . $mailingId . '/sendnow');
427  }
428 
429 
430 
442  function getDoiMailingKey($mailingId)
443  {
444  return $this->get('mailings/' . $mailingId . '/settings/doi_key', null, "text/html");
445  }
446 
457  function setDoiMailingKey($mailingId, $doiKey)
458  {
459  return $this->post('mailings/' . $mailingId . '/settings/doi_key', "<doi_key>$doiKey</doi_key>");
460  }
461 
469  function deactivateTriggerMailing($mailingId)
470  {
471  return $this->delete("mailings/${mailingId}/dispatching");
472  }
473 
474 
475 
483  function getTriggerDispatchLogic($mailingId)
484  {
485  return $this->get("mailings/${mailingId}/dispatching");
486  }
487 
488 
496  function getSchedule($mailingId)
497  {
498  return $this->get("mailings/${mailingId}/schedule");
499  }
500 
508  function getArchiveUrl($mailingId)
509  {
510  return $this->get("mailings/${mailingId}/archiveurl");
511  }
512 
525  function setName($mailingId, $name)
526  {
527  return $this->post('mailings/' . $mailingId . '/name', "<name>" . $name . "</name>");
528  }
529 
537  function getName($mailingId)
538  {
539  return $this->get("mailings/${mailingId}/name");
540  }
541 
554  function setTags($mailingId, $tags)
555  {
556  return $this->post('mailings/' . $mailingId . '/settings/tags', "<tags>" . join("#", $tags) . "</tags>");
557  }
558 
566  function getTags($mailingId)
567  {
568  return $this->get("mailings/${mailingId}/settings/tags");
569  }
570 
583  function setLocale($mailingId, $locale)
584  {
585  return $this->post('mailings/' . $mailingId . '/settings/locale', "<locale>$locale</locale>");
586  }
587 
595  function getLocale($mailingId)
596  {
597  return $this->get("mailings/${mailingId}/settings/locale");
598  }
599 
608  function fillRssSmartContentTags($mailingId)
609  {
610  return $this->post("mailings/${mailingId}/contents/smartmailing/rss");
611  }
612 
620  function copyMailing($mailingId)
621  {
622  return $this->post("mailings/${mailingId}/copy");
623  }
624 
636  function addAttachmentFromFile($mailingId, $filename, $contentType, $attachmentFileName = null) {
637  $handle = fopen($filename, "rb");
638  if (FALSE === $filename) {
639  throw new com_maileon_api_MaileonAPIException("Cannot read file " . $filename . ".");
640  }
641  $contents = '';
642  while (!feof($handle)) {
643  $contents .= fread($handle, 8192);
644  }
645  fclose($handle);
646  if ($attachmentFileName === null) {
647  $attachmentFileName = basename($filename);
648  }
649 
650  return $this->addAttachment($mailingId, $attachmentFileName, $contentType, $contents);
651  }
652 
663  function addAttachment($mailingId, $filename, $contentType, $contents) {
664  $queryParameters = array( 'filename' => $filename );
665  return $this->post("mailings/${mailingId}/attachments", $contents, $queryParameters, null, null, $contentType, strlen($contents));
666  }
667 
674  function getAttachments($mailingId) {
675  return $this->get("mailings/${mailingId}/attachments");
676  }
677 
685  function getAttachment($mailingId, $attachmentId) {
686  return $this->get("mailings/${mailingId}/attachments/${attachmentId}");
687  }
688 
695  function getAttachmentsCount($mailingId) {
696  return $this->get("mailings/${mailingId}/attachments/count");
697  }
698 
705  function deleteAttachments($mailingId) {
706  return $this->delete("mailings/${mailingId}/attachments/");
707  }
708 
718  function deleteAttachment($mailingId, $attachmentId) {
719  if(empty($attachmentId)) { throw new com_maileon_api_MaileonAPIException("no attachment id specified"); }
720 
721  return $this->delete("mailings/${mailingId}/attachments/${attachmentId}");
722  }
723 
731  function copyAttachments($mailingId, $srcMailingId) {
732  $queryParameters = array( 'src_mailing_id' => $srcMailingId );
733 
734  return $this->put("mailings/${mailingId}/attachments", "", $queryParameters);
735  }
736 
743  function getCustomProperties($mailingId) {
744  return $this->get("mailings/${mailingId}/settings/properties");
745  }
746 
747 
755  function addCustomProperties($mailingId, $properties) {
756 
757  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><properties></properties>");
758 
759  if (is_array($properties)) {
760  foreach ($properties as $property) {
761  $this->sxml_append($xml, $property->toXML());
762  }
763  } else {
764  $this->sxml_append($xml, $properties->toXML());
765  }
766 
767  return $this->post("mailings/${mailingId}/settings/properties", $xml->asXML());
768  }
769 
770 
778  function updateCustomProperty($mailingId, $property) {
779 
780  $queryParameters = array(
781  'name' => $property->key,
782  'value' => $property->value
783  );
784 
785  return $this->put("mailings/${mailingId}/settings/properties", "", $queryParameters);
786  }
787 
788 
796  function deleteCustomProperty($mailingId, $propertyName) {
797 
798  $queryParameters = array(
799  'name' => $propertyName,
800  );
801 
802  return $this->delete("mailings/${mailingId}/settings/properties", $queryParameters);
803  }
804 
805  function sxml_append(SimpleXMLElement $to, SimpleXMLElement $from) {
806  $toDom = dom_import_simplexml($to);
807  $fromDom = dom_import_simplexml($from);
808  $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
809  }
810 
811 }
addCustomProperties($mailingId, $properties)
getAttachment($mailingId, $attachmentId)
deleteCustomProperty($mailingId, $propertyName)
setTargetGroupId($mailingId, $targetGroupId)
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)
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)