2017 © Pedro Peláez
 

library sms-assistant-php

PHP library for using sms-assistent.by HTTP API

image

by-zer0/sms-assistant-php

PHP library for using sms-assistent.by HTTP API

  • Friday, March 24, 2017
  • by Zer0
  • Repository
  • 1 Watchers
  • 0 Stars
  • 65 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

StyleCI, (*1)

sms-assistent.by API PHP wrapper

This library can be used to send messages via sms-assistent.by site., (*2)

More info about API can be found here., (*3)

Installation

Add following requirement to your composer.json file:, (*4)

{
    "require": {
        "by-zer0/sms-assistant-php": "1.2"
    }
}

or just use composer command, (*5)

composer require by-zer0/sms-assistant-php:1.2

Usage

First create client instance., (*6)

require 'vendor/autoload.php';

use ByZer0\SmsAssistantBy\Client;
use ByZer0\SmsAssistantBy\Http\GuzzleClient;

$client = (new Client(new GuzzleClient()))
    ->setUsername('<username>') // Set username to pass API authorization.
    ->setSender('<sender-name>') // Set default sender name.
    ->setPassword('<password>'); // Set account password to pass API authorization.
//    ->setToken('<token>'); // Optional, set access token instead of password.

Constructor accepts ByZer0\SmsAssistantBy\Http\ClientInterface instance. This instance will be actually used to perform HTTP requests. By default, package contains ByZer0\SmsAssistantBy\Http\GuzzleClient class - request wrapper for guzzlehttp/guzzle library. You can write your own implementation of ByZer0\SmsAssistantBy\Http\ClientInterface to use with any other library., (*7)

Execute following command if you want to use default guzzle adapter:, (*8)

composer require guzzlehttp/guzzle

Massive sending

Use method sendMessages($messages, $default = [], $time = null) to send multiple messages at once., (*9)

$default = [
    'sender' => '<default-sender>',
    'text' => 'This is default message text',
];

$messages = [
    [
        'phone' => '+375294011111',
        'sender' => 'notdefault',
        'text' => 'Message for first recipient',
    ],
    [
        'phone' => '+375294022222', // default sender name and text will be used
    ],
];

$client->sendMessages($messages, $default);

in this case $default represents common settings for each message. Default message can contain next fields:, (*10)

  • sender - to use one sender name for every message
  • text - common text can be placed here to avoid duplicate in every message

Every message must contain one required field:, (*11)

  • phone - phone number of message recipient.

In addition to phone, every default value can be overwritten in any message., (*12)

You can also use third parameter of sendMessages() to delay send. Third parameter $time accepts DateTime instance., (*13)

Single message

Use method sendMessage($phone, $text, $time = null, $sender = null) to send single message., (*14)

$client->sendMessage('+375294011111', 'Example message text');

This method accepts up to four parameters:, (*15)

  • phone - Phone number of message recipient.
  • text - Message text.
  • time - DateTime instance. Use to delay message delivery.
  • sender - Sender name. If used, this name will override default value specified by setSender() method.

The Versions

24/03 2017

dev-master

9999999-dev https://github.com/ByZer0/sms-assistant-php

PHP library for using sms-assistent.by HTTP API

  Sources   Download

MIT

28/12 2016

1.2

1.2.0.0 https://github.com/ByZer0/sms-assistant-php

PHP library for using sms-assistent.by HTTP API

  Sources   Download

MIT

03/11 2016

1.1

1.1.0.0 https://github.com/ByZer0/sms-assistant-php

PHP library for using sms-assistent.by HTTP API

  Sources   Download

MIT

24/09 2016

1.0

1.0.0.0 https://github.com/ByZer0/sms-assistant-php

PHP library for using sms-assistent.by HTTP API

  Sources   Download

MIT