Messages.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace OntraportAPI;
  3. /**
  4. * Class Messages
  5. *
  6. * @author ONTRAPORT
  7. *
  8. * @package OntraportAPI
  9. */
  10. class Messages extends BaseApi
  11. {
  12. /**
  13. * $var string endpoint for single message
  14. */
  15. protected $_endpoint = "Message";
  16. /**
  17. * $var string endpoint for plural messages
  18. */
  19. protected $_endpointPlural = "Messages";
  20. /**
  21. * @param Ontraport $client
  22. */
  23. public function __construct(Ontraport $client)
  24. {
  25. parent::__construct($client);
  26. }
  27. /*
  28. * @TODO This is a placeholder, API needs to be revised to follow one standard for endpoint naming
  29. */
  30. private $_mainMessageEndpoint = "message";
  31. /**
  32. * @brief Retrieve a single specified message
  33. *
  34. * @param mixed[] $requestParams The parameters to submit with GET request.
  35. * Possible array keys: "id" (required)
  36. *
  37. * @return string JSON formatted response
  38. */
  39. public function retrieveSingle($requestParams)
  40. {
  41. return parent::_retrieveSingle($requestParams);
  42. }
  43. /**
  44. * @brief Retrieve multiple messages according to specific criteria, handle pagination
  45. *
  46. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional but if "ids"
  47. * are not specified, all will be selected.
  48. * Possible array keys: "ids","start","range","sort","sortDir","condition","search",
  49. * "searchNotes","group_ids","performAll","externs","listFields"
  50. *
  51. * @return string JSON formatted array of response data: each page of data will be an element in that array.
  52. */
  53. public function retrieveMultiplePaginated($requestParams)
  54. {
  55. return parent::_retrieveMultiplePaginated($requestParams);
  56. }
  57. /**
  58. * @brief Retrieve multiple messages according to specific criteria
  59. *
  60. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional but if "ids"
  61. * are not specified, all will be selected.
  62. * Possible array keys: "ids","start","range","sort","sortDir","condition","search",
  63. * "searchNotes","group_ids","performAll","externs","listFields"
  64. *
  65. * @return string JSON formatted response
  66. */
  67. public function retrieveMultiple($requestParams)
  68. {
  69. return parent::_retrieveMultiple($requestParams);
  70. }
  71. /**
  72. * @brief Retrieve information (such as number of messages) about message collection
  73. *
  74. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional.
  75. * Possible array keys: "condition","search","searchNotes","group_ids","performAll"
  76. *
  77. * @return string JSON formatted response
  78. */
  79. public function retrieveCollectionInfo($requestParams)
  80. {
  81. return parent::_retrieveCollectionInfo($requestParams);
  82. }
  83. /**
  84. * @brief Retrieve meta for a message object
  85. *
  86. * @return string JSON formatted meta for message object
  87. */
  88. public function retrieveMeta()
  89. {
  90. return parent::_retrieveMeta();
  91. }
  92. /**
  93. * @brief Create a new message
  94. *
  95. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  96. * Possible array keys: "alias","name","subject","type" (must be "template","email",
  97. * "sms", or "task), "object_type_id" (default 0 for contacts),
  98. * "from" (can be "owner","custom", or a staff ID), "send_out_name"
  99. * "reply_to_email","plaintext","send_from","message_body",
  100. * "email_title"
  101. * Legacy email only: "message_body"
  102. * ONTRAmail only: "resource" (use with caution)
  103. * SMS only: "send_to" (default sms_number)
  104. * Task only: "task_data","due_date","task_owner","task_form"
  105. *
  106. * @return string JSON formatted response
  107. */
  108. public function create($requestParams)
  109. {
  110. $requiredParams = array("type");
  111. return $this->client->request($requestParams, $this->_mainMessageEndpoint, "post", $requiredParams, $options = NULL);
  112. }
  113. /**
  114. * @brief Update an existing message
  115. *
  116. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  117. * Possible array keys: "id" (required),"alias","name","subject","type" (must be
  118. * "template","email", "sms", or "task),"object_type_id"
  119. * (default 0 for contacts),"from" (can be "owner","custom", or a
  120. * staff ID), "send_out_name","reply_to_email","plaintext",
  121. * "send_from","message_body","email_title"
  122. * Legacy email only: "message_body"
  123. * ONTRAmail only: "resource" (use with caution)
  124. * SMS only: "send_to" (default sms_number)
  125. * Task only: "task_data","due_date","task_owner","task_form"
  126. *
  127. * @return string JSON formatted response
  128. */
  129. public function update($requestParams)
  130. {
  131. $requiredParams = array("id","type");
  132. return $this->client->request($requestParams, $this->_mainMessageEndpoint, "put", $requiredParams, $options = NULL);
  133. }
  134. }