csrest_people.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. require_once dirname(__FILE__).'/class/base_classes.php';
  3. /**
  4. * Class to access the person resources from the create send API.
  5. * This class includes functions to add and remove people,
  6. * along with getting details for a single person
  7. * @author tobyb
  8. *
  9. */
  10. class CS_REST_People extends CS_REST_Wrapper_Base {
  11. /**
  12. * The base route of the people resource.
  13. * @var string
  14. * @access private
  15. */
  16. var $_people_base_route;
  17. /**
  18. * Constructor.
  19. * @param $client_id string The client id that the people belong to
  20. * @param $auth_details array Authentication details to use for API calls.
  21. * This array must take one of the following forms:
  22. * If using OAuth to authenticate:
  23. * array(
  24. * 'access_token' => 'your access token',
  25. * 'refresh_token' => 'your refresh token')
  26. *
  27. * Or if using an API key:
  28. * array('api_key' => 'your api key')
  29. * @param $protocol string The protocol to use for requests (http|https)
  30. * @param $debug_level int The level of debugging required CS_REST_LOG_NONE | CS_REST_LOG_ERROR | CS_REST_LOG_WARNING | CS_REST_LOG_VERBOSE
  31. * @param $host string The host to send API requests to. There is no need to change this
  32. * @param $log CS_REST_Log The logger to use. Used for dependency injection
  33. * @param $serialiser The serialiser to use. Used for dependency injection
  34. * @param $transport The transport to use. Used for dependency injection
  35. * @access public
  36. */
  37. function __construct (
  38. $client_id,
  39. $auth_details,
  40. $protocol = 'https',
  41. $debug_level = CS_REST_LOG_NONE,
  42. $host = 'api.createsend.com',
  43. $log = NULL,
  44. $serialiser = NULL,
  45. $transport = NULL) {
  46. parent::__construct($auth_details, $protocol, $debug_level, $host, $log, $serialiser, $transport);
  47. $this->set_client_id($client_id);
  48. }
  49. /**
  50. * Change the client id used for calls after construction
  51. * @param $client_id
  52. * @access public
  53. */
  54. function set_client_id($client_id) {
  55. $this->_people_base_route = $this->_base_route.'clients/'.$client_id . '/people';
  56. }
  57. /**
  58. * Adds a new person to the specified client
  59. * @param array $person The person details to use during creation.
  60. * This array should be of the form
  61. * array (
  62. * 'EmailAddress' => The new person email address
  63. * 'Name' => The name of the new person
  64. * 'AccessLevel' => The access level of the new person. See http://www.campaignmonitor.com/api/clients/#setting_access_details for details
  65. * 'Password' => (optional) if not specified, an invitation will be sent to the person by email
  66. * )
  67. * @access public
  68. * @return CS_REST_Wrapper_Result A successful response will be empty
  69. */
  70. function add($person) {
  71. return $this->post_request($this->_people_base_route.'.json', $person);
  72. }
  73. /**
  74. * Updates details for an existing person associated with the specified client.
  75. * @param string $email The email address of the person to be updated
  76. * @param array $person The updated person details to use for the update.
  77. * This array should be of the form
  78. * array (
  79. * 'EmailAddress' => The new email address
  80. * 'Name' => The name of the person
  81. * 'AccessLevel' => the access level of the person
  82. * 'Password' => (optional) if specified, changes the password to the specified value
  83. * )
  84. * @access public
  85. * @return CS_REST_Wrapper_Result A successful response will be empty
  86. */
  87. function update($email, $person) {
  88. return $this->put_request($this->_people_base_route.'.json?email='.urlencode($email), $person);
  89. }
  90. /**
  91. * Gets the details for a specific person
  92. * @access public
  93. * @return CS_REST_Wrapper_Result A successful response will be an object of the form
  94. * {
  95. * 'EmailAddress' => The email address of the person
  96. * 'Name' => The name of the person
  97. * 'Status' => The status of the person
  98. * 'AccessLevel' => The access level of the person
  99. * )
  100. * }
  101. */
  102. function get($email) {
  103. return $this->get_request($this->_people_base_route.'.json?email='.urlencode($email));
  104. }
  105. /**
  106. * deletes the given person from the current client
  107. * @param string $email The email address of the person to delete
  108. * @access public
  109. * @return CS_REST_Wrapper_Result A successful response will be empty
  110. */
  111. function delete($email) {
  112. return $this->delete_request($this->_people_base_route.'.json?email='.urlencode($email));
  113. }
  114. }