Webhooks.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. class Mandrill_Webhooks {
  3. public function __construct(Mandrill $master) {
  4. $this->master = $master;
  5. }
  6. /**
  7. * Get the list of all webhooks defined on the account
  8. * @return array the webhooks associated with the account
  9. * - return[] struct the individual webhook info
  10. * - id integer a unique integer indentifier for the webhook
  11. * - url string The URL that the event data will be posted to
  12. * - description string a description of the webhook
  13. * - auth_key string the key used to requests for this webhook
  14. * - events array The message events that will be posted to the hook
  15. * - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
  16. * - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  17. * - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
  18. * - batches_sent integer the number of event batches that have ever been sent to this webhook
  19. * - events_sent integer the total number of events that have ever been sent to this webhook
  20. * - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
  21. */
  22. public function getList() {
  23. $_params = array();
  24. return $this->master->call('webhooks/list', $_params);
  25. }
  26. /**
  27. * Add a new webhook
  28. * @param string $url the URL to POST batches of events
  29. * @param string $description an optional description of the webhook
  30. * @param array $events an optional list of events that will be posted to the webhook
  31. * - events[] string the individual event to listen for
  32. * @return struct the information saved about the new webhook
  33. * - id integer a unique integer indentifier for the webhook
  34. * - url string The URL that the event data will be posted to
  35. * - description string a description of the webhook
  36. * - auth_key string the key used to requests for this webhook
  37. * - events array The message events that will be posted to the hook
  38. * - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
  39. * - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  40. * - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
  41. * - batches_sent integer the number of event batches that have ever been sent to this webhook
  42. * - events_sent integer the total number of events that have ever been sent to this webhook
  43. * - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
  44. */
  45. public function add($url, $description=null, $events=array()) {
  46. $_params = array("url" => $url, "description" => $description, "events" => $events);
  47. return $this->master->call('webhooks/add', $_params);
  48. }
  49. /**
  50. * Given the ID of an existing webhook, return the data about it
  51. * @param integer $id the unique identifier of a webhook belonging to this account
  52. * @return struct the information about the webhook
  53. * - id integer a unique integer indentifier for the webhook
  54. * - url string The URL that the event data will be posted to
  55. * - description string a description of the webhook
  56. * - auth_key string the key used to requests for this webhook
  57. * - events array The message events that will be posted to the hook
  58. * - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
  59. * - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  60. * - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
  61. * - batches_sent integer the number of event batches that have ever been sent to this webhook
  62. * - events_sent integer the total number of events that have ever been sent to this webhook
  63. * - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
  64. */
  65. public function info($id) {
  66. $_params = array("id" => $id);
  67. return $this->master->call('webhooks/info', $_params);
  68. }
  69. /**
  70. * Update an existing webhook
  71. * @param integer $id the unique identifier of a webhook belonging to this account
  72. * @param string $url the URL to POST batches of events
  73. * @param string $description an optional description of the webhook
  74. * @param array $events an optional list of events that will be posted to the webhook
  75. * - events[] string the individual event to listen for
  76. * @return struct the information for the updated webhook
  77. * - id integer a unique integer indentifier for the webhook
  78. * - url string The URL that the event data will be posted to
  79. * - description string a description of the webhook
  80. * - auth_key string the key used to requests for this webhook
  81. * - events array The message events that will be posted to the hook
  82. * - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
  83. * - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  84. * - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
  85. * - batches_sent integer the number of event batches that have ever been sent to this webhook
  86. * - events_sent integer the total number of events that have ever been sent to this webhook
  87. * - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
  88. */
  89. public function update($id, $url, $description=null, $events=array()) {
  90. $_params = array("id" => $id, "url" => $url, "description" => $description, "events" => $events);
  91. return $this->master->call('webhooks/update', $_params);
  92. }
  93. /**
  94. * Delete an existing webhook
  95. * @param integer $id the unique identifier of a webhook belonging to this account
  96. * @return struct the information for the deleted webhook
  97. * - id integer a unique integer indentifier for the webhook
  98. * - url string The URL that the event data will be posted to
  99. * - description string a description of the webhook
  100. * - auth_key string the key used to requests for this webhook
  101. * - events array The message events that will be posted to the hook
  102. * - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
  103. * - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  104. * - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
  105. * - batches_sent integer the number of event batches that have ever been sent to this webhook
  106. * - events_sent integer the total number of events that have ever been sent to this webhook
  107. * - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
  108. */
  109. public function delete($id) {
  110. $_params = array("id" => $id);
  111. return $this->master->call('webhooks/delete', $_params);
  112. }
  113. }