csrest_templates.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. require_once dirname(__FILE__).'/class/base_classes.php';
  3. /**
  4. * Class to access a templates resources from the create send API.
  5. * This class includes functions to create update and delete templates
  6. * @author tobyb
  7. *
  8. */
  9. class CS_REST_Templates extends CS_REST_Wrapper_Base {
  10. /**
  11. * The base route of the lists resource.
  12. * @var string
  13. * @access private
  14. */
  15. var $_templates_base_route;
  16. /**
  17. * Constructor.
  18. * @param $list_id string The template id to access (Ignored for create requests)
  19. * @param $auth_details array Authentication details to use for API calls.
  20. * This array must take one of the following forms:
  21. * If using OAuth to authenticate:
  22. * array(
  23. * 'access_token' => 'your access token',
  24. * 'refresh_token' => 'your refresh token')
  25. *
  26. * Or if using an API key:
  27. * array('api_key' => 'your api key')
  28. * @param $protocol string The protocol to use for requests (http|https)
  29. * @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
  30. * @param $host string The host to send API requests to. There is no need to change this
  31. * @param $log CS_REST_Log The logger to use. Used for dependency injection
  32. * @param $serialiser The serialiser to use. Used for dependency injection
  33. * @param $transport The transport to use. Used for dependency injection
  34. * @access public
  35. */
  36. function __construct (
  37. $template_id,
  38. $auth_details,
  39. $protocol = 'https',
  40. $debug_level = CS_REST_LOG_NONE,
  41. $host = 'api.createsend.com',
  42. $log = NULL,
  43. $serialiser = NULL,
  44. $transport = NULL) {
  45. parent::__construct($auth_details, $protocol, $debug_level, $host, $log, $serialiser, $transport);
  46. $this->set_template_id($template_id);
  47. }
  48. /**
  49. * Change the template id used for calls after construction
  50. * @param $template_id
  51. * @access public
  52. */
  53. function set_template_id($template_id) {
  54. $this->_templates_base_route = $this->_base_route.'templates/'.$template_id.'.json';
  55. }
  56. /**
  57. * Creates a new template for the specified client based on the provided data
  58. * @param string $client_id The client to create the template for
  59. * @param array $template_details The details of the template
  60. * This should be an array of the form
  61. * array(
  62. * 'Name' => The name of the template
  63. * 'HtmlPageURL' => The url where the template html can be accessed
  64. * 'ZipFileURL' => The url where the template image zip can be accessed
  65. * )
  66. * @access public
  67. * @return CS_REST_Wrapper_Result A successful response will be the ID of the newly created template
  68. */
  69. function create($client_id, $template_details) {
  70. return $this->post_request($this->_base_route.'templates/'.$client_id.'.json', $template_details);
  71. }
  72. /**
  73. * Updates the current template with the provided code
  74. * @param array $template_details The details of the template
  75. * This should be an array of the form
  76. * array(
  77. * 'Name' => The name of the template
  78. * 'HtmlPageURL' => The url where the template html can be accessed
  79. * 'ZipFileURL' => The url where the template image zip can be accessed
  80. * )
  81. * @access public
  82. * @return CS_REST_Wrapper_Result A successful response will be empty
  83. */
  84. function update($template_details) {
  85. return $this->put_request($this->_templates_base_route, $template_details);
  86. }
  87. /**
  88. * Deletes the current template from the system
  89. * @access public
  90. * @return CS_REST_Wrapper_Result A successful response will be empty
  91. */
  92. function delete() {
  93. return $this->delete_request($this->_templates_base_route);
  94. }
  95. /**
  96. * Gets the basic details of the current template
  97. * @access public
  98. * @return CS_REST_Wrapper_Result A successful response will be an object of the form
  99. * {
  100. * 'TemplateID' => The id of the template
  101. * 'Name' => The name of the template
  102. * 'PreviewURL' => A url where the template can be previewed from
  103. * 'ScreenshotURL' => The url of the template screenshot if one was provided
  104. * }
  105. */
  106. function get() {
  107. return $this->get_request($this->_templates_base_route);
  108. }
  109. }