Skip to content

Commit 6458cf9

Browse files
authored
Merge pull request #8 from seven-io/dev
Dev
2 parents 5777763 + d2b7570 commit 6458cf9

19 files changed

+964
-294
lines changed

.idea/php-client.iml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php-test-framework.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 13 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
{
2-
"authors": [
3-
{
4-
"email": "[email protected]",
5-
"homepage": "https://www.seven.io",
6-
"name": "seven communications GmbH & Co. KG",
7-
"role": "Developer"
8-
}
9-
],
10-
"autoload": {
11-
"psr-4": {
12-
"Seven\\Api\\": "src/"
13-
}
14-
},
15-
"autoload-dev": {
16-
"psr-4": {
17-
"Seven\\Tests\\": "tests/"
18-
}
19-
},
20-
"config": {
21-
"platform": {
22-
"php": "7.4"
23-
}
24-
},
25-
"description": "Official API Client for requesting the seven.io SMS Gateway.",
26-
"homepage": "https://github.com/seven-io/php-client",
27-
"keywords": [
28-
"2fa",
29-
"cnam",
30-
"gateway",
31-
"hlr",
32-
"mnp",
33-
"sms",
34-
"text2speech",
35-
"tts"
36-
],
37-
"license": "MIT",
38-
"name": "seven.io/api",
39-
"require": {
40-
"php": ">=7.4",
41-
"ext-ctype": "*",
42-
"ext-curl": "*",
43-
"ext-mbstring": "*",
44-
"ext-json": "*"
45-
},
46-
"require-dev": {
47-
"phpunit/phpunit": "^9",
48-
"ext-xdebug": "*",
49-
"ext-soap": "*",
50-
"ext-simplexml": "*"
51-
},
52-
"support": {
53-
"docs": "https://github.com/seven-io/php-client",
54-
"email": "[email protected]",
55-
"rss": "https://www.seven.io/en/feed/",
56-
"source": "https://github.com/seven-io/php-client"
57-
},
58-
"type": "library"
2+
"authors": [
3+
{
4+
"email": "[email protected]",
5+
"homepage": "https://www.seven.io",
6+
"name": "seven communications GmbH & Co. KG",
7+
"role": "Developer"
8+
}
9+
],
10+
"autoload": {
11+
"psr-4": {
12+
"Seven\\Api\\": "src/"
13+
}
14+
},
15+
"autoload-dev": {
16+
"psr-4": {
17+
"Seven\\Tests\\": "tests/"
18+
}
19+
},
20+
"config": {
21+
"platform": {
22+
"php": "8.2"
23+
}
24+
},
25+
"description": "Official API Client for requesting the seven.io messaging Gateway.",
26+
"homepage": "https://github.com/seven-io/php-client",
27+
"keywords": [
28+
"2fa",
29+
"cnam",
30+
"gateway",
31+
"hlr",
32+
"mnp",
33+
"rcs",
34+
"sms",
35+
"text2speech",
36+
"tts"
37+
],
38+
"license": "MIT",
39+
"name": "seven.io/api",
40+
"require": {
41+
"php": ">=8.2",
42+
"ext-ctype": "*",
43+
"ext-curl": "*",
44+
"ext-mbstring": "*",
45+
"ext-json": "*"
46+
},
47+
"require-dev": {
48+
"phpunit/phpunit": "^11",
49+
"ext-xdebug": "*",
50+
"ext-soap": "*",
51+
"ext-simplexml": "*"
52+
},
53+
"support": {
54+
"docs": "https://github.com/seven-io/php-client",
55+
"email": "[email protected]",
56+
"rss": "https://www.seven.io/en/feed/",
57+
"source": "https://github.com/seven-io/php-client"
58+
},
59+
"type": "library"
5960
}

src/BaseClient.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
use Seven\Api\Constant\HttpMethod;
88
use UnexpectedValueException;
99

