Skip to content

Commit 81bda25

Browse files
Merge pull request #16 from Palbahngmiyine/master
Release PHP SDK 5.0.2
2 parents c9dbff2 + 31d6430 commit 81bda25

File tree

6 files changed

+84
-8
lines changed

6 files changed

+84
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "solapi/sdk",
33
"description": "SOLAPI SDK for PHP",
4-
"version": "5.0.1",
4+
"version": "5.0.2",
55
"type": "library",
66
"license": "MIT",
77
"autoload": {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Nurigo\Solapi\Exceptions;
4+
5+
use Exception;
6+
7+
class UnknownException extends Exception
8+
{
9+
10+
/**
11+
* @var mixed
12+
*/
13+
public $response;
14+
15+
public function __construct($message = "", $errorResponse = null)
16+
{
17+
parent::__construct($message);
18+
$this->response = $errorResponse;
19+
}
20+
21+
/**
22+
* @return mixed|null
23+
*/
24+
public function getResponse()
25+
{
26+
return $this->response;
27+
}
28+
}

src/Libraries/Fetcher.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace Nurigo\Solapi\Libraries;
44

55
use Exception;
6+
use Nurigo\Solapi\Exceptions\BaseException;
67
use Nurigo\Solapi\Exceptions\CurlException;
8+
use Nurigo\Solapi\Exceptions\UnknownException;
9+
use Nurigo\Solapi\Models\Response\ErrorResponse;
710

811
/**
912
* @template T, R
@@ -51,7 +54,7 @@ public function __destruct()
5154
* @param string $method
5255
* @param string $uri
5356
* @param mixed $data
54-
* @throws Exception|CurlException CURL 관련된 Exception
57+
* @throws Exception|CurlException|BaseException|UnknownException CURL 관련된 Exception
5558
*/
5659
public function request(string $method, string $uri, $data = false)
5760
{
@@ -76,13 +79,22 @@ public function request(string $method, string $uri, $data = false)
7679
curl_setopt($curl, CURLOPT_URL, $url);
7780
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
7881
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
79-
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
80-
if (curl_error($curl)) {
82+
$result = curl_exec($curl);
83+
$jsonResult = json_decode($result);
84+
85+
if (curl_errno($curl)) {
8186
throw new CurlException(curl_error($curl));
8287
}
83-
$result = curl_exec($curl);
88+
89+
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
90+
if ($httpStatusCode >= 400 && $httpStatusCode <= 500) {
91+
$errorResponse = new ErrorResponse($jsonResult);
92+
throw new BaseException($errorResponse->errorMessage, $errorResponse->errorCode);
93+
} else if ($httpStatusCode != 200) {
94+
throw new UnknownException("Unknown Http Error Occurred", $result);
95+
}
8496
curl_close($curl);
8597

86-
return json_decode($result);
98+
return $jsonResult;
8799
}
88100
}

src/Models/Request/DefaultAgent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DefaultAgent
1616

1717
public function __construct()
1818
{
19-
$this->sdkVersion = 'php/5.0.0';
19+
$this->sdkVersion = 'php/5.0.2';
2020
$this->osPlatform = PHP_OS . " | " . phpversion();
2121
}
2222
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Nurigo\Solapi\Models\Response;
4+
5+
use JsonSerializable;
6+
7+
class ErrorResponse implements JsonSerializable
8+
{
9+
/**
10+
* @var string
11+
*/
12+
public $errorCode;
13+
14+
/**
15+
* @var string
16+
*/
17+
public $errorMessage;
18+
19+
/**
20+
* @param $value mixed
21+
*/
22+
public function __construct($value)
23+
{
24+
$this->errorCode = $value->errorCode;
25+
$this->errorMessage = $value->errorMessage;
26+
}
27+
28+
public function jsonSerialize(): array
29+
{
30+
return [
31+
"errorCode" => $this->errorCode,
32+
"errorMessage" => $this->errorMessage
33+
];
34+
}
35+
}

src/Services/SolapiMessageService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Nurigo\Solapi\Exceptions\BaseException;
88
use Nurigo\Solapi\Exceptions\CurlException;
99
use Nurigo\Solapi\Exceptions\MessageNotReceivedException;
10+
use Nurigo\Solapi\Exceptions\UnknownException;
1011
use Nurigo\Solapi\Libraries\Fetcher;
1112
use Nurigo\Solapi\Models\Message;
1213
use Nurigo\Solapi\Models\Request\GetGroupMessagesRequest;
@@ -41,7 +42,7 @@ public function __construct(string $apiKey, string $apiSecretKey)
4142
* @param Message|Message[] $messages
4243
* @param DateTime|null $scheduledDateTime
4344
* @return SendResponse
44-
* @throws Exception|CurlException|MessageNotReceivedException
45+
* @throws Exception|CurlException|MessageNotReceivedException|BaseException|UnknownException
4546
*/
4647
public function send($messages, DateTime $scheduledDateTime = null): SendResponse
4748
{

0 commit comments

Comments
 (0)