-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclass.amazon_sns_topic.php
73 lines (62 loc) · 1.75 KB
/
class.amazon_sns_topic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/*
* Amazon SNS Topic
*
* Allows creating of new topics, deleting, setting the display name and publishing to existing topics
*
* @author Russell Smith <[email protected]>
*/
class amazon_sns_topic {
private $TopicArn;
/*
* Create a new topic object
*
* param string the topicarn you got previously after creating a new topic
*/
public function __construct ($TopicArn = null) {
if (!is_null($TopicArn)) {
$this->TopicArn = $TopicArn;
}
}
/*
* Publish a message to this topic
*
* @param string subject of the message (for emails)
* @param string message body
*/
public function publish ($subject, $message) {
$response = amazon_sns_helper::request(array('Subject'=>$subject, 'Message'=>$message, 'TopicArn'=>$this->TopicArn, 'Action'=>'Publish'));
}
/*
* Set the display name for this topic
*
* @param string the human readable display name
*/
public function setDisplayName ($DisplayName) {
$response = amazon_sns_helper::request(array('Action'=>'SetTopicAttributes', 'TopicArn'=>$this->TopicArn, 'AttributeName'=>'DisplayName', 'AttributeValue'=>$DisplayName));
}
/*
* Return the arn for the current topic
*
* @return string
*/
public function getArn () {
return $this->TopicArn;
}
/*
* Ask amazon to delete the current topic
*/
public function delete () {
$response = amazon_sns_helper::request(array('Action'=>'DeleteTopic', 'TopicArn'=>$this->TopicArn));
}
/**
* Create a new topic with this name
*
* @param string topic name
* @return amazon_sns_topic
*/
public static function create ($name) {
$response = amazon_sns_helper::request(array('Action'=>'CreateTopic', 'Name'=>$name));
return new amazon_sns_topic($response->CreateTopicResult->TopicArn);
}
}