Skip to content

Commit 7f00321

Browse files
committed
Update README for improved clarity and configuration examples
1 parent 6babdc3 commit 7f00321

1 file changed

Lines changed: 15 additions & 43 deletions

File tree

README.md

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ $discogs = DiscogsClientFactory::createWithPersonalAccessToken('token');
6363
$collection = $discogs->listCollectionFolders('your-username');
6464
$wantlist = $discogs->getUserWantlist('your-username');
6565

66-
// Add to collection with named parameters
66+
// Add to the collection with named parameters
6767
$discogs->addToCollection(
6868
username: 'your-username',
6969
folderId: 1,
@@ -107,46 +107,37 @@ $identity = $discogs->getIdentity();
107107
- **php** ^8.1
108108
- **guzzlehttp/guzzle** ^6.5 || ^7.0
109109

110-
## ⚙️ Advanced Configuration
110+
## ⚙️ Configuration
111111

112-
### Option 1: Simple Configuration (Recommended)
112+
### Configuration
113113

114-
For basic customizations like timeout or User-Agent, use the DiscogsClientFactory:
114+
**Simple (works out of the box):**
115115

116116
```php
117117
use Calliostro\Discogs\DiscogsClientFactory;
118118

119-
$discogs = DiscogsClientFactory::create([
120-
'timeout' => 30,
121-
'headers' => [
122-
'User-Agent' => 'MyApp/1.0 (+https://myapp.com)',
123-
]
124-
]);
119+
$discogs = DiscogsClientFactory::create();
125120
```
126121

127-
### Option 2: Advanced Guzzle Configuration
128-
129-
For advanced HTTP client features (middleware, interceptors, etc.), create your own Guzzle client:
122+
**Advanced (middleware, custom options, etc.):**
130123

131124
```php
132-
use GuzzleHttp\Client;
133-
use Calliostro\Discogs\DiscogsClient;
134125
use Calliostro\Discogs\DiscogsClientFactory;
126+
use GuzzleHttp\{HandlerStack, Middleware};
135127

136-
$httpClient = new Client([
137-
'base_uri' => 'https://api.discogs.com/',
128+
$handler = HandlerStack::create();
129+
$handler->push(Middleware::retry(
130+
fn ($retries, $request, $response) => $retries < 3 && $response?->getStatusCode() === 429,
131+
fn ($retries) => 1000 * 2 ** ($retries + 1) // Rate limit handling
132+
));
133+
134+
$discogs = DiscogsClientFactory::create([
138135
'timeout' => 30,
139-
'connect_timeout' => 10,
136+
'handler' => $handler,
140137
'headers' => [
141138
'User-Agent' => 'MyApp/1.0 (+https://myapp.com)',
142139
]
143140
]);
144-
145-
// Direct usage
146-
$discogs = new DiscogsClient($httpClient);
147-
148-
// Or via DiscogsClientFactory
149-
$discogs = DiscogsClientFactory::create($httpClient);
150141
```
151142

152143
> 💡 **Note:** By default, the client uses `DiscogsClient/4.0.0 +https://github.com/calliostro/php-discogs-api` as User-Agent. You can override this by setting custom headers as shown above.
@@ -243,25 +234,6 @@ $identity = $discogs->getIdentity();
243234
echo "Hello " . $identity['username'];
244235
```
245236

246-
## 🛡️ Rate Limiting (Optional)
247-
248-
Quick demo for handling Discogs rate limits (60/min authenticated, 25/min unauthenticated) with Guzzle middleware:
249-
250-
```php
251-
use GuzzleHttp\{HandlerStack, Middleware};
252-
use Calliostro\Discogs\DiscogsClientFactory;
253-
254-
$handler = HandlerStack::create();
255-
$handler->push(Middleware::retry(
256-
fn ($retries, $request, $response) => $retries < 3 && $response?->getStatusCode() === 429,
257-
fn ($retries) => 1000 * 2 ** ($retries + 1) // 2s, 4s, 8s delays
258-
), 'rate_limit');
259-
260-
$discogs = DiscogsClientFactory::create(['handler' => $handler]);
261-
```
262-
263-
> 💡 **Note:** For long-running batches, consider optimized solutions with retry backoff caps to prevent exponentially increasing delays.
264-
265237
## 🧪 Testing
266238

267239
### Quick Testing Commands

0 commit comments

Comments
 (0)