Skip to content

Commit

Permalink
Merge pull request #2 from enricodias/dev
Browse files Browse the repository at this point in the history
Adds first documentation
  • Loading branch information
enricodias authored Jan 19, 2020
2 parents 53eea85 + c15ef9f commit d32d41b
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 5 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Contributing

👍 First off, thanks for taking the time to contribute! 👍

When contributing to this project, please first discuss the change you wish to make in an [Issue](https://github.com/enricodias/smsdev-php/issues/new).

## Coding conventions

- Use the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style.
- Follow the PHPMD and PHPCS rules when possible.
- Include DocBlocks in new methods, classes and properties.
- Create the appropriate tests for any new feature.
- Update the README.md explaining new or modified features.
- Follow the SOLID principles.

Please note, if your changes are purely to things like README, CHANGELOG etc, you can add ```[skip ci]``` as the last line of your commit message and your PR won't be run through our continuous integration systems. We ask that you use ```[skip ci]``` where appropriate as it helps to get changes through CI faster and doesn't waste resources kindly donated to the Open Source community.

## Guidelines for merging

- Issue 1 Pull Request per feature. Don't lump unrelated changes together.
- Use the present tense ("Add feature" not "Added feature").
- Use the imperative mood ("Change string to..." not "Changes string to...").
- Limit the first line to 72 characters or less.
- Reference issues and pull requests liberally after the first line.
122 changes: 121 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,122 @@
# smsdev-php
A PHP library that wraps the smsdev.com.br API

[![Build Status](https://travis-ci.com/enricodias/smsdev-php.svg?branch=master)](https://travis-ci.com/enricodias/smsdev-php)
[![Code Coverage](https://scrutinizer-ci.com/g/enricodias/smsdev-php/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/enricodias/smsdev-php/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/enricodias/smsdev-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/enricodias/smsdev-php/?branch=master)
[![Latest version](http://img.shields.io/packagist/v/enricodias/smsdev.svg)](https://packagist.org/packages/enricodias/smsdev)
[![Downloads total](http://img.shields.io/packagist/dt/enricodias/smsdev.svg)](https://packagist.org/packages/enricodias/smsdev)
[![License](http://img.shields.io/packagist/l/enricodias/smsdev.svg)](https://github.com/enricodias/smsdev-php/blob/master/LICENSE.md)

Send and receive SMS using [SmsDev.com.br](https://www.smsdev.com.br)

## Installation

Require this package with Composer in the root directory of your project.

```bash
composer require enricodias/smsdev-php
```

## Usage

Create a new instance with your API key:

```php
$SmsDev = new \enricodias\SmsDev('API_KEY');
```

Set any date format to be used in all date methods:

```php
$SmsDev->setDateFormat('Y-m-d H:i:s'); // default is 'U', timestamp
```

### Sending an SMS message

```php
$SmsDev->send(5511988881111, 'SMS Message'); // returns true if the API accepts the message

var_dump($SmsDev->getResult()); // Returns the raw API response.
```

The country code optional. The default is 55 (Brazil).

### Receiving SMS messages

Get unread messages in a specific date interval:

```php
$SmsDev->setFilter()
->isUnread()
->dateBetween('2018-01-19', '2019-01-19')
->fetch();
```

Search for a specific message id:

```php
$SmsDev->setFilter()
->byId(2515974)
->fetch();
```

### Parsing the response

After fetching the messages you can either access the raw API response using ```getResult()``` or use the function ```parsedMessages()``` to get a simplified array:

```php
$SmsDev->setDateFormat('U'); // timestamp

$messages = $SmsDev->parsedMessages();

var_dump($messages);

/*
array(1) {
['date'] => '1529418914'
['number'] => '5511988887777'
['message'] => 'Message'
}
*/
```

Dates are converted to the format specified in ```setDateFormat()```.

### Date filters

The following filters are equivalent:

```php
$SmsDev->setFilter()
->dateBetween('2018-01-19', '2019-01-19')
->fetch();

$SmsDev->setFilter()
->dateBetween('2018-01-19', '')
->dateTo('2019-01-19')
->fetch();

$SmsDev->setFilter()
->dateBetween('', '2019-01-19')
->dateFrom('2018-01-19')
->fetch();

$SmsDev->setFilter()
->dateFrom('2018-01-19')
->dateTo('2019-01-19')
->fetch();
```

## Timezone problems

The API uses the timezone America/Sao_Paulo. Using another timezone in your application will force you to convert dates locally in order to get correct values.

> Ex: if you are using UTC-4 and receive a new message, it will look like the message came from the future because America/Sao_Paulo is UTC-3.
This class solves this problem by automatically correcting dates both in search filters and in parsed messages. Only the dates in raw API responses are not converted.

## TODO

- Verify phone number locally.
- Check the status of sent messages.
- Send multiple SMS messages.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enricodias/smsdev",
"type": "library",
"license": "MIT",
"description": "A wrapper to the SmsDev.com.br API.",
"description": "Send and receive SMS using SmsDev.com.br",
"keywords": ["smsdev", "sms"],
"authors": [
{
Expand Down
Loading

0 comments on commit d32d41b

Please sign in to comment.