10-
abstract class BaseClient {
10+
abstract class BaseClient
11+
{
1112
public const BASE_URI = 'https://gateway.seven.io/api';
1213

13-
protected string $apiKey;
14-
protected string $sentWith;
15-
1614
/**
1715
* @throws Exception
1816
*/
19-
public function __construct(string $apiKey, string $sentWith = 'php-api') {
20-
$this->apiKey = $apiKey;
21-
$this->sentWith = $sentWith;
17+
public function __construct(
18+
protected string $apiKey,
19+
protected string $sentWith = 'php-api'
20+
)
21+
{
2222

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

30-
public function getApiKey(): string {
30+
public function getApiKey(): string
31+
{
3132
return $this->apiKey;
3233
}
3334

34-
public function getSentWith(): string {
35+
public function getSentWith(): string
36+
{
3537
return $this->sentWith;
3638
}
3739

38-
/**
39-
* @return mixed
40-
*/
41-
public function delete(string $path, array $options = []) {
40+
public function delete(string $path, array $options = []): mixed
41+
{
4242
return $this->request($path, HttpMethod::DELETE, $options);
4343
}
4444

45-
/**
46-
* @return mixed
47-
*/
48-
protected function request(string $path, string $method, array $options = []) {
45+
protected function request(string $path, string $method, array $options = []): mixed
46+
{
4947
$method = strtoupper($method);
5048
$methods = HttpMethod::values();
5149
if (!in_array($method, $methods)) {
@@ -58,16 +56,17 @@ protected function request(string $path, string $method, array $options = []) {
5856
$headers = [
5957
'Accept: application/json',
6058
'Content-Type: application/json',
61-
"SentWith: $this->sentWith",
62-
"X-Api-Key: $this->apiKey",
59+
'SentWith: ' . $this->sentWith,
60+
'X-Api-Key:' . $this->apiKey,
6361
];
64-
$url = self::BASE_URI . "/$path";
62+
$url = self::BASE_URI . '/' . $path;
6563
$params = http_build_query($options);
66-
if (HttpMethod::GET === $method) $url .= "?$params";
64+
if (HttpMethod::GET === $method) $url .= '?' . $params;
6765

6866
$ch = curl_init($url);
6967

7068
if (HttpMethod::POST === $method) {
69+
var_dump($options);
7170
$params = stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE));
7271

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

8988
try {
9089
$res = json_decode($res, false, 512, JSON_THROW_ON_ERROR);
91-
} catch (Exception $e) {
90+
} catch (Exception) {
9291
}
9392

9493
return $res;
9594
}
9695

97-
/**
98-
* @return mixed
99-
*/
100-
public function post(string $path, array $options = []) {
96+
public function post(string $path, array $options = []): mixed
97+
{
10198
return $this->request($path, HttpMethod::POST, $options);
10299
}
103100

104-
/**
105-
* @return mixed
106-
*/
107-
public function get(string $path, array $options = []) {
101+
public function get(string $path, array $options = []): mixed
102+
{
108103
return $this->request($path, HttpMethod::GET, $options);
109104
}
110105
}

src/Client.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,31 @@
99
use Seven\Api\Resource\JournalResource;
1010
use Seven\Api\Resource\LookupResource;
1111
use Seven\Api\Resource\PricingResource;
12+
use Seven\Api\Resource\RcsResource;
1213
use Seven\Api\Resource\SmsResource;
1314
use Seven\Api\Resource\StatusResource;
1415
use Seven\Api\Resource\SubaccountsResource;
1516
use Seven\Api\Resource\ValidateForVoiceResource;
1617
use Seven\Api\Resource\VoiceResource;
1718

18-
class Client extends BaseClient {
19+
class Client extends BaseClient
20+
{
1921
public AnalyticsResource $analytics;
2022
public BalanceResource $balance;
2123
public ContactsResource $contacts;
2224
public HooksResource $hooks;
2325
public JournalResource $journal;
2426
public LookupResource $lookup;
2527
public PricingResource $pricing;
28+
public RcsResource $rcs;
2629
public SmsResource $sms;
2730
public StatusResource $status;
2831
public SubaccountsResource $subaccounts;
2932
public ValidateForVoiceResource $validateForVoice;
3033
public VoiceResource $voice;
3134

32-
public function __construct(string $apiKey, string $sentWith = 'php-api') {
35+
public function __construct(string $apiKey, string $sentWith = 'php-api')
36+
{
3337
parent::__construct($apiKey, $sentWith);
3438

3539
$this->analytics = new AnalyticsResource($this);
@@ -39,6 +43,7 @@ public function __construct(string $apiKey, string $sentWith = 'php-api') {
3943
$this->journal = new JournalResource($this);
4044
$this->lookup = new LookupResource($this);
4145
$this->pricing = new PricingResource($this);
46+
$this->rcs = new RcsResource($this);
4247
$this->sms = new SmsResource($this);
4348
$this->status = new StatusResource($this);
4449
$this->subaccounts = new SubaccountsResource($this);

src/Params/Rcs/RcsEvent.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Seven\Api\Params\Rcs;
4+
5+
enum RcsEvent
6+
{
7+
case IS_TYPING;
8+
case READ;
9+
}

0 commit comments

Comments
 (0)