Skip to content

Commit 44364e3

Browse files
hasokericPhil Sturgeon
authored andcommitted
added: settings in config to set table names for keys, limits, logs & minor cleanup
1 parent ee778d6 commit 44364e3

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

application/config/rest.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@
6161
*/
6262
$config['rest_database_group'] = 'default';
6363

64+
/*
65+
|--------------------------------------------------------------------------
66+
| REST API Keys Table Name
67+
|--------------------------------------------------------------------------
68+
|
69+
| The table name in your database that stores API Keys.
70+
|
71+
| 'keys'
72+
|
73+
*/
74+
$config['rest_keys_table'] = 'keys';
75+
6476
/*
6577
|--------------------------------------------------------------------------
6678
| REST Enable Keys
@@ -98,17 +110,28 @@
98110

99111
/*
100112
|--------------------------------------------------------------------------
101-
| REST Key Length
113+
| REST API Key Variable
102114
|--------------------------------------------------------------------------
103115
|
104-
| How long should created keys be? Double check this in your db schema.
116+
| Which variable will provide us the API Key
105117
|
106-
| Default: 32
107-
| Max: 40
118+
| Default: X-API-KEY
108119
|
109120
*/
110121
$config['rest_key_name'] = 'X-API-KEY';
111122

123+
/*
124+
|--------------------------------------------------------------------------
125+
| REST API Logs Table Name
126+
|--------------------------------------------------------------------------
127+
|
128+
| The table name in your database that stores logs.
129+
|
130+
| 'logs'
131+
|
132+
*/
133+
$config['rest_logs_table'] = 'logs';
134+
112135
/*
113136
|--------------------------------------------------------------------------
114137
| REST Enable Logging
@@ -135,6 +158,18 @@
135158
*/
136159
$config['rest_enable_logging'] = FALSE;
137160

161+
/*
162+
|--------------------------------------------------------------------------
163+
| REST API Limits Table Name
164+
|--------------------------------------------------------------------------
165+
|
166+
| The table name in your database that stores limits.
167+
|
168+
| 'logs'
169+
|
170+
*/
171+
$config['rest_limits_table'] = 'limits';
172+
138173
/*
139174
|--------------------------------------------------------------------------
140175
| REST Enable Limits

application/libraries/REST_Controller.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ function __construct()
9595
// Which format should the data be returned in?
9696
$this->request->lang = $this->_detect_lang();
9797

98-
// Load DB if its enabled
99-
if (config_item('rest_database_group') AND (config_item('rest_enable_keys') OR config_item('rest_enable_logging')))
100-
{
101-
$this->rest->db = $this->load->database(config_item('rest_database_group'), TRUE);
102-
}
103-
104-
// Checking for keys? GET TO WORK!
105-
if (config_item('rest_enable_keys'))
106-
{
107-
$this->_allow = $this->_detect_api_key();
108-
}
98+
// Load DB if its enabled
99+
if (config_item('rest_database_group') AND (config_item('rest_enable_keys') OR config_item('rest_enable_logging')))
100+
{
101+
$this->rest->db = $this->load->database(config_item('rest_database_group'), TRUE);
102+
}
103+
104+
// Checking for keys? GET TO WORK!
105+
if (config_item('rest_enable_keys'))
106+
{
107+
$this->_allow = $this->_detect_api_key();
108+
}
109109
}
110110

111111
/*
@@ -319,7 +319,7 @@ private function _detect_api_key()
319319
// Find the key from server or arguments
320320
if ($key = isset($this->_args['API-Key']) ? $this->_args['API-Key'] : $this->input->server($key_name))
321321
{
322-
if ( ! $row = $this->rest->db->where('key', $key)->get('keys')->row())
322+
if ( ! $row = $this->rest->db->where('key', $key)->get(config_item('rest_keys_table'))->row())
323323
{
324324
return FALSE;
325325
}
@@ -377,7 +377,7 @@ private function _detect_lang()
377377
*/
378378
private function _log_request($authorized = FALSE)
379379
{
380-
return $this->rest->db->insert('logs', array(
380+
return $this->rest->db->insert(config_item('rest_logs_table'), array(
381381
'uri' => $this->uri->uri_string(),
382382
'method' => $this->request->method,
383383
'params' => serialize($this->_args),
@@ -410,7 +410,7 @@ private function _check_limit($controller_method)
410410
$result = $this->rest->db
411411
->where('uri', $this->uri->uri_string())
412412
->where('api_key', $this->rest->key)
413-
->get('limits')
413+
->get(config_item('rest_limits_table'))
414414
->row();
415415

416416
// No calls yet, or been an hour since they called
@@ -438,7 +438,7 @@ private function _check_limit($controller_method)
438438
->where('uri', $this->uri->uri_string())
439439
->where('api_key', $this->rest->key)
440440
->set('count', 'count + 1', FALSE)
441-
->update('limits');
441+
->update(config_item('limits'));
442442
}
443443

444444
return TRUE;

0 commit comments

Comments
 (0)