Installation
composer require atm/my_theresa_api
Publish the configuration file:
php artisan vendor:publish --provider="Atm\MyTheresaApi\MyTheresaApiServiceProvider" --tag="config"
First Use Case: Fetching Product Data
Initialize the client in config/my_theresa_api.php:
'client' => [
'client_id' => env('MY_THERESA_CLIENT_ID'),
'client_secret' => env('MY_THERESA_CLIENT_SECRET'),
'api_url' => env('MY_THERESA_API_URL', 'https://api.mytheresa.com'),
],
Use the facade in a controller or service:
use Atm\MyTheresaApi\Facades\MyTheresaApi;
$products = MyTheresaApi::get('/products', [
'filter' => ['category' => 'women'],
'limit' => 10
]);
Key Files to Review
src/Facades/MyTheresaApi.php (Facade entry point)src/Client.php (Core HTTP client logic)src/Exceptions/ (Custom exceptions for error handling)MyTheresaApi::setToken($refreshToken); // Manually set if needed
$response = MyTheresaApi::get('/protected/endpoint'); // Auto-handles token refresh
MyTheresaApi::onTokenRefreshed(function ($newToken) {
Log::debug("Token refreshed. New token: " . substr($newToken, 0, 10) . "...");
});
$paginator = MyTheresaApi::getPaginated('/products', [
'limit' => 50,
'page' => 1
]);
foreach ($paginator as $product) {
// Process each product
}
MyTheresaApi::withRetry(3, 1000)->get('/products'); // Retry 3 times with 1s delay
$product = MyTheresaApi::get('/products/123')->mapToProduct();
MyTheresaApi::extendMapper('product', function ($data) {
return (object) array_merge($data, [
'formatted_price' => '$' . number_format($data->price / 100, 2)
]);
});
MyTheresaApi::listenForWebhooks('inventory_update', function ($payload) {
// Handle inventory updates
});
$isValid = MyTheresaApi::verifyWebhookSignature(
$request->getContent(),
$request->header('X-Signature')
);
MyTheresaApi::dispatchSync('/products')->onQueue('mytheresa');
$products = Cache::remember('mytheresa_products', now()->addHours(1), function () {
return MyTheresaApi::get('/products');
});
class MyTheresaScoutEngine extends ScoutEngine {
public function search($query) {
return MyTheresaApi::search($query);
}
}
MyTheresaApi::shouldReceive('get')
->once()
->with('/products/123')
->andReturn((object) ['id' => 123, 'name' => 'Test Product']);
Token Expiry Handling
.env has:
MY_THERESA_TOKEN_REFRESH_URL=https://api.mytheresa.com/oauth/token
'debug' => env('APP_DEBUG', false),
to log token refreshes.Rate Limiting
MyTheresaApi::withRateLimit(100, 60)->get('/products');
Data Format Inconsistencies
snake_case while others use camelCase. Normalize with:
MyTheresaApi::setNormalizeKeys(true); // Converts all keys to snake_case
Webhook Idempotency
webhook_signature table to track processed payloads:
MyTheresaApi::markWebhookAsProcessed($payload['id'], $signature);
MyTheresaApi::setLogLevel(Log::DEBUG);
$response = MyTheresaApi::get('/products', [], true); // Returns raw response
| Error Code | Cause | Solution |
|---|---|---|
| 401 | Invalid token | Refresh token or check credentials |
| 429 | Rate limit exceeded | Implement retry logic |
| 500 | Server error | Check MyTheresa status or contact support |
Custom Endpoints Add a new endpoint class:
namespace Atm\MyTheresaApi\Endpoints;
class CustomEndpoint extends Endpoint {
protected $path = '/custom/path';
protected $methods = ['GET', 'POST'];
}
Register it in config/my_theresa_api.php:
'endpoints' => [
'custom' => \Atm\MyTheresaApi\Endpoints\CustomEndpoint::class,
],
Middleware Attach middleware to all requests:
MyTheresaApi::addMiddleware(function ($request) {
$request->headers->set('X-Custom-Header', 'value');
});
Event Listeners Extend the event system:
MyTheresaApi::listen('before_request', function ($request) {
// Modify request before sending
});
How can I help you explore Laravel packages today?