Skip to content

Commit 18d1904

Browse files
committed
Add composer support, update readme and minor tweaks - tag 1.0.0
1 parent ef8773a commit 18d1904

File tree

4 files changed

+87
-55
lines changed

4 files changed

+87
-55
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.tmp*
22
.DS_Store*
3+
.idea/
4+
vendor/

README.md

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
1-
# Amazon SNS PHP API v0.5.1 Documentation #
1+
# Amazon SNS PHP API v1.0.0 Documentation
2+
23
This API wrapper is a lightweight alternative to the official [Amazon aws-sdk-for-php](http://aws.amazon.com/sdkforphp) for access to Amazon SNS (Simple Notification Service) using PHP
34

45
Find out more about Amazon SNS here - http://aws.amazon.com/sns
56

67
To use this wrapper you must be using PHP5 with cURL, and have an [Amazon AWS account](http://aws.amazon.com)
78

8-
## Basic Use ##
9-
Download the latest version: https://github.com/chrisbarr/AmazonSNS-PHP-API/tarball/master
10-
11-
Include the class on your page:
12-
13-
include('lib/amazonsns.class.php');
14-
15-
Create a connection to the API:
9+
## Basic Use
10+
Install using [Composer](https://getcomposer.org/) on the command line:
11+
```
12+
$ composer require chrisbarr/amazon-sns-php-api
13+
```
1614

17-
$AmazonSNS = new AmazonSNS(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY);
15+
Or add it to your composer.json file:
1816

19-
Create a Topic:
17+
```
18+
{
19+
...
20+
"require": {
21+
"chrisbarr/amazon-sns-php-api": "~1.0"
22+
}
23+
}
24+
```
2025

21-
$topicArn = $AmazonSNS->createTopic('My New SNS Topic');
26+
Example usage:
2227

23-
Set the Topic's Display Name (required):
28+
```php
29+
<?php
30+
require 'vendor/autoload.php';
2431

25-
$result = $AmazonSNS->setTopicAttributes($topicArn, 'DisplayName', 'My SNS Topic Display Name');
32+
// Create an instance
33+
$AmazonSNS = new AmazonSNS(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY);
2634

27-
Subscribe to this topic:
35+
// Create a Topic
36+
$topicArn = $AmazonSNS->createTopic('My New SNS Topic');
2837

29-
$AmazonSNS->subscribe($topicArn, 'email', 'example@github.com');
38+
// Set the Topic's Display Name (required)
39+
$AmazonSNS->setTopicAttributes($topicArn, 'DisplayName', 'My SNS Topic Display Name');
3040

31-
And send a message to subscribers of this topic:
41+
// Subscribe to this topic
42+
$AmazonSNS->subscribe($topicArn, 'email', 'example@github.com');
3243

33-
$AmazonSNS->publish($topicArn, 'Hello, world!');
44+
// And send a message to subscribers of this topic
45+
$AmazonSNS->publish($topicArn, 'Hello, world!');
46+
```
3447

35-
## API Methods ##
48+
## API Methods
3649
Available methods:
3750

3851
* `addPermission($topicArn, $label, $permissions)`
@@ -55,25 +68,25 @@ To set the API region (US-EAST-1, US-WEST-1, EU-WEST-1, AP-SE-1, AP-NE-1 or SA-E
5568

5669
*The default API region is US-EAST-1*
5770

58-
## Advanced Use ##
59-
A more complex example demonstrating catching Exceptions:
60-
61-
<?php
62-
include('lib/amazonsns.class.php');
63-
$AmazonSNS = new AmazonSNS(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY);
64-
$AmazonSNS->setRegion('EU-WEST-1');
65-
66-
try
67-
{
68-
$topics = $AmazonSNS->listTopics();
69-
}
70-
catch(SNSException $e)
71-
{
72-
// Amazon SNS returned an error
73-
echo 'SNS returned the error "' . $e->getMessage() . '" and code ' . $e->getCode();
74-
}
75-
catch(APIException $e)
76-
{
77-
// Problem with the API
78-
echo 'There was an unknown problem with the API, returned code ' . $e->getCode();
79-
}
71+
## Further Example
72+
Make sure to catch Exceptions where necessary:
73+
74+
```php
75+
<?php
76+
require 'vendor/autoload.php';
77+
78+
$AmazonSNS = new AmazonSNS(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY);
79+
$AmazonSNS->setRegion('EU-WEST-1');
80+
81+
try {
82+
$topics = $AmazonSNS->listTopics();
83+
}
84+
catch(SNSException $e) {
85+
// Amazon SNS returned an error
86+
echo 'SNS returned the error "' . $e->getMessage() . '" and code ' . $e->getCode();
87+
}
88+
catch(APIException $e) {
89+
// Problem with the API
90+
echo 'There was an unknown problem with the API, returned code ' . $e->getCode();
91+
}
92+
```

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "chrisbarr/amazon-sns-php-api",
3+
"type": "library",
4+
"description": "Amazon SNS PHP API",
5+
"homepage": "https://github.com/chrisbarr/AmazonSNS-PHP-API",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Chris Barr",
10+
"email": "chris.barr@ntlworld.com"
11+
}
12+
],
13+
"require": {
14+
"php": ">=5.2"
15+
},
16+
"autoload": {
17+
"psr-0": {
18+
"AmazonSNS": "lib/"
19+
}
20+
}
21+
}
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
/**
44
* Lightweight API interface with the Amazon Simple Notification Service
55
*
6-
* @author Chris Barr
6+
* @author Chris Barr <chris.barr@ntlworld.com>
77
* @link http://aws.amazon.com/sns/
88
* @link http://docs.amazonwebservices.com/sns/latest/api/
9-
* @version 0.5.1
109
*/
1110
class AmazonSNS {
1211
/** @var string $access_key */
13-
private $access_key = '';
12+
private $access_key;
1413
/** @var string $secret_key */
15-
private $secret_key = '';
14+
private $secret_key;
1615

1716
/** @var string $protocol */
1817
private $protocol = 'https://'; // http is allowed
@@ -33,23 +32,20 @@ class AmazonSNS {
3332
/**
3433
* Instantiate the object - set access_key and secret_key and set default region
3534
*
36-
* @param string|null $access_key [optional]
37-
* @param string|null $secret_key [optional]
35+
* @param string $access_key
36+
* @param string $secret_key
37+
* @param string $region [optional]
3838
* @throws InvalidArgumentException
3939
*/
40-
public function __construct($access_key = null, $secret_key = null) {
41-
if(!is_null($access_key)) {
42-
$this->access_key = $access_key;
43-
}
44-
if(!is_null($secret_key)) {
45-
$this->secret_key = $secret_key;
46-
}
40+
public function __construct($access_key, $secret_key, $region = 'US-EAST-1') {
41+
$this->access_key = $access_key;
42+
$this->secret_key = $secret_key;
4743

4844
if(empty($this->access_key) || empty($this->secret_key)) {
4945
throw new InvalidArgumentException('Must define Amazon access key and secret key');
5046
}
5147

52-
$this->setRegion('US-EAST-1');
48+
$this->setRegion($region);
5349
}
5450

5551
/**

0 commit comments

Comments
 (0)