AmazonSNS

The W3 Total Cache AmazonSNS class.

Defined (1)

The class is defined in the following location(s).

/lib/SNS/services/sns.class.php  
  1. class AmazonSNS extends CFRuntime 
  2.  
  3. /**%******************************************************************************************%*/ 
  4. // CLASS CONSTANTS 
  5.  
  6. /** 
  7. * Specify the default queue URL. 
  8. */ 
  9. const DEFAULT_URL = 'sns.us-east-1.amazonaws.com'; 
  10.  
  11. /** 
  12. * Specify the queue URL for the US-East (Northern Virginia) Region. 
  13. */ 
  14. const REGION_US_E1 = self::DEFAULT_URL; 
  15.  
  16. /** 
  17. * Specify the queue URL for the US-West (Northern California) Region. 
  18. */ 
  19. const REGION_US_W1 = 'sns.us-west-1.amazonaws.com'; 
  20.  
  21. /** 
  22. * Specify the queue URL for the EU (Ireland) Region. 
  23. */ 
  24. const REGION_EU_W1 = 'sns.eu-west-1.amazonaws.com'; 
  25.  
  26. /** 
  27. * Specify the queue URL for the Asia Pacific (Singapore) Region. 
  28. */ 
  29. const REGION_APAC_SE1 = 'sns.ap-southeast-1.amazonaws.com'; 
  30.  
  31. /** 
  32. * Specify the queue URL for the Asia Pacific (Japan) Region. 
  33. */ 
  34. const REGION_APAC_NE1 = 'sns.ap-northeast-1.amazonaws.com'; 
  35.  
  36.  
  37. /**%******************************************************************************************%*/ 
  38. // SETTERS 
  39.  
  40. /** 
  41. * This allows you to explicitly sets the region for the service to use. 
  42. * @param string $region (Required) The region to use for subsequent Amazon S3 operations. [Allowed values: `AmazonSNS::REGION_US_E1 `, `AmazonSNS::REGION_US_W1`, `AmazonSNS::REGION_EU_W1`, `AmazonSNS::REGION_APAC_SE1`] 
  43. * @return $this A reference to the current instance. 
  44. */ 
  45. public function set_region($region) 
  46. $this->set_hostname($region); 
  47. return $this; 
  48.  
  49.  
  50. /**%******************************************************************************************%*/ 
  51. // CONVENIENCE METHODS 
  52.  
  53. /** 
  54. * Gets a simple list of Topic ARNs. 
  55. * @param string $pcre (Optional) A Perl-Compatible Regular Expression (PCRE) to filter the names against. 
  56. * @return array A list of Topic ARNs. 
  57. * @link http://php.net/pcre Perl-Compatible Regular Expression (PCRE) Docs 
  58. */ 
  59. public function get_topic_list($pcre = null) 
  60. if ($this->use_batch_flow) 
  61. throw new SNS_Exception(__FUNCTION__ . '() cannot be batch requested'); 
  62.  
  63. // Get a list of topics. 
  64. $list = $this->list_topics(); 
  65. if ($list = $list->body->TopicArn()) 
  66. $list = $list->map_string($pcre); 
  67. return $list; 
  68.  
  69. return array(); 
  70.  
  71.  
  72. /**%******************************************************************************************%*/ 
  73. // CONSTRUCTOR 
  74.  
  75. /** 
  76. * Constructs a new instance of <AmazonSNS>. If the <code>AWS_DEFAULT_CACHE_CONFIG</code> configuration 
  77. * option is set, requests will be authenticated using a session token. Otherwise, requests will use 
  78. * the older authentication method. 
  79. * @param string $key (Optional) Your AWS key, or a session key. If blank, it will look for the <code>AWS_KEY</code> constant. 
  80. * @param string $secret_key (Optional) Your AWS secret key, or a session secret key. If blank, it will look for the <code>AWS_SECRET_KEY</code> constant. 
  81. * @param string $token (optional) An AWS session token. If blank, a request will be made to the AWS Secure Token Service to fetch a set of session credentials. 
  82. * @return boolean A value of <code>false</code> if no valid values are set, otherwise <code>true</code>. 
  83. */ 
  84. public function __construct($key = null, $secret_key = null, $token = null) 
  85. $this->api_version = '2010-03-31'; 
  86. $this->hostname = self::DEFAULT_URL; 
  87.  
  88. if (!$key && !defined('AWS_KEY')) 
  89. // @codeCoverageIgnoreStart 
  90. throw new SNS_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.'); 
  91. // @codeCoverageIgnoreEnd 
  92.  
  93. if (!$secret_key && !defined('AWS_SECRET_KEY')) 
  94. // @codeCoverageIgnoreStart 
  95. throw new SNS_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.'); 
  96. // @codeCoverageIgnoreEnd 
  97.  
  98. if (defined('AWS_DEFAULT_CACHE_CONFIG') && AWS_DEFAULT_CACHE_CONFIG) 
  99. return parent::session_based_auth($key, $secret_key, $token); 
  100.  
  101. return parent::__construct($key, $secret_key); 
  102.  
  103.  
  104. /**%******************************************************************************************%*/ 
  105. // SERVICE METHODS 
  106.  
  107. /** 
  108. * The ConfirmSubscription action verifies an endpoint owner's intent to receive messages by validating the token sent to the endpoint by an 
  109. * earlier Subscribe action. If the token is valid, the action creates a new subscription and returns its Amazon Resource Name (ARN). This call 
  110. * requires an AWS signature only when the AuthenticateOnUnsubscribe flag is set to "true". 
  111. * @param string $topic_arn (Required) The ARN of the topic for which you wish to confirm a subscription. 
  112. * @param string $token (Required) Short-lived token sent to an endpoint during the Subscribe action. 
  113. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  114. * <li><code>AuthenticateOnUnsubscribe</code> - <code>string</code> - Optional - Indicates that you want to disable unauthenticated unsubsciption of the subscription. If parameter is present in the request, the request has an AWS signature, and the value of this parameter is true, only the topic owner and the subscription owner will be permitted to unsubscribe the endopint, and the Unsubscribe action will require AWS authentication. </li> 
  115. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  116. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  117. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  118. */ 
  119. public function confirm_subscription($topic_arn, $token, $opt = null) 
  120. if (!$opt) $opt = array(); 
  121. $opt['TopicArn'] = $topic_arn; 
  122. $opt['Token'] = $token; 
  123.  
  124. return $this->authenticate('ConfirmSubscription', $opt, $this->hostname); 
  125.  
  126. /** 
  127. * The GetTopicAttribtues action returns all of the properties of a topic customers have created. Topic properties returned might differ based 
  128. * on the authorization of the user. 
  129. * @param string $topic_arn (Required) The ARN of the topic whose properties you want to get. 
  130. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  131. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  132. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  133. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  134. */ 
  135. public function get_topic_attributes($topic_arn, $opt = null) 
  136. if (!$opt) $opt = array(); 
  137. $opt['TopicArn'] = $topic_arn; 
  138.  
  139. return $this->authenticate('GetTopicAttributes', $opt, $this->hostname); 
  140.  
  141. /** 
  142. * The Subscribe action prepares to subscribe an endpoint by sending the endpoint a confirmation message. To actually create a subscription,  
  143. * the endpoint owner must call the ConfirmSubscription action with the token from the confirmation message. Confirmation tokens are valid for 
  144. * twenty-four hours. 
  145. * @param string $topic_arn (Required) The ARN of topic you want to subscribe to. 
  146. * @param string $protocol (Required) The protocol you want to use. Supported protocols include: <ul> <li>http -- delivery of JSON-encoded message via HTTP POST</li><li>https -- delivery of JSON-encoded message via HTTPS POST</li><li>email -- delivery of message via SMTP</li><li>email-json -- delivery of JSON-encoded message via SMTP</li><li>sqs -- delivery of JSON-encoded message to an Amazon SQS queue</li> </ul> 
  147. * @param string $endpoint (Required) The endpoint that you want to receive notifications. Endpoints vary by protocol: <ul> <li>For the http protocol, the endpoint is an URL beginning with "http://"</li><li>For the https protocol, the endpoint is a URL beginning with "https://"</li><li>For the email protocol, the endpoint is an e-mail address</li><li>For the email-json protocol, the endpoint is an e-mail address</li><li>For the sqs protocol, the endpoint is the ARN of an Amazon SQS queue</li> </ul> 
  148. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  149. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  150. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  151. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  152. */ 
  153. public function subscribe($topic_arn, $protocol, $endpoint, $opt = null) 
  154. if (!$opt) $opt = array(); 
  155. $opt['TopicArn'] = $topic_arn; 
  156. $opt['Protocol'] = $protocol; 
  157. $opt['Endpoint'] = $endpoint; 
  158.  
  159. return $this->authenticate('Subscribe', $opt, $this->hostname); 
  160.  
  161. /** 
  162. * The SetTopicAttributes action allows a topic owner to set an attribute of the topic to a new value. 
  163. * @param string $topic_arn (Required) The ARN of the topic to modify. 
  164. * @param string $attribute_name (Required) The name of the attribute you want to set. Only a subset of the topic's attributes are mutable. 
  165. * @param string $attribute_value (Required) The new value for the attribute. 
  166. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  167. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  168. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  169. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  170. */ 
  171. public function set_topic_attributes($topic_arn, $attribute_name, $attribute_value, $opt = null) 
  172. if (!$opt) $opt = array(); 
  173. $opt['TopicArn'] = $topic_arn; 
  174. $opt['AttributeName'] = $attribute_name; 
  175. $opt['AttributeValue'] = $attribute_value; 
  176.  
  177. return $this->authenticate('SetTopicAttributes', $opt, $this->hostname); 
  178.  
  179. /** 
  180. * The DeleteTopic action deletes a topic and all its subscriptions. Deleting a topic might prevent some messages previously sent to the topic 
  181. * from being delivered to subscribers. This action is idempotent, so deleting a topic that does not exist will not result in an error. 
  182. * @param string $topic_arn (Required) The ARN of the topic you want to delete. 
  183. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  184. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  185. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  186. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  187. */ 
  188. public function delete_topic($topic_arn, $opt = null) 
  189. if (!$opt) $opt = array(); 
  190. $opt['TopicArn'] = $topic_arn; 
  191.  
  192. return $this->authenticate('DeleteTopic', $opt, $this->hostname); 
  193.  
  194. /** 
  195. * The RemovePermission action removes a statement from a topic's access control policy. 
  196. * @param string $topic_arn (Required) The ARN of the topic whose access control policy you wish to modify. 
  197. * @param string $label (Required) The unique label of the statement you want to remove. 
  198. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  199. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  200. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  201. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  202. */ 
  203. public function remove_permission($topic_arn, $label, $opt = null) 
  204. if (!$opt) $opt = array(); 
  205. $opt['TopicArn'] = $topic_arn; 
  206. $opt['Label'] = $label; 
  207.  
  208. return $this->authenticate('RemovePermission', $opt, $this->hostname); 
  209.  
  210. /** 
  211. * The ListSubscriptions action returns a list of the requester's subscriptions. Each call returns a limited list of subscriptions. If there 
  212. * are more subscriptions, a NextToken is also returned. Use the NextToken parameter in a new ListSubscriptions call to get further results. 
  213. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  214. * <li><code>NextToken</code> - <code>string</code> - Optional - Token returned by the previous ListSubscriptions request. </li> 
  215. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  216. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  217. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  218. */ 
  219. public function list_subscriptions($opt = null) 
  220. if (!$opt) $opt = array(); 
  221.  
  222. return $this->authenticate('ListSubscriptions', $opt, $this->hostname); 
  223.  
  224. /** 
  225. * The AddPermission action adds a statement to a topic's access control policy, granting access for the specified AWS accounts to the 
  226. * specified actions. 
  227. * @param string $topic_arn (Required) The ARN of the topic whose access control policy you wish to modify. 
  228. * @param string $label (Required) A unique identifier for the new policy statement. 
  229. * @param string|array $account_id (Required) The AWS account IDs of the users (principals) who will be given access to the specified actions. The users must have AWS accounts, but do not need to be signed up for this service. Pass a string for a single value, or an indexed array for multiple values. 
  230. * @param string|array $action_name (Required) The action you want to allow for the specified principal(s). Pass a string for a single value, or an indexed array for multiple values. 
  231. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  232. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  233. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  234. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  235. */ 
  236. public function add_permission($topic_arn, $label, $account_id, $action_name, $opt = null) 
  237. if (!$opt) $opt = array(); 
  238. $opt['TopicArn'] = $topic_arn; 
  239. $opt['Label'] = $label; 
  240.  
  241. // Required parameter 
  242. $opt = array_merge($opt, CFComplexType::map(array( 
  243. 'AWSAccountId' => (is_array($account_id) ? $account_id : array($account_id)) 
  244. ), 'member')); 
  245.  
  246. // Required parameter 
  247. $opt = array_merge($opt, CFComplexType::map(array( 
  248. 'ActionName' => (is_array($action_name) ? $action_name : array($action_name)) 
  249. ), 'member')); 
  250.  
  251. return $this->authenticate('AddPermission', $opt, $this->hostname); 
  252.  
  253. /** 
  254. * The CreateTopic action creates a topic to which notifications can be published. Users can create at most 25 topics. This action is 
  255. * idempotent, so if the requester already owns a topic with the specified name, that topic's ARN will be returned without creating a new 
  256. * topic. 
  257. * @param string $name (Required) The name of the topic you want to create. Constraints: Topic names must be made up of only uppercase and lowercase ASCII letters, numbers, and hyphens, and must be between 1 and 256 characters long. 
  258. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  259. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  260. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  261. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  262. */ 
  263. public function create_topic($name, $opt = null) 
  264. if (!$opt) $opt = array(); 
  265. $opt['Name'] = $name; 
  266.  
  267. return $this->authenticate('CreateTopic', $opt, $this->hostname); 
  268.  
  269. /** 
  270. * The ListTopics action returns a list of the requester's topics. Each call returns a limited list of topics. If there are more topics, a 
  271. * NextToken is also returned. Use the NextToken parameter in a new ListTopics call to get further results. 
  272. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  273. * <li><code>NextToken</code> - <code>string</code> - Optional - Token returned by the previous ListTopics request. </li> 
  274. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  275. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  276. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  277. */ 
  278. public function list_topics($opt = null) 
  279. if (!$opt) $opt = array(); 
  280.  
  281. return $this->authenticate('ListTopics', $opt, $this->hostname); 
  282.  
  283. /** 
  284. * The Unsubscribe action deletes a subscription. If the subscription requires authentication for deletion, only the owner of the subscription 
  285. * or the its topic's owner can unsubscribe, and an AWS signature is required. If the Unsubscribe call does not require authentication and the 
  286. * requester is not the subscription owner, a final cancellation message is delivered to the endpoint, so that the endpoint owner can easily 
  287. * resubscribe to the topic if the Unsubscribe request was unintended. 
  288. * @param string $subscription_arn (Required) The ARN of the subscription to be deleted. 
  289. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  290. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  291. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  292. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  293. */ 
  294. public function unsubscribe($subscription_arn, $opt = null) 
  295. if (!$opt) $opt = array(); 
  296. $opt['SubscriptionArn'] = $subscription_arn; 
  297.  
  298. return $this->authenticate('Unsubscribe', $opt, $this->hostname); 
  299.  
  300. /** 
  301. * The ListSubscriptionsByTopic action returns a list of the subscriptions to a specific topic. Each call returns a limited list of 
  302. * subscriptions. If there are more subscriptions, a NextToken is also returned. Use the NextToken parameter in a new ListSubscriptionsByTopic 
  303. * call to get further results. 
  304. * @param string $topic_arn (Required) The ARN of the topic for which you wish to find subscriptions. 
  305. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  306. * <li><code>NextToken</code> - <code>string</code> - Optional - Token returned by the previous ListSubscriptionsByTopic request. </li> 
  307. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  308. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  309. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  310. */ 
  311. public function list_subscriptions_by_topic($topic_arn, $opt = null) 
  312. if (!$opt) $opt = array(); 
  313. $opt['TopicArn'] = $topic_arn; 
  314.  
  315. return $this->authenticate('ListSubscriptionsByTopic', $opt, $this->hostname); 
  316.  
  317. /** 
  318. * The Publish action sends a message to all of a topic's subscribed endpoints. When a messageId is returned, the message has been saved and 
  319. * Amazon SNS will attempt to deliver it to the topic's subscribers shortly. The format of the outgoing message to each subscribed endpoint 
  320. * depends on the notification protocol selected. 
  321. * @param string $topic_arn (Required) The topic you want to publish to. 
  322. * @param string $message (Required) The message you want to send to the topic. Constraints: Messages must be UTF-8 encoded strings at most 8 KB in size (8192 bytes, not 8192 characters). 
  323. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul> 
  324. * <li><code>Subject</code> - <code>string</code> - Optional - Optional parameter to be used as the "Subject" line of when the message is delivered to e-mail endpoints. This field will also be included, if present, in the standard JSON messages delivered to other endpoints. Constraints: Subjects must be ASCII text that begins with a letter, number or punctuation mark; must not include line breaks or control characters; and must be less than 100 characters long. </li> 
  325. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li> 
  326. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul> 
  327. * @return CFResponse A <CFResponse> object containing a parsed HTTP response. 
  328. */ 
  329. public function publish($topic_arn, $message, $opt = null) 
  330. if (!$opt) $opt = array(); 
  331. $opt['TopicArn'] = $topic_arn; 
  332. $opt['Message'] = $message; 
  333.  
  334. return $this->authenticate('Publish', $opt, $this->hostname);