Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fovelas committed Feb 18, 2023
1 parent e6507ab commit 3bd17a1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Kandilli Rasathanesi'nin yayınladığı Türkiye geneli tüm depremler için RE
| --------- | ------------------ | --------------------------------------------- |
| year | Yok (Zorunlu) | Çekmek istediğiniz yıl. |
| month | Yok (Zorunlu) | Çekmek istediğiniz ay. |
| mag | 0 | Bu büyüklük ve üzerindeki depremleri getirir. |
| limit | 50 | Maksimum kaç tane veri çekileceğini belirler. |
| city | Yok (Tüm şehirler) | Çekmek istediğiniz şehir. |

Expand All @@ -43,16 +44,26 @@ https://api.hknsoft.com/earthquake/v1/get?year=2023&month=01&limit=500

Sadece İstanbul'da gerçekleşen depremleri getirir.

**Şehir isimlerinde türkçe karakter kullanılmamalı ve hepsi küçük harf olmalıdır.**
**Uyarı:** Şehir isimlerinde türkçe karakter kullanılmamalı ve hepsi küçük harf olmalıdır.
~~~
https://api.hknsoft.com/earthquake/v1/get?year=2023&month=01&limit=500&city=istanbul
~~~

İstanbul'da gerçekleşen 5.4 ve üzeri büyüklükteki depremleri getirir.

~~~
https://api.hknsoft.com/earthquake/v1/get?year=2023&month=01&mag=5.4&limit=500&city=istanbul
~~~

Son 24 saatte gerçekleşen depremleri getirir.
~~~
https://api.hknsoft.com/earthquake/v1/last24hours
~~~

~~~
https://api.hknsoft.com/earthquake/v1/last24hours?mag=7.9&limit=50
~~~

~~~
https://api.hknsoft.com/earthquake/v1/last24hours?limit=500&city=bursa
~~~
Expand Down
12 changes: 9 additions & 3 deletions v1/classes/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function get_xml($date)
* @param string $filter_city
* @return array
*/
public function parse($date, $limit = 50, $filter_city = 'none')
public function parse($date, $limit = 50, $filter_city = 'none', $filter_magnitude = 0)
{
$xml_res = $this->get_xml($date);

Expand Down Expand Up @@ -95,6 +95,8 @@ public function parse($date, $limit = 50, $filter_city = 'none')
$city = 'YOK';
}

$magnitude = doubleval($earthquake['mag']);

$earthquake_obj = array(
'date' => $date,
'time' => $time,
Expand All @@ -107,10 +109,14 @@ public function parse($date, $limit = 50, $filter_city = 'none')
);

if ($filter_city == 'none') {
$earthquakes_array[] = $earthquake_obj;
if ($magnitude >= $filter_magnitude) {
$earthquakes_array[] = $earthquake_obj;
}
} else {
if (strtolower($city) == $filter_city) {
$earthquakes_array[] = $earthquake_obj;
if ($magnitude >= $filter_magnitude) {
$earthquakes_array[] = $earthquake_obj;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions v1/classes/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ class Response
{
public static $ERR_MISSING_PARAMS = 'ERR_MISSING_PARAMS'; // 101
public static $ERR_INVALID_LIMIT = 'ERR_INVALID_LIMIT'; // 102
public static $ERR_INVALID_MAGNITUDE = 'ERR_INVALID_MAGNITUDE'; // 103
public static $ERR_UNNECESSARY_PARAMETER = 'ERR_UNNECESSARY_PARAMETER'; // 104

public static $ERR_NO_RESPONSE = 'ERR_NO_RESPONSE'; // 404
}
4 changes: 2 additions & 2 deletions v1/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

return array(
'app_name' => 'Türkiye Deprem API',
'version' => '0.0.1-beta',
'latest_update' => '07.01.2023 19:18',
'version' => '1.0.2-beta',
'latest_update' => '18.02.2023 02:25',
'github' => 'https://github.com/hakansrndk60/php-deprem-api',
'warning' => 'Söz konusu bilgi, veri ve haritalar Boğaziçi Üniversitesi Rektörlüğü’nün yazılı izni ve onayı olmadan herhangi bir şekilde ticari amaçlı kullanılamaz.',
'reference' => 'http://www.koeri.boun.edu.tr/scripts/lasteq.asp',
Expand Down
3 changes: 2 additions & 1 deletion v1/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

$f3 = Base::instance();

$f3->route('GET /',
$f3->route(
'GET /',
function () {
$config = include './config/config.php';
$res = array(
Expand Down
46 changes: 42 additions & 4 deletions v1/routes/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function error($message, $code, $detail = null)

$f3 = Base::instance();

$f3->route('GET /get',
$f3->route(
'GET /get',
function ($f3, $params) {
$GLOBALS['params'] = $params;

Expand Down Expand Up @@ -66,8 +67,22 @@ function ($f3, $params) {
$city = 'none';
}

if (isset($_GET['mag'])) {
$mag = doubleval($_GET['mag']);

if ($mag < 0) {
error(Response::$ERR_INVALID_MAGNITUDE, 103, 'magnitude must be bigger than zero (0)');
return;
} else if ($mag > 11) {
error(Response::$ERR_INVALID_MAGNITUDE, 103, 'magnitude must be smaller than eleven (11)');
return;
}
} else {
$mag = 0;
}

$parser = new Parser();
$data = $parser->parse($date, $limit, $city);
$data = $parser->parse($date, $limit, $city, $mag);

if ($data) {
echo json_encode($data, JSON_UNESCAPED_UNICODE);
Expand All @@ -77,12 +92,21 @@ function ($f3, $params) {
}
);

$f3->route('GET /last24hours',
$f3->route(
'GET /last24hours',
function ($f3, $params) {
$GLOBALS['params'] = $params;

$date = 'son24saat';

if (isset($_GET['year'])) {
error(Response::$ERR_UNNECESSARY_PARAMETER, 104, 'year parameter is unnecessary');
return;
} else if (isset($_GET['month'])) {
error(Response::$ERR_UNNECESSARY_PARAMETER, 104, 'month parameter is unnecessary');
return;
}

if (isset($_GET['limit'])) {
$limit = intval($_GET['limit']);

Expand All @@ -103,8 +127,22 @@ function ($f3, $params) {
$city = 'none';
}

if (isset($_GET['mag'])) {
$mag = doubleval($_GET['mag']);

if ($mag < 0) {
error(Response::$ERR_INVALID_MAGNITUDE, 103, 'magnitude must be bigger than zero (0)');
return;
} else if ($mag > 11) {
error(Response::$ERR_INVALID_MAGNITUDE, 103, 'magnitude must be smaller than eleven (11)');
return;
}
} else {
$mag = 0;
}

$parser = new Parser();
$data = $parser->parse($date, $limit, $city);
$data = $parser->parse($date, $limit, $city, $mag);

if ($data) {
echo json_encode($data, JSON_UNESCAPED_UNICODE);
Expand Down

0 comments on commit 3bd17a1

Please sign in to comment.