mehmeterdogan / nobetci-eczane-api
Türkiye ve KKTC güncel nöbetçi eczane verilerine REST API üzerinden erişim sağlayan resmi PHP SDK.
Package info
github.com/mehmeterdogan/nobetci-eczane-api-php
pkg:composer/mehmeterdogan/nobetci-eczane-api
Requires
- php: ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4
- ext-curl: *
- ext-json: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-23 20:40:04 UTC
README
Türkiye ve KKTC genelindeki tüm güncel nöbetçi eczane verilerine, il/ilçe sorgularına ve koordinat bazlı en yakın eczane konumlarına programatik erişim sağlayan resmi PHP SDK (Composer Paketi).
✨ Özellikler
- 🐘 PHP 8+ Uyumlu: Strict Types, Match Expressions, Constructor Promotion vb. modern standartlar.
- 🚀 Sıfır Dış Bağımlılık (Zero Dependencies): Native cURL ile ultra hafif (< 15 KB) ve hızlı çalışır.
- 📦 Tüm Framework'lerle Uyumlu: Laravel, Symfony, WordPress, CodeIgniter veya Saf (Native) PHP projelerinde doğrudan kullanılabilir.
- 🛡️ Özelleştirilmiş İstisna Yönetimi:
AuthenticationException,RateLimitException,InvalidRequestExceptionvb. - ⚡ Akıllı Önbellek Mimarisi: Milisaniyeler seviyesinde yanıt süreleri.
📦 Kurulum
Composer aracılığıyla projenize ekleyin:
composer require mehmeterdogan/nobetci-eczane-api
🔑 Hızlı Başlangıç
API anahtarınızı Eczaneler.ORG üzerinden veya Telegram (@mehmeterdogannet) üzerinden ücretsiz test anahtarı alarak temin edebilirsiniz.
<?php require_once __DIR__ . '/vendor/autoload.php'; use Eczaneler\NobetciEczane\EczaneClient; use Eczaneler\NobetciEczane\Exceptions\EczaneApiException; $client = new EczaneClient('SENIN_API_ANAHTARIN'); try { // 1. İstanbul'daki (34) nöbetçi eczaneleri çek $istanbul = $client->getSentryByCity(34, limit: 50); print_r($istanbul['data']); // 2. Kadıköy'deki (440) nöbetçi eczaneleri çek $kadikoy = $client->getSentryByDistrict('istanbul', 'kadikoy'); print_r($kadikoy['data']); // 3. Konumunuza en yakın 5 nöbetçi eczane $enYakin = $client->getNearby( lat: 41.0082, lon: 28.9784, isSentry: true, limit: 5 ); print_r($enYakin['data']); } catch (EczaneApiException $e) { echo "Hata [{$e->getCode()}]: " . $e->getMessage(); }
📖 API Metodları Referansı
1. getSentryPharmacies(int $page = 1, int $limit = 25)
Türkiye genelinde o gün nöbetçi olan tüm eczaneleri sayfalı listeler.
$result = $client->getSentryPharmacies(page: 1, limit: 50); echo "Toplam nöbetçi: " . $result['pagination']['total'];
2. getSentryByCity(string|int $city, int $page = 1, int $limit = 25)
Belirtilen ildeki nöbetçi eczaneleri listeler. $city parametresi plaka ID'si (34) veya slug ("istanbul") olabilir.
$result = $client->getSentryByCity('ankara', limit: 30);
3. getSentryByDistrict(string|int $city, string|int $district, int $page = 1, int $limit = 25)
Belirtilen ilçedeki nöbetçi eczaneleri listeler.
$result = $client->getSentryByDistrict(34, 440); // 34: İstanbul, 440: Kadıköy // Veya slug ile: $result = $client->getSentryByDistrict('izmir', 'karsiyaka');
4. getNearby(float $lat, float $lon, bool $isSentry = true, int $limit = 10, ?float $radius = null)
Koordinatlara göre en yakından uzağa doğru eczaneleri listeler.
$result = $client->getNearby( lat: 37.0342, lon: 35.3081, isSentry: true, limit: 10 );
5. getCities() & getDistricts(int $cityId)
Sistemdeki tüm il ve ilçe ID/Slug listesini getirir.
$iller = $client->getCities(); $ilceler = $client->getDistricts(34); // İstanbul ilçeleri
6. getAccountInfo()
API anahtarınıza ait kalan kullanım, kota ve yetki durumunu döner.
$account = $client->getAccountInfo(); echo "Kalan Gün: " . $account['remaining_days'];
7. updateWhitelist(string $ips)
Dinamik IP Whitelist tanımını günceller.
$client->updateWhitelist('5.132.*');
8. getAllPharmacies(int $page = 1, int $limit = 25) (Premium)
Türkiye'deki tüm aktif eczane verilerine (+30.000) erişim sağlar.
$result = $client->getAllPharmacies(page: 1, limit: 50);
⚡ Laravel Entegrasyon Örneği
Laravel Controller içerisinde doğrudan kullanım:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use Eczaneler\NobetciEczane\EczaneClient; use Eczaneler\NobetciEczane\Exceptions\EczaneApiException; class PharmacyController extends Controller { private EczaneClient $client; public function __construct() { $this->client = new EczaneClient(config('services.eczaneler.api_key')); } public function getSentryByCity(Request $request, string $city): JsonResponse { try { $limit = (int)$request->query('limit', 25); $page = (int)$request->query('page', 1); $data = $this->client->getSentryByCity($city, $page, $limit); return response()->json($data); } catch (EczaneApiException $e) { return response()->json([ 'error' => $e->getMessage() ], $e->getCode() ?: 500); } } }
🛡️ Hata Yönetimi
use Eczaneler\NobetciEczane\Exceptions\AuthenticationException; use Eczaneler\NobetciEczane\Exceptions\RateLimitException; use Eczaneler\NobetciEczane\Exceptions\InvalidRequestException; use Eczaneler\NobetciEczane\Exceptions\EczaneApiException; try { $data = $client->getSentryByCity(34); } catch (AuthenticationException $e) { // 401 Hatası: API Anahtarı geçersiz } catch (RateLimitException $e) { // 429 Hatası: İstek limiti aşıldı echo "Sıfırlanma süresi: " . $e->getResetInSeconds() . "s"; } catch (InvalidRequestException $e) { // 400 Hatası: Parametreler eksik veya hatalı } catch (EczaneApiException $e) { // Genel API Hatası }
📄 Lisans
Bu paket MIT Lisansı altında sunulmaktadır.
💬 Destek ve İletişim
- Dokümantasyon: eczaneler.org/nobetci-eczane-api
- Telegram Destek: @mehmeterdogannet
- Web Sitesi: eczaneler.org