Subaccounts.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. class Mandrill_Subaccounts {
  3. public function __construct(Mandrill $master) {
  4. $this->master = $master;
  5. }
  6. /**
  7. * Get the list of subaccounts defined for the account, optionally filtered by a prefix
  8. * @param string $q an optional prefix to filter the subaccounts' ids and names
  9. * @return array the subaccounts for the account, up to a maximum of 1,000
  10. * - return[] struct the individual subaccount info
  11. * - id string a unique indentifier for the subaccount
  12. * - name string an optional display name for the subaccount
  13. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  14. * - status string the current sending status of the subaccount, one of "active" or "paused"
  15. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  16. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  17. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  18. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  19. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  20. * - sent_total integer the number of emails the subaccount has sent since it was created
  21. */
  22. public function getList($q=null) {
  23. $_params = array("q" => $q);
  24. return $this->master->call('subaccounts/list', $_params);
  25. }
  26. /**
  27. * Add a new subaccount
  28. * @param string $id a unique identifier for the subaccount to be used in sending calls
  29. * @param string $name an optional display name to further identify the subaccount
  30. * @param string $notes optional extra text to associate with the subaccount
  31. * @param integer $custom_quota an optional manual hourly quota for the subaccount. If not specified, Mandrill will manage this based on reputation
  32. * @return struct the information saved about the new subaccount
  33. * - id string a unique indentifier for the subaccount
  34. * - name string an optional display name for the subaccount
  35. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  36. * - status string the current sending status of the subaccount, one of "active" or "paused"
  37. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  38. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  39. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  40. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  41. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  42. * - sent_total integer the number of emails the subaccount has sent since it was created
  43. */
  44. public function add($id, $name=null, $notes=null, $custom_quota=null) {
  45. $_params = array("id" => $id, "name" => $name, "notes" => $notes, "custom_quota" => $custom_quota);
  46. return $this->master->call('subaccounts/add', $_params);
  47. }
  48. /**
  49. * Given the ID of an existing subaccount, return the data about it
  50. * @param string $id the unique identifier of the subaccount to query
  51. * @return struct the information about the subaccount
  52. * - id string a unique indentifier for the subaccount
  53. * - name string an optional display name for the subaccount
  54. * - notes string optional extra text to associate with the subaccount
  55. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  56. * - status string the current sending status of the subaccount, one of "active" or "paused"
  57. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  58. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  59. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  60. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  61. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  62. * - sent_total integer the number of emails the subaccount has sent since it was created
  63. * - sent_hourly integer the number of emails the subaccount has sent in the last hour
  64. * - hourly_quota integer the current hourly quota for the subaccount, either manual or reputation-based
  65. * - last_30_days struct stats for this subaccount in the last 30 days
  66. * - sent integer the number of emails sent for this subaccount in the last 30 days
  67. * - hard_bounces integer the number of emails hard bounced for this subaccount in the last 30 days
  68. * - soft_bounces integer the number of emails soft bounced for this subaccount in the last 30 days
  69. * - rejects integer the number of emails rejected for sending this subaccount in the last 30 days
  70. * - complaints integer the number of spam complaints for this subaccount in the last 30 days
  71. * - unsubs integer the number of unsbuscribes for this subaccount in the last 30 days
  72. * - opens integer the number of times emails have been opened for this subaccount in the last 30 days
  73. * - unique_opens integer the number of unique opens for emails sent for this subaccount in the last 30 days
  74. * - clicks integer the number of URLs that have been clicked for this subaccount in the last 30 days
  75. * - unique_clicks integer the number of unique clicks for emails sent for this subaccount in the last 30 days
  76. */
  77. public function info($id) {
  78. $_params = array("id" => $id);
  79. return $this->master->call('subaccounts/info', $_params);
  80. }
  81. /**
  82. * Update an existing subaccount
  83. * @param string $id the unique identifier of the subaccount to update
  84. * @param string $name an optional display name to further identify the subaccount
  85. * @param string $notes optional extra text to associate with the subaccount
  86. * @param integer $custom_quota an optional manual hourly quota for the subaccount. If not specified, Mandrill will manage this based on reputation
  87. * @return struct the information for the updated subaccount
  88. * - id string a unique indentifier for the subaccount
  89. * - name string an optional display name for the subaccount
  90. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  91. * - status string the current sending status of the subaccount, one of "active" or "paused"
  92. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  93. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  94. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  95. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  96. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  97. * - sent_total integer the number of emails the subaccount has sent since it was created
  98. */
  99. public function update($id, $name=null, $notes=null, $custom_quota=null) {
  100. $_params = array("id" => $id, "name" => $name, "notes" => $notes, "custom_quota" => $custom_quota);
  101. return $this->master->call('subaccounts/update', $_params);
  102. }
  103. /**
  104. * Delete an existing subaccount. Any email related to the subaccount will be saved, but stats will be removed and any future sending calls to this subaccount will fail.
  105. * @param string $id the unique identifier of the subaccount to delete
  106. * @return struct the information for the deleted subaccount
  107. * - id string a unique indentifier for the subaccount
  108. * - name string an optional display name for the subaccount
  109. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  110. * - status string the current sending status of the subaccount, one of "active" or "paused"
  111. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  112. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  113. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  114. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  115. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  116. * - sent_total integer the number of emails the subaccount has sent since it was created
  117. */
  118. public function delete($id) {
  119. $_params = array("id" => $id);
  120. return $this->master->call('subaccounts/delete', $_params);
  121. }
  122. /**
  123. * Pause a subaccount's sending. Any future emails delivered to this subaccount will be queued for a maximum of 3 days until the subaccount is resumed.
  124. * @param string $id the unique identifier of the subaccount to pause
  125. * @return struct the information for the paused subaccount
  126. * - id string a unique indentifier for the subaccount
  127. * - name string an optional display name for the subaccount
  128. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  129. * - status string the current sending status of the subaccount, one of "active" or "paused"
  130. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  131. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  132. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  133. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  134. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  135. * - sent_total integer the number of emails the subaccount has sent since it was created
  136. */
  137. public function pause($id) {
  138. $_params = array("id" => $id);
  139. return $this->master->call('subaccounts/pause', $_params);
  140. }
  141. /**
  142. * Resume a paused subaccount's sending
  143. * @param string $id the unique identifier of the subaccount to resume
  144. * @return struct the information for the resumed subaccount
  145. * - id string a unique indentifier for the subaccount
  146. * - name string an optional display name for the subaccount
  147. * - custom_quota integer an optional manual hourly quota for the subaccount. If not specified, the hourly quota will be managed based on reputation
  148. * - status string the current sending status of the subaccount, one of "active" or "paused"
  149. * - reputation integer the subaccount's current reputation on a scale from 0 to 100
  150. * - created_at string the date and time that the subaccount was created as a UTC string in YYYY-MM-DD HH:MM:SS format
  151. * - first_sent_at string the date and time that the subaccount first sent as a UTC string in YYYY-MM-DD HH:MM:SS format
  152. * - sent_weekly integer the number of emails the subaccount has sent so far this week (weeks start on midnight Monday, UTC)
  153. * - sent_monthly integer the number of emails the subaccount has sent so far this month (months start on midnight of the 1st, UTC)
  154. * - sent_total integer the number of emails the subaccount has sent since it was created
  155. */
  156. public function resume($id) {
  157. $_params = array("id" => $id);
  158. return $this->master->call('subaccounts/resume', $_params);
  159. }
  160. }