You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
12
20
@@ -23,7 +31,10 @@ $api = new OpenWeatherMap('yourapikey', [
23
31
Unit system used when retrieving data.
24
32
Affects temperature and speed values.
25
33
26
-
Available options are `metric`, `imperial` and `standard`.
34
+
Available options:
35
+
-`metric`
36
+
-`imperial`
37
+
-`standard`
27
38
28
39
Example:
29
40
@@ -54,147 +65,96 @@ $api = new OpenWeatherMap('yourapikey', [
54
65
]);
55
66
```
56
67
57
-
### `httpClientBuilder`
58
-
59
-
Configure a PSR-18 HTTP client and PSR-17 HTTP factory adapters.
68
+
## Methods
60
69
61
-
By default, and for convenience, this library makes use of the [HTTPlug's Discovery](https://github.com/php-http/discovery) library.
62
-
This means that it will automatically find and install a well-known PSR-18 and PSR-17 implementation for you (if one was not found on your project):
63
-
-[List of PSR-18 compatible implementations](https://packagist.org/providers/psr/http-client-implementation)
64
-
-[List of PSR-17 compatible implementations](https://packagist.org/providers/psr/http-factory-implementation)
70
+
> [!IMPORTANT]
71
+
> The [PHP API SDK](https://github.com/programmatordev/php-api-sdk) library was used to create the OpenWeatherMap PHP API.
72
+
> To get to know about all available methods, make sure to check the documentation [here](https://github.com/programmatordev/php-api-sdk?tab=readme-ov-file#php-api-sdk).
65
73
66
-
If you want to manually provide one, it should look like this:
74
+
The following sections have examples of some of the most important methods,
75
+
particularly related with the configuration of the client, cache and logger.
67
76
68
-
```php
69
-
use ProgrammatorDev\OpenWeatherMap\Config;
70
-
use ProgrammatorDev\OpenWeatherMap\HttpClient\HttpClientBuilder;
71
-
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
77
+
### `setClientBuilder`
72
78
73
-
$httpClient = new Symfony\Component\HttpClient\Psr18Client();
74
-
$httpFactory = new Nyholm\Psr7\Factory\Psr17Factory();
> All `HttpClientBuilder` parameters are optional.
93
-
> If you only pass an HTTP client, an HTTP factory will still be discovered for you.
94
-
95
-
#### Plugin System
96
-
97
-
[HTTPlug's plugin system](https://docs.php-http.org/en/latest/plugins/index.html) is also implemented to give you full control of what happens during the request/response workflow.
98
-
99
-
For example, to attempt to re-send a request in case of failure (service temporarily down because of unreliable connections/servers, etc.),
100
-
the [RetryPlugin](https://docs.php-http.org/en/latest/plugins/retry.html) can be added:
85
+
If you don't want to rely on the discovery of implementations, you can set the ones you want:
101
86
102
87
```php
103
-
use ProgrammatorDev\OpenWeatherMap\Config;
104
-
use ProgrammatorDev\OpenWeatherMap\HttpClient\HttpClientBuilder;
88
+
use Nyholm\Psr7\Factory\Psr17Factory;
105
89
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
90
+
use Symfony\Component\HttpClient\Psr18Client;
106
91
107
-
$httpClientBuilder = new HttpClientBuilder();
108
-
$httpClientBuilder->addPlugin(
109
-
new \Http\Client\Common\Plugin\RetryPlugin([
110
-
'retries' => 3
111
-
])
112
-
);
92
+
$api = new OpenWeatherMap('yourapikey');
113
93
114
-
$openWeatherMap = new OpenWeatherMap(
115
-
new Config([
116
-
'applicationKey' => 'yourappkey',
117
-
'httpClientBuilder' => $httpClientBuilder
118
-
])
94
+
$client = new Psr18Client();
95
+
$requestFactory = $streamFactory = new Psr17Factory();
96
+
97
+
$api->setClientBuilder(
98
+
new ClientBuilder(
99
+
client: $client,
100
+
requestFactory: $requestFactory,
101
+
streamFactory: $streamFactory
102
+
)
119
103
);
120
104
```
121
105
122
-
You can check their [plugin list](https://docs.php-http.org/en/latest/plugins/index.html) or [create your own](https://docs.php-http.org/en/latest/plugins/build-your-own.html).
123
-
124
-
> **Note**
125
-
> This library already uses HTTPlug's `CachePlugin` and `LoggerPlugin`.
126
-
> Re-adding those may lead to an unexpected behaviour.
127
-
128
-
### `cache`
106
+
Check the full documentation [here](https://github.com/programmatordev/php-api-sdk?tab=readme-ov-file#http-client-psr-18-and-http-factories-psr-17).
129
107
130
-
Configure a PSR-6 cache adapter.
108
+
### `setCacheBuilder`
131
109
132
-
By default, no responses are cached.
133
-
To enable cache, you must provide a PSR-6 implementation:
134
-
-[List of PSR-6 compatible implementations](https://packagist.org/providers/psr/cache-implementation)
110
+
This library allows configuring the cache layer of the client for making API requests.
111
+
It uses a standard PSR-6 implementation and provides methods to fine-tune how HTTP caching behaves:
0 commit comments