# File Mandrill/Subaccounts.php

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