Skip to content

Dev #8

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

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .idea/php-client.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 13 additions & 22 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 58 additions & 57 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
{
"authors": [
{
"email": "support@seven.io",
"homepage": "https://www.seven.io",
"name": "seven communications GmbH & Co. KG",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Seven\\Api\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Seven\\Tests\\": "tests/"
}
},
"config": {
"platform": {
"php": "7.4"
}
},
"description": "Official API Client for requesting the seven.io SMS Gateway.",
"homepage": "https://github.com/seven-io/php-client",
"keywords": [
"2fa",
"cnam",
"gateway",
"hlr",
"mnp",
"sms",
"text2speech",
"tts"
],
"license": "MIT",
"name": "seven.io/api",
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-curl": "*",
"ext-mbstring": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9",
"ext-xdebug": "*",
"ext-soap": "*",
"ext-simplexml": "*"
},
"support": {
"docs": "https://github.com/seven-io/php-client",
"email": "support@seven.io",
"rss": "https://www.seven.io/en/feed/",
"source": "https://github.com/seven-io/php-client"
},
"type": "library"
"authors": [
{
"email": "support@seven.io",
"homepage": "https://www.seven.io",
"name": "seven communications GmbH & Co. KG",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Seven\\Api\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Seven\\Tests\\": "tests/"
}
},
"config": {
"platform": {
"php": "8.2"
}
},
"description": "Official API Client for requesting the seven.io messaging Gateway.",
"homepage": "https://github.com/seven-io/php-client",
"keywords": [
"2fa",
"cnam",
"gateway",
"hlr",
"mnp",
"rcs",
"sms",
"text2speech",
"tts"
],
"license": "MIT",
"name": "seven.io/api",
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-curl": "*",
"ext-mbstring": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^11",
"ext-xdebug": "*",
"ext-soap": "*",
"ext-simplexml": "*"
},
"support": {
"docs": "https://github.com/seven-io/php-client",
"email": "support@seven.io",
"rss": "https://www.seven.io/en/feed/",
"source": "https://github.com/seven-io/php-client"
},
"type": "library"
}
55 changes: 25 additions & 30 deletions src/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
use Seven\Api\Constant\HttpMethod;
use UnexpectedValueException;

abstract class BaseClient {
abstract class BaseClient
{
public const BASE_URI = 'https://gateway.seven.io/api';

protected string $apiKey;
protected string $sentWith;

/**
* @throws Exception
*/
public function __construct(string $apiKey, string $sentWith = 'php-api') {
$this->apiKey = $apiKey;
$this->sentWith = $sentWith;
public function __construct(
protected string $apiKey,
protected string $sentWith = 'php-api'
)
{

if ('' === $apiKey) throw new InvalidArgumentException(
"Invalid required constructor argument apiKey: $apiKey");
Expand All @@ -27,25 +27,23 @@ public function __construct(string $apiKey, string $sentWith = 'php-api') {
"Invalid required constructor argument sentWith: $sentWith");
}

public function getApiKey(): string {
public function getApiKey(): string
{
return $this->apiKey;
}

public function getSentWith(): string {
public function getSentWith(): string
{
return $this->sentWith;
}

/**
* @return mixed
*/
public function delete(string $path, array $options = []) {
public function delete(string $path, array $options = []): mixed
{
return $this->request($path, HttpMethod::DELETE, $options);
}

/**
* @return mixed
*/
protected function request(string $path, string $method, array $options = []) {
protected function request(string $path, string $method, array $options = []): mixed
{
$method = strtoupper($method);
$methods = HttpMethod::values();
if (!in_array($method, $methods)) {
Expand All @@ -58,16 +56,17 @@ protected function request(string $path, string $method, array $options = []) {
$headers = [
'Accept: application/json',
'Content-Type: application/json',
"SentWith: $this->sentWith",
"X-Api-Key: $this->apiKey",
'SentWith: ' . $this->sentWith,
'X-Api-Key:' . $this->apiKey,
];
$url = self::BASE_URI . "/$path";
$url = self::BASE_URI . '/' . $path;
$params = http_build_query($options);
if (HttpMethod::GET === $method) $url .= "?$params";
if (HttpMethod::GET === $method) $url .= '?' . $params;

$ch = curl_init($url);

if (HttpMethod::POST === $method) {
var_dump($options);
$params = stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE));

curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
Expand All @@ -88,23 +87,19 @@ protected function request(string $path, string $method, array $options = []) {

try {
$res = json_decode($res, false, 512, JSON_THROW_ON_ERROR);
} catch (Exception $e) {
} catch (Exception) {
}

return $res;
}

/**
* @return mixed
*/
public function post(string $path, array $options = []) {
public function post(string $path, array $options = []): mixed
{
return $this->request($path, HttpMethod::POST, $options);
}

/**
* @return mixed
*/
public function get(string $path, array $options = []) {
public function get(string $path, array $options = []): mixed
{
return $this->request($path, HttpMethod::GET, $options);
}
}
9 changes: 7 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@
use Seven\Api\Resource\JournalResource;
use Seven\Api\Resource\LookupResource;
use Seven\Api\Resource\PricingResource;
use Seven\Api\Resource\RcsResource;
use Seven\Api\Resource\SmsResource;
use Seven\Api\Resource\StatusResource;
use Seven\Api\Resource\SubaccountsResource;
use Seven\Api\Resource\ValidateForVoiceResource;
use Seven\Api\Resource\VoiceResource;

class Client extends BaseClient {
class Client extends BaseClient
{
public AnalyticsResource $analytics;
public BalanceResource $balance;
public ContactsResource $contacts;
public HooksResource $hooks;
public JournalResource $journal;
public LookupResource $lookup;
public PricingResource $pricing;
public RcsResource $rcs;
public SmsResource $sms;
public StatusResource $status;
public SubaccountsResource $subaccounts;
public ValidateForVoiceResource $validateForVoice;
public VoiceResource $voice;

public function __construct(string $apiKey, string $sentWith = 'php-api') {
public function __construct(string $apiKey, string $sentWith = 'php-api')
{
parent::__construct($apiKey, $sentWith);

$this->analytics = new AnalyticsResource($this);
Expand All @@ -39,6 +43,7 @@ public function __construct(string $apiKey, string $sentWith = 'php-api') {
$this->journal = new JournalResource($this);
$this->lookup = new LookupResource($this);
$this->pricing = new PricingResource($this);
$this->rcs = new RcsResource($this);
$this->sms = new SmsResource($this);
$this->status = new StatusResource($this);
$this->subaccounts = new SubaccountsResource($this);
Expand Down
9 changes: 9 additions & 0 deletions src/Params/Rcs/RcsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Seven\Api\Params\Rcs;

enum RcsEvent
{
case IS_TYPING;
case READ;
}
Loading