Skip to content

Commit a7c184c

Browse files
Update README and Fetcher/HttpClient classes for improved error handling and requirements
- Added requirements section to README, specifying PHP version and necessary extensions. - Updated installation instructions to use Composer instead of npm. - Refactored Fetcher and HttpClient classes to replace CurlException with HttpException for better error handling. - Modified Fetcher to allow injection of a custom PSR-18 HTTP client.
1 parent 9058013 commit a7c184c

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ You can send text messages(SMS, LMS, MMS), Kakao friendtalk(include notification
44
package.
55
This package is 100% compatible with SOLAPI family services (Purple Book, Nurigo, etc.).
66

7+
## Requirements
8+
9+
- PHP 7.1 or higher
10+
- `ext-json` extension
11+
- `allow_url_fopen` enabled in php.ini (for the default HTTP client)
12+
13+
> **Note:** If `allow_url_fopen` is disabled in your environment (common in shared hosting), you can inject a custom PSR-18 HTTP client (e.g., Guzzle) via the `Fetcher` constructor or `getInstance()` method.
14+
715
## Installing
816

9-
To use the SDK, simply use npm package manager CLI. Type the following into a terminal window.
17+
To use the SDK, simply use Composer. Type the following into a terminal window.
1018

1119
```bash
1220
composer require solapi/sdk

src/Libraries/Fetcher.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Nyholm\Psr7\Request;
99
use Nyholm\Psr7\Uri;
1010
use Nurigo\Solapi\Exceptions\BaseException;
11-
use Nurigo\Solapi\Exceptions\CurlException;
11+
use Nurigo\Solapi\Exceptions\HttpException;
1212
use Nurigo\Solapi\Exceptions\UnknownException;
1313
use Nurigo\Solapi\Models\Response\ErrorResponse;
1414

@@ -22,12 +22,11 @@ class Fetcher
2222

2323
const API_URL = "https://api.solapi.com";
2424
const DEFAULT_TIMEOUT = 30.0;
25-
const DEFAULT_CONNECT_TIMEOUT = 10.0;
2625

27-
public static function getInstance(string $apiKey, string $apiSecretKey): Fetcher
26+
public static function getInstance(string $apiKey, string $apiSecretKey, ?ClientInterface $httpClient = null): Fetcher
2827
{
2928
if (!isset(Fetcher::$singleton)) {
30-
Fetcher::$singleton = new Fetcher($apiKey, $apiSecretKey);
29+
Fetcher::$singleton = new Fetcher($apiKey, $apiSecretKey, $httpClient);
3130
}
3231
return Fetcher::$singleton;
3332
}
@@ -38,7 +37,6 @@ public function __construct(string $apiKey, string $apiSecretKey, ?ClientInterfa
3837
$this->apiSecretKey = $apiSecretKey;
3938
$this->httpClient = $httpClient ?? new HttpClient([
4039
'timeout' => self::DEFAULT_TIMEOUT,
41-
'connect_timeout' => self::DEFAULT_CONNECT_TIMEOUT,
4240
'verify' => true,
4341
]);
4442
}
@@ -54,7 +52,7 @@ public function __destruct()
5452
* @param string $uri
5553
* @param mixed $data
5654
* @return mixed
57-
* @throws Exception|CurlException|BaseException|UnknownException
55+
* @throws Exception|HttpException|BaseException|UnknownException
5856
*/
5957
public function request(string $method, string $uri, $data = false)
6058
{
@@ -103,7 +101,7 @@ public function request(string $method, string $uri, $data = false)
103101
return $jsonResult;
104102

105103
} catch (ClientExceptionInterface $e) {
106-
throw new CurlException($e->getMessage(), null, null, $e);
104+
throw new HttpException($e->getMessage(), null, null, $e);
107105
}
108106
}
109107
}

src/Libraries/HttpClient.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use Nyholm\Psr7\Response;
9-
use Nurigo\Solapi\Exceptions\CurlException;
9+
use Nurigo\Solapi\Exceptions\HttpException;
1010

1111
class HttpClient implements ClientInterface
1212
{
1313
protected $timeout;
14-
protected $connectTimeout;
1514
protected $verifySsl;
1615

1716
public function __construct(array $options = [])
1817
{
1918
$this->timeout = $options['timeout'] ?? 30.0;
20-
$this->connectTimeout = $options['connect_timeout'] ?? 10.0;
2119
$this->verifySsl = $options['verify'] ?? true;
2220
}
2321

@@ -66,11 +64,8 @@ public function sendRequest(RequestInterface $request): ResponseInterface
6664

6765
if ($responseBody === false) {
6866
$error = error_get_last();
69-
throw new CurlException(
70-
$error['message'] ?? 'HTTP request failed: ' . $url,
71-
null,
72-
null,
73-
null
67+
throw new HttpException(
68+
$error['message'] ?? 'HTTP request failed: ' . $url
7469
);
7570
}
7671

0 commit comments

Comments
 (0)