Skip to content

Commit fdc2e37

Browse files
committed
# v.1.1.5
* If the database library did not load, the error was shown * change API errors string * modify documentation
1 parent 99f105c commit fdc2e37

File tree

4 files changed

+164
-70
lines changed

4 files changed

+164
-70
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ user_guide_src/cilexer/pycilexer.egg-info/*
3030
*.sublime-project
3131
/tests/tests/
3232
/tests/results/
33+
34+
test/*

application/libraries/API_Controller.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @category Libraries
99
* @author Jeevan Lal
1010
* @license MIT
11-
* @version 1.1.0
11+
* @version 1.1.5
1212
*/
1313
class API_Controller extends CI_Controller
1414
{
@@ -178,10 +178,14 @@ public function _limit_method(array $data)
178178
if (!isset($data[1])) {
179179
$this->_response(['status' => FALSE, 'error' => 'Limit Type Required'], self::HTTP_BAD_REQUEST);
180180
}
181+
182+
if (!isset($this->db)) {
183+
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
184+
}
181185

182186
// check limit database table exists
183187
if (!$this->db->table_exists($this->API_LIMIT_TABLE_NAME)) {
184-
$this->_response(['status' => FALSE, 'error' => 'Create Limit Database Table'], self::HTTP_BAD_REQUEST);
188+
$this->_response(['status' => FALSE, 'error' => 'Create API Limit Database Table'], self::HTTP_BAD_REQUEST);
185189
}
186190

187191
$limit_num = $data[0]; // limit number
@@ -328,11 +332,15 @@ private function _api_key(array $key)
328332
if ($api_key != "table")
329333
{
330334
if ($HEADER_VALUE != $api_key) {
331-
$this->_response(['status' => FALSE, 'error' => 'API Key invalid'], self::HTTP_UNAUTHORIZED);
335+
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_UNAUTHORIZED);
332336
}
333337

334338
} else
335339
{
340+
if (!isset($this->db)) {
341+
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
342+
}
343+
336344
// check api key database table exists
337345
if (!$this->db->table_exists($this->API_KEYS_TABLE_NAME)) {
338346
$this->_response(['status' => FALSE, 'error' => 'Create API Key Database Table'], self::HTTP_BAD_REQUEST);
@@ -346,13 +354,13 @@ private function _api_key(array $key)
346354
$limit_query = $this->CI->db->get_where($this->API_KEYS_TABLE_NAME, $where_key_data);
347355
if (!$this->db->affected_rows() > 0)
348356
{
349-
$this->_response(['status' => FALSE, 'error' => 'API Key invalid'], self::HTTP_NOT_FOUND);
357+
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_NOT_FOUND);
350358
}
351359
}
352360

353361
} else
354362
{
355-
$this->_response(['status' => FALSE, 'error' => 'API Key Header Required'], self::HTTP_NOT_FOUND);
363+
$this->_response(['status' => FALSE, 'error' => 'Set API Key in Request Header'], self::HTTP_NOT_FOUND);
356364
}
357365
} else if (strtolower($api_key_type) == 'get') // // api key type `get`
358366
{
@@ -375,11 +383,15 @@ private function _api_key(array $key)
375383
if ($api_key != "table")
376384
{
377385
if ($get_param_value != $api_key) {
378-
$this->_response(['status' => FALSE, 'error' => 'API Key invalid'], self::HTTP_UNAUTHORIZED);
386+
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_UNAUTHORIZED);
379387
}
380388

381389
} else
382390
{
391+
if (!isset($this->db)) {
392+
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
393+
}
394+
383395
// check api key database table exists
384396
if (!$this->db->table_exists($this->API_KEYS_TABLE_NAME)) {
385397
$this->_response(['status' => FALSE, 'error' => 'Create API Key Database Table'], self::HTTP_BAD_REQUEST);
@@ -393,7 +405,7 @@ private function _api_key(array $key)
393405
$limit_query = $this->CI->db->get_where($this->API_KEYS_TABLE_NAME, $where_key_data);
394406
if (!$this->db->affected_rows() > 0)
395407
{
396-
$this->_response(['status' => FALSE, 'error' => 'API Key invalid'], self::HTTP_NOT_FOUND);
408+
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_NOT_FOUND);
397409
}
398410
}
399411
} else
@@ -421,11 +433,15 @@ private function _api_key(array $key)
421433
if ($api_key != "table")
422434
{
423435
if ($get_param_value != $api_key) {
424-
$this->_response(['status' => FALSE, 'error' => 'API Key invalid'], self::HTTP_UNAUTHORIZED);
436+
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_UNAUTHORIZED);
425437
}
426438

427439
} else
428440
{
441+
if (!isset($this->db)) {
442+
$this->_response(['status' => FALSE, 'error' => 'Load CodeIgniter Database Library'], self::HTTP_BAD_REQUEST);
443+
}
444+
429445
// check api key database table exists
430446
if (!$this->db->table_exists($this->API_KEYS_TABLE_NAME)) {
431447
$this->_response(['status' => FALSE, 'error' => 'Create API Key Database Table'], self::HTTP_BAD_REQUEST);
@@ -439,7 +455,7 @@ private function _api_key(array $key)
439455
$limit_query = $this->CI->db->get_where($this->API_KEYS_TABLE_NAME, $where_key_data);
440456
if (!$this->db->affected_rows() > 0)
441457
{
442-
$this->_response(['status' => FALSE, 'error' => 'API Key invalid'], self::HTTP_NOT_FOUND);
458+
$this->_response(['status' => FALSE, 'error' => 'API Key Invalid'], self::HTTP_NOT_FOUND);
443459
}
444460
}
445461
} else

fix_bug.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Fix Bug
2+
3+
## v.1.1.5
4+
5+
* If the database library did not load, the error was shown
6+
* change API errors string
7+
* modify documentation

0 commit comments

Comments
 (0)