Giter Site home page Giter Site logo

amazonsns-php-api's Introduction

Amazon SNS PHP API v0.5.1 Documentation

This API wrapper is a lightweight alternative to the official Amazon aws-sdk-for-php for access to Amazon SNS (Simple Notification Service) using PHP

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

To use this wrapper you must be using PHP5 with cURL, and have an Amazon AWS account

Basic Use

Download the latest version: https://github.com/chrisbarr/AmazonSNS-PHP-API/tarball/master

Include the class on your page:

include('lib/amazonsns.class.php');

Create a connection to the API:

$AmazonSNS = new AmazonSNS(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY);

Create a Topic:

$topicArn = $AmazonSNS->createTopic('My New SNS Topic');

Set the Topic's Display Name (required):

$result = $AmazonSNS->setTopicAttributes($topicArn, 'DisplayName', 'My SNS Topic Display Name');

Subscribe to this topic:

$AmazonSNS->subscribe($topicArn, 'email', '[email protected]');

And send a message to subscribers of this topic:

$AmazonSNS->publish($topicArn, 'Hello, world!');

API Methods

Available methods:

  • addPermission($topicArn, $label, $permissions)
  • confirmSubscription($topicArn, $token)
  • createTopic($name)
  • deleteTopic($topicArn)
  • getTopicAttributes($topicArn)
  • listSubscriptions()
  • listSubscriptionsByTopic($topicArn)
  • listTopics()
  • publish($topicArn, $message)
  • removePermission($topicArn, $label)
  • setTopicAttributes($topicArn, $attrName, $attrValue)
  • subscribe($topicArn, $protocol, $endpoint)
  • unsubscribe($subscriptionArn)

To set the API region (US-EAST-1, US-WEST-1, EU-WEST-1, AP-SE-1, AP-NE-1 or SA-EAST-1):

  • setRegion($region)

The default API region is US-EAST-1

Advanced Use

A more complex example demonstrating catching Exceptions:

<?php
include('lib/amazonsns.class.php');
$AmazonSNS = new AmazonSNS(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY);
$AmazonSNS->setRegion('EU-WEST-1');

try
{
	$topics = $AmazonSNS->listTopics();
}
catch(SNSException $e)
{
	// Amazon SNS returned an error
	echo 'SNS returned the error "' . $e->getMessage() . '" and code ' . $e->getCode();
}
catch(APIException $e)
{
	// Problem with the API
	echo 'There was an unknown problem with the API, returned code ' . $e->getCode();
}

amazonsns-php-api's People

Contributors

chrisbarr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.