Skip to content

Commit

Permalink
Smart SMS v1
Browse files Browse the repository at this point in the history
  • Loading branch information
pk committed Oct 18, 2024
0 parents commit 7b95749
Show file tree
Hide file tree
Showing 16 changed files with 497 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_ENV=development
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor
.env
composer.lock
/.phpunit.result.cache
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Orange SmartSMS API Client

A PHP client to interact with the Orange SmartSMS API. This package allows you to send SMS messages, check their delivery status, and monitor API usage limits.

## Features

- Send SMS messages to various networks.
- Check the delivery status of previously sent SMS messages.
- Retrieve the usage limit and available requests for the SmartSMS API.

## Installation

1. Install via Composer:

```bash
composer require kwarcek/orange-smartsms-api
```

## Usage

### 1. Send an SMS Message

You can send an SMS message by using the `sendSMS` method. The message will be delivered to the recipient's mobile phone.
#### Example:
```php
use Kwarcek\OrangeSmartsmsApi\Requests\MessagingRequest;
use Kwarcek\OrangeSmartsmsApi\DTO\SMSMessage;
use GuzzleHttp\Client;
$isDev = getenv('APP_ENV');
// Create a new Guzzle client and MessagingRequest instance
$client = new Client([
'base_uri' => $isDev ? 'https://apib2b-test.orange.pl/' : 'https://apib2b.orange.pl/',
]);
$apiKey = 'your-api-key-here';
$messagingRequest = new MessagingRequest($client, $apiKey);
// Define the SMS message
$message = new SMSMessage([
'sender' => 'YourSenderID',
'recipient' => '48510123456', // Recipient's phone number
'content' => 'Hello from Orange SmartSMS!',
]);

// Send the SMS
$response = $messagingRequest->sendSMS($message, true);

print_r($response);
```

### 2. Check SMS Delivery Status

You can check the delivery status of a sent SMS by passing the unique ID returned in the sendSMS response.
Example:

```php
use Kwarcek\OrangeSmartsmsApi\Requests\MessagingRequest;
use GuzzleHttp\Client;

$isDev = getenv('APP_ENV');

$client = new Client([
'base_uri' => $isDev ? 'https://apib2b-test.orange.pl/' : 'https://apib2b.orange.pl/',
]);
$apiKey = 'your-api-key-here';

$messagingRequest = new MessagingRequest($client, $apiKey);

$id = '54510a5d0361'; // Example message ID
$response = $messagingRequest->checkDeliveryStatus($id);

print_r($response);
```

### 3. Check API Usage Limit

You can check the current API usage limit for SmartSMS, including used and available requests.
Example:

```php
use Kwarcek\OrangeSmartsmsApi\Requests\MessagingRequest;
use GuzzleHttp\Client;

$isDev = getenv('APP_ENV');

$client = new Client([
'base_uri' => $isDev ? 'https://apib2b-test.orange.pl/' : 'https://apib2b.orange.pl/',
]);
$apiKey = 'your-api-key-here';

$messagingRequest = new MessagingRequest($client, $apiKey);

$response = $messagingRequest->checkLimit();

print_r($response);
```
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "kwarcek/smart-sms-api",
"description": "A PHP API client for Orange SmartSMS service.",
"type": "library",
"version": "1.0.0",
"require": {
"php": "^8.2",
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Kwarcek\\OrangeSmartsmsApi\\":"src/"
}
},
"autoload-dev": {
"psr-4": {
"Kwarcek\\OrangeSmartsmsApi\\Test\\": "tests"
}
},
"scripts": {
"test": "phpunit"
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
php:
container_name: orange-smartsms-api
build:
context: .
dockerfile: docker/Dockerfile
env_file:
- .env
tty: true
volumes:
- ./:/app
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:8.1

WORKDIR /app

COPY . .

RUN apt-get update -y && \
apt-get install git -y

RUN apt-get update && \
apt-get install -y libpq-dev \
unzip \
zlib1g-dev \
zlib1g-dev \
zip \
--no-install-recommends

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

CMD /bin/bash
15 changes: 15 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>

<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
</coverage>
<php>
<server name="APP_ENV" value="development"/>
</php>
</phpunit>
14 changes: 14 additions & 0 deletions src/DTO/SMSMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Kwarcek\OrangeSmartsmsApi\DTO;

class SMSMessage
{
public function __construct(
public string $sender,
public string $recipient,
public string $content
)
{
}
}
8 changes: 8 additions & 0 deletions src/Exceptions/BadRequestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Kwarcek\OrangeSmartsmsApi\Exceptions;

class BadRequestException extends Exception
{

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

namespace Kwarcek\OrangeSmartsmsApi\Exceptions;

class Exception extends \Exception
{

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

namespace Kwarcek\OrangeSmartsmsApi\Exceptions;

class ForbiddenException extends Exception
{

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

namespace Kwarcek\OrangeSmartsmsApi\Exceptions;

class InternalServerException extends Exception
{

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

namespace Kwarcek\OrangeSmartsmsApi\Exceptions;

class NotFoundException extends Exception
{

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

namespace Kwarcek\OrangeSmartsmsApi\Exceptions;

class UnathorizedException extends Exception
{

}
Loading

0 comments on commit 7b95749

Please sign in to comment.