Wallogit.com
2017 © Pedro Peláez
This library provides an easy way to interact with the Rungopher SimpleSms API
, (*1)
This library provides an easy way to interact with the Rungopher SimpleSms API., (*2)
Distributed via packagist. The suggested installation method is via composer:, (*3)
``` shell composer require "rungopher/simplesms:~1.0.0", (*4)
## Usage ### Sending an SMS: *Note: This example uses cURL which requires the [cURL PHP Extension](http://php.net/manual/en/book.curl.php). To use a custom requester see* ***Using a Custom Requester*** *below.* ``` php use Rungopher\SimpleSms\CurlRequester; use Rungopher\SimpleSms\SimpleSmsClient; $requester = new CurlRequester(); $client = new SimpleSmsClient($requester, "username", "password", "from"); try { $response = $client->sendSms("to", "message"); } catch(SimpleSmsErrorException $e) { log($e->getMessage()); }
Error: SimpleSmsErrorException is thrown containing the error message., (*5)
Success: $client->sendSms() returns an instance of SimpleSmsOutbound which has the following methods:, (*6)
| Method | Response Field |
|---|---|
| getFrom() | from |
| getTo() | to |
| getBody() | body |
| getMessageSid() | sid |
| getStatus() | status |
``` php use Rungopher\SimpleSms\Messages\SimpleSmsDeliveryReceipt;, (*7)
$deliveryReceipt = SimpleSmsDeliveryReceipt::fromRequestBody($requestBody);, (*8)
**SimpleSmsDeliveryReceipt:** | Method | Response Field | | --------------- | -------------- | | getMessageSid() | MessageSid | | getStatus() | Status | | wasDelivered() | NA | | failed() | NA | ### Receiving an Inbound SMS: ``` php use Rungopher\SimpleSms\Messages\SimpleSmsInbound; $inboundSms = SimpleSmsInbound::fromRequestBody($requestBody);
SimpleSmsInbound:, (*9)
| Method | Response Field |
|---|---|
| getFrom() | From |
| getTo() | To |
| getBody() | Body |
| getMessageSid() | MessageSid |
A custom requester must implement RequesterInterface:, (*10)
``` php /** returns: SimpleSmsResponse */ public function newRequest(SimpleSmsRequest $request);, (*11)
**SimpleSmsRequest:** | Method | Returns | | --------------- | --------------------- | | getBody() | The request body. | | getUrl() | The request url. | | getPort() | The request port. | | getUsername() | The request username. | | getPassword() | The request password. | **SimpleSmsResponse:** | Property | Description | | ----------------- | ----------------------------- | | statusCode | The request http status code. | | response | The request response body. | ``` php return new SimpleSmsResponse($statusCode, $response);