Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: partikule/spothit-sms-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Alpifra/spothit-sms-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 16, 2022

  1. Complie with psr-4

    Alpifra committed Jun 16, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    alexanderbez Aleksandr Bezobchuk
    Copy the full SHA
    0b853bf View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    alexanderbez Aleksandr Bezobchuk
    Copy the full SHA
    6454106 View commit details

Commits on Jun 17, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    alexanderbez Aleksandr Bezobchuk
    Copy the full SHA
    581bca1 View commit details
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
}
],
"autoload": {
"psr-0": {
"Spothit\\Api\\": "src/"
"psr-4": {
"Partikule\\Spothit\\": "src/"
}
},
"require": {
133 changes: 45 additions & 88 deletions src/Spothit/Api/Client.php → src/Base.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,72 +1,61 @@
<?php
<?php

namespace Spothit\Api;
namespace Partikule\Spothit;

use Spothit\Api\Exception\RequestException;
use Spothit\Api\Exception\ResponseException;
use Spothit\Api\Exception\ResponseCodeException;
use Partikule\Spothit\Exception\RequestException;
use Partikule\Spothit\Exception\ResponseException;
use Partikule\Spothit\Exception\ResponseCodeException;

/**
* Spothit API client.
*/
class Client
{
const BASE_URL = 'http://www.spot-hit.fr';
class Base {

const SMS_TYPE_LOWCOST = 'lowcost';
const SMS_TYPE_PREMIUM = 'premium';

/**
* User login (email address).
*
* @var string
*/
private $userLogin;
const BASE_URL = 'https://www.spot-hit.fr';

/**
* API key available on your manager.
*
* @var string
*/
private $apiKey;

/**
* @var string self::SMS_TYPE_*
*/
private $smsType = self::SMS_TYPE_LOWCOST;
public $apiKey;

/**
* Numbers in international format + XXZZZZZ.
*
* @var array
*/
private $smsRecipients = [];
public $smsRecipients = [];

/**
* @var DateTime
*/
private $sendingTime;
public $sendingTime;

/**
* Sender of the message (if the user allows it), 3-11 alphanumeric characters (a-zA-Z).
*
* @var string
*/
private $smsSender = 'OneSender';
public $smsSender = 'Spot-Hit';

/**
* Campaign identifier used for Spot-Hit administration panel and not visible to the recipients.
*
* @var string
*/
public $campaignName = null;

/**
* Allow long SMS
*
* @var bool
*/
private $allowLongSms = 1;
public $allowLongSms = 1;

/**
* callback URL
*
* @var string
*/
private $callbackUrl;
public $callbackUrl;


public function __construct($apiKey)
@@ -75,11 +64,6 @@ public function __construct($apiKey)
$this->sendingTime = new \DateTime();
}

public function setSmsType($smsType)
{
$this->smsType = $smsType;
}

public function setSmsRecipients(array $smsRecipients)
{
$this->smsRecipients = $smsRecipients;
@@ -95,78 +79,34 @@ public function setSmsSender($smsSender)
$this->smsSender = $smsSender;
}

public function setCallbackUrl($url)
public function setCampaignName($campaignName)
{
$this->callbackUrl=$url;
$this->campaignName = $campaignName;
}

/**
* Sends a simple SMS.
*
* @param string $smsText Message text (maximum 459 characters).
*
* @return array
*
* @see https://www.spot-hit.fr/documentation-api#chapter2para1
*/
public function send($smsText)
{
$data = [
'key' => $this->apiKey,
'type' => $this->smsType,
'message' => $smsText,
'destinataires' => implode(',', $this->smsRecipients),
'expediteur' => $this->smsSender,
'smslong' => $this->allowLongSms
];

if ($this->sendingTime > (new \DateTime())) {
$data['date'] = $this->sendingTime->getTimestamp();
}

if ($this->callbackUrl) {
$data['url'] = $this->callbackUrl;
}

return $this->httpRequest('/api/envoyer/sms', $data);
}

/**
* Returns credit balance as a number of Euros left on account.
*
* @return array
*
* @see https://www.spot-hit.fr/api/credits
*/
public function getCredit()
public function setCallbackUrl($url)
{
$data = [
'key' => $this->apiKey,
];

return $this->httpRequest('/api/credits', $data);
$this->callbackUrl = $url;
}

private function httpRequest($path, array $fields)
public function httpRequest($path, array $fields)
{
set_time_limit(0);

$qs = [];
foreach ($fields as $k => $v) {
$qs[] = $k.'='.urlencode($v);
$qs[] = $k . '=' . urlencode($v);
}

$request = implode('&', $qs);

if (false === $ch = curl_init(self::BASE_URL.$path)) {
if (false === $ch = curl_init(self::BASE_URL . $path)) {
throw new RequestException(sprintf('Request initialization to "%s" failed.', $path));
}

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_PORT, 80);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

if (false === $result = curl_exec($ch)) {
curl_close($ch);
@@ -200,4 +140,21 @@ private function httpRequest($path, array $fields)

return $responseArray;
}
}

/**
* Returns credit balance as a number of Euros left on account.
*
* @return array
*
* @see https://www.spot-hit.fr/api/credits
*/
public function getCredit()
{
$data = [
'key' => $this->apiKey,
];

return $this->httpRequest('/api/credits', $data);
}

}
40 changes: 40 additions & 0 deletions src/Client/Sms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Partikule\Spothit\Client;

use Partikule\Spothit\Base;

/**
* Spothit API client.
*/
class Sms extends Base
{

/**
* Sends a simple SMS.
*
* @param string $sender Sender of the message (if the user allows it), 3-11 alphanumeric characters (a-zA-Z).
* @param string $smsText Message text (maximum 459 characters).
*
* @return array
*
* @see https://www.spot-hit.fr/documentation-api#chapter2para1
*/
public function send($smsText)
{
$data = [
'key' => $this->apiKey,
'message' => $smsText,
'destinataires' => implode(',', $this->smsRecipients),
'nom' => $this->campaignName,
'expediteur' => $this->smsSender,
'smslong' => $this->allowLongSms
];

if ($this->callbackUrl) {
$data['url'] = $this->callbackUrl;
}

return $this->httpRequest('/api/envoyer/sms', $data);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spothit\Api\Exception;
namespace Partikule\Spothit\Exception;

class RequestException extends \RuntimeException
{
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spothit\Api\Exception;
namespace Partikule\Spothit\Exception;

class ResponseCodeException extends \RuntimeException
{
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spothit\Api\Exception;
namespace Partikule\Spothit\Exception;

class ResponseException extends \RuntimeException
{