Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to release 4.0.0 #12

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
operating-system: ["ubuntu-latest"]
#@wontfix v.5.3 conflicts with php-cs-fixer
#@todo fix v.8 conflicts with phpunit
php-versions: ["7.3", "7.4", "8.2"]
php-versions: ["7.3", "7.4", "8.2", "8.3"]
#phpunit-versions: ['latest']

steps:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ echo "Balance : " . $response->balance. "\n";

## Compatibility

`greensms-php` is compatible with PHP 5.5 and PHP 7+ onwards until the latest PHP Version
`greensms-php` is compatible with PHP 7.3+ onwards until the latest PHP Version

## Methods

Expand All @@ -78,7 +78,7 @@ echo "Balance : " . $response->balance. "\n";

## Getting help

If you need help installing or using the library, please contact us: [support@greensms.ru](mailto:support@greensms.ru).
If you need help installing or using the library, please contact us: [support@greensms.io](mailto:support@greensms.io).

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Expand All @@ -103,4 +103,4 @@ GreenSMS has all the unit tests defined under **tests** folder with `*Test.php`
./vendor/bin/phpunit tests
```

[apidocs]: https://api.greensms.ru/
[apidocs]: https://api.greensms.io/
8 changes: 5 additions & 3 deletions composer.json
2naive marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"authors": [
{
"name": "Team GreenSMS",
"email": "support@greensms.ru"
"email": "support@greensms.io"
}
],
"require": {
"php": ">=7.0",
"vlucas/valitron": "^1.4"
"php": ">=7.3",
"vlucas/valitron": "^1.4",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9",
Expand Down
20 changes: 20 additions & 0 deletions examples/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,23 @@
$response = $client->account->tariff();
echo "Tariff Response: ";
print_r($response);

$response = $client->account->blacklist->add(['to' => '70000000000', 'module' => 'ALL', 'comment' => 'test']);
echo "Blacklist Add Response: ";
print_r($response);
$response = $client->account->blacklist->get();
echo "Blacklist Get Response: ";
print_r($response);
$response = $client->account->blacklist->delete(['to' => '70000000000']);
echo "Blacklist Delete Response: ";
print_r($response);

$response = $client->account->limits->set(['type' => 'IP', 'module' => 'ALL', 'value' => '1.1.1.1,8.8.8.8', 'comment' => 'test']);
echo "Limits Set Response: ";
print_r($response);
$response = $client->account->limits->get();
echo "Limits Get Response: ";
print_r($response);
$response = $client->account->limits->delete(['type' => 'IP']);
echo "Limits Delete Response: ";
print_r($response);
125 changes: 86 additions & 39 deletions src/Api/ModuleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace GreenSMS\Api;

use GreenSMS\Api\Modules;
use GreenSMS\Api\Module;
use GreenSMS\Utils\Url;
use GreenSMS\Utils\Helpers;
use GreenSMS\Api\MethodInvoker;

class ModuleLoader
{
Expand Down Expand Up @@ -40,44 +37,13 @@ public function registerModules($sharedOptions, $filters = null)


foreach ($moduleVersions as $version => $versionFunctions) {
if (!property_exists($this->moduleMap->{$moduleName}, $version)) {
$this->moduleMap->{$moduleName}->{$version} = new MethodInvoker;
}

foreach ($versionFunctions as $functionName => $functionDefinition) {
$moduleSchema = null;
$schemaExists = self::doesSchemaExists($moduleInfo, $version, $functionName);
if ($schemaExists) {
$moduleSchema = $moduleInfo['schema'][$version][$functionName];
}

$urlParts = [];
if (!$isStaticModule) {
array_push($urlParts, $moduleName);
}

array_push($urlParts, $functionName);
$apiUrl = Url::buildUrl($sharedOptions['baseUrl'], $urlParts);

$functionOptions = [
'url' => $apiUrl,
'definition' => $functionDefinition,
'sharedOptions' => $sharedOptions,
'moduleSchema' => $moduleSchema
];


$this->moduleMap->{$moduleName}->{$version}->{$functionName} = $this->getFunctionInstance($functionOptions);

if ($version === $currentVersion) {
$this->moduleMap->{$moduleName}->{$functionName} = $this->moduleMap->{$moduleName}->{$version}->{$functionName};
}

if ($isStaticModule) {
$this->moduleMap->{$functionName} = $this->moduleMap->{$moduleName}->{$version}->{$functionName};
unset($this->moduleMap->{$moduleName});
}
if ($version === 'v1') {
$this->addModuleMapV1($versionFunctions, $moduleInfo, $version, $isStaticModule, $moduleName, $sharedOptions, $currentVersion);
} elseif ($version === 'v4.0.0') {
$this->addModuleMapV4_0_0($versionFunctions, $moduleInfo, $version, $isStaticModule, $moduleName, $sharedOptions, $currentVersion);
}

}
}

Expand Down Expand Up @@ -110,4 +76,85 @@ private function getFunctionInstance($options)
$functionInstance = array($module, 'apiFunction');
return $functionInstance;
}

private function addModuleMapV1($versionFunctions, $moduleInfo, $version, $isStaticModule, $moduleName, $sharedOptions, $currentVersion)
{
if (!property_exists($this->moduleMap->{$moduleName}, $version)) {
$this->moduleMap->{$moduleName}->{$version} = new MethodInvoker;
}

foreach ($versionFunctions as $functionName => $functionDefinition) {
$moduleSchema = null;
$schemaExists = self::doesSchemaExists($moduleInfo, $version, $functionName);
if ($schemaExists) {
$moduleSchema = $moduleInfo['schema'][$version][$functionName];
}

$urlParts = [];
if (!$isStaticModule) {
array_push($urlParts, $moduleName);
}

array_push($urlParts, $functionName);
$apiUrl = Url::buildUrl($sharedOptions['baseUrl'], $urlParts);

$functionOptions = [
'url' => $apiUrl,
'definition' => $functionDefinition,
'sharedOptions' => $sharedOptions,
'moduleSchema' => $moduleSchema
];

$this->moduleMap->{$moduleName}->{$version}->{$functionName} = $this->getFunctionInstance($functionOptions);

if ($version === $currentVersion) {
$this->moduleMap->{$moduleName}->{$functionName} = $this->moduleMap->{$moduleName}->{$version}->{$functionName};
}

if ($isStaticModule) {
$this->moduleMap->{$functionName} = $this->moduleMap->{$moduleName}->{$version}->{$functionName};
unset($this->moduleMap->{$moduleName});
}
}
}

private function addModuleMapV4_0_0($functions, $moduleInfo, $version, $isStaticModule, $moduleName, $sharedOptions, $currentVersion)
{

foreach ($functions as $prop => $definitions) {
if (!property_exists($this->moduleMap->{$moduleName}, $prop)) {
$this->moduleMap->{$moduleName}->{$prop} = new MethodInvoker;
}
if (!property_exists($this->moduleMap->{$moduleName}->{$prop}, $version)) {
$this->moduleMap->{$moduleName}->{$prop}->{$version} = new MethodInvoker;
}

foreach ($definitions as $functionName => $functionDefinition) {
$moduleSchema = null;
if ($moduleInfo['schema'][$version][$prop][$functionName]) {
$moduleSchema = $moduleInfo['schema'][$version][$prop][$functionName];
}

$urlParts = [];
if (!$isStaticModule) {
array_push($urlParts, $moduleName);
}

array_push($urlParts, $prop);
$apiUrl = Url::buildUrl($sharedOptions['baseUrl'], $urlParts);

$functionOptions = [
'url' => $apiUrl,
'definition' => $functionDefinition,
'sharedOptions' => $sharedOptions,
'moduleSchema' => $moduleSchema
];


$this->moduleMap->{$moduleName}->{$prop}->{$version}->{$functionName} = $this->getFunctionInstance($functionOptions);
$this->moduleMap->{$moduleName}->{$prop}->{$functionName} = $this->moduleMap->{$moduleName}->{$prop}->{$version}->{$functionName};

}
}
}
}
85 changes: 62 additions & 23 deletions src/Api/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace GreenSMS\Api;

use GreenSMS\Api\Schema;

class Modules
{
public static function getModules()
public static function getModules(): array
{
$schema = Schema::getSchema();

$modules = [
return [
'account' => [
'schema' => $schema['account'],
'versions' => [
Expand All @@ -26,8 +24,66 @@ public static function getModules()
'tariff' => [
'args' => null,
'method' => 'GET'
]
]
],
],
'v4.0.0' => [
'blacklist' => [
'get' => [
'args' => null,
'method' => 'GET',
],
'add' => [
'args' => ['params'],
'method' => 'POST',
],
'delete' => [
'args' => ['params'],
'method' => 'DELETE',
],
],
'limits' => [
'get' => [
'args' => null,
'method' => 'GET',
],
'set' => [
'args' => null,
'method' => 'POST',
],
'delete' => [
'args' => null,
'method' => 'DELETE',
],
],
'webhook' => [
'get' => [
'args' => null,
'method' => 'GET',
],
'set' => [
'args' => null,
'method' => 'POST',
],
'delete' => [
'args' => null,
'method' => 'DELETE',
],
],
'whitelist' => [
'get' => [
'args' => null,
'method' => 'GET',
],
'add' => [
'args' => null,
'method' => 'POST',
],
'delete' => [
'args' => null,
'method' => 'DELETE',
],
],
],
]
],
'call' => [
Expand Down Expand Up @@ -177,23 +233,6 @@ public static function getModules()
]
]
],
'social' => [
'schema' => $schema['social'],
'versions' => [
'v1' => [
'send' => [
'args' => ['params'],
'method' => 'POST',
],
'status' => [
'args' => ['params'],
'method' => 'GET',
],
]
]
],
];

return $modules;
}
}
Loading
Loading