Skip to content

Commit

Permalink
Update codeigniter-restserver and tests
Browse files Browse the repository at this point in the history
codeigniter-restserver 2015/11/15 master abce915786a7667b9150105df27039b7e4209110
  • Loading branch information
kenjis committed Nov 15, 2015
1 parent ddd61bc commit 1a33312
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 162 deletions.
37 changes: 35 additions & 2 deletions application/config/rest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/*
|--------------------------------------------------------------------------
| REST Format
| REST Output Format
|--------------------------------------------------------------------------
|
| The default format of the response
Expand All @@ -31,6 +31,29 @@
*/
$config['rest_default_format'] = 'json';

/*
|--------------------------------------------------------------------------
| REST Supported Output Formats
|--------------------------------------------------------------------------
|
| The following setting contains a list of the supported/allowed formats.
| You may remove those formats that you don't want to use.
| If the default format $config['rest_default_format'] is missing within
| $config['rest_supported_formats'], it will be added silently during
| REST_Controller initialization.
|
*/
$config['rest_supported_formats'] = [
'json',
'array',
'csv',
'html',
'jsonp',
'php',
'serialized',
'xml',
];

/*
|--------------------------------------------------------------------------
| REST Status Field Name
Expand Down Expand Up @@ -352,7 +375,7 @@
| `time` INT(11) NOT NULL,
| `rtime` FLOAT DEFAULT NULL,
| `authorized` VARCHAR(1) NOT NULL,
| `response_code` SMALLINT(3) NOT NULL,
| `response_code` smallint(3) DEFAULT '0',
| PRIMARY KEY (`id`)
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
Expand Down Expand Up @@ -477,3 +500,13 @@
|
*/
$config['rest_ajax_only'] = FALSE;

/*
|--------------------------------------------------------------------------
| REST Language File
|--------------------------------------------------------------------------
|
| Language file to load from the language directory
|
*/
$config['rest_language'] = 'english';
14 changes: 7 additions & 7 deletions application/config/routes.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,43 @@
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://codeigniter.com/user_guide/general/routing.html
| http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['404_override'] = 'errors/page_missing';
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Rest_server.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Rest_server extends CI_Controller {
Expand Down
Empty file modified application/controllers/Welcome.php
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions application/controllers/api/Example.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function users_get()
// Set the response and exit
$this->response([
'status' => FALSE,
'error' => 'No users were found'
'message' => 'No users were found'
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public function users_get()
{
$this->set_response([
'status' => FALSE,
'error' => 'User could not be found'
'message' => 'User could not be found'
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
}
}
Expand Down
22 changes: 11 additions & 11 deletions application/controllers/api/Key.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function index_put()
{
$this->response([
'status' => FALSE,
'error' => 'Could not save the key'
'message' => 'Could not save the key'
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
}
}
Expand All @@ -73,7 +73,7 @@ public function index_delete()
// It doesn't appear the key exists
$this->response([
'status' => FALSE,
'error' => 'Invalid API key'
'message' => 'Invalid API key'
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}

Expand All @@ -83,7 +83,7 @@ public function index_delete()
// Respond that the key was destroyed
$this->response([
'status' => TRUE,
'success' => 'API key was deleted'
'message' => 'API key was deleted'
], REST_Controller::HTTP_NO_CONTENT); // NO_CONTENT (204) being the HTTP response code
}

Expand All @@ -104,7 +104,7 @@ public function level_post()
// It doesn't appear the key exists
$this->response([
'status' => FALSE,
'error' => 'Invalid API key'
'message' => 'Invalid API key'
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}

Expand All @@ -113,14 +113,14 @@ public function level_post()
{
$this->response([
'status' => TRUE,
'success' => 'API key was updated'
'message' => 'API key was updated'
], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
}
else
{
$this->response([
'status' => FALSE,
'error' => 'Could not update the key level'
'message' => 'Could not update the key level'
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
}
}
Expand All @@ -141,7 +141,7 @@ public function suspend_post()
// It doesn't appear the key exists
$this->response([
'status' => FALSE,
'error' => 'Invalid API key'
'message' => 'Invalid API key'
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}

Expand All @@ -150,14 +150,14 @@ public function suspend_post()
{
$this->response([
'status' => TRUE,
'success' => 'Key was suspended'
'message' => 'Key was suspended'
], REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
}
else
{
$this->response([
'status' => FALSE,
'error' => 'Could not suspend the user'
'message' => 'Could not suspend the user'
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
}
}
Expand All @@ -179,7 +179,7 @@ public function regenerate_post()
// It doesn't appear the key exists
$this->response([
'status' => FALSE,
'error' => 'Invalid API key'
'message' => 'Invalid API key'
], REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
}

Expand All @@ -201,7 +201,7 @@ public function regenerate_post()
{
$this->response([
'status' => FALSE,
'error' => 'Could not save the key'
'message' => 'Could not save the key'
], REST_Controller::HTTP_INTERNAL_SERVER_ERROR); // INTERNAL_SERVER_ERROR (500) being the HTTP response code
}
}
Expand Down
Empty file modified application/controllers/api/index.html
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions application/language/english/rest_controller_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
* English language
*/

$lang['text_rest_invalid_api_key'] = 'Invalid API key %s'; // %s is the REST API key
$lang['text_rest_invalid_credentials'] = 'Invalid credentials';
$lang['text_rest_ip_denied'] = 'IP denied';
$lang['text_rest_ip_unauthorized'] = 'IP unauthorized';
$lang['text_rest_unauthorized'] = 'Unauthorized';
$lang['text_rest_ajax_only'] = 'Only AJAX requests are allowed';
$lang['text_rest_api_key_unauthorized'] = 'This API key does not have access to the requested controller';
$lang['text_rest_api_key_permissions'] = 'This API key does not have enough permissions';
$lang['text_rest_api_key_time_limit'] = 'This API key has reached the time limit for this method';
$lang['text_rest_unknown_method'] = 'Unknown method';
$lang['text_rest_unsupported'] = 'Unsupported protocol';
22 changes: 11 additions & 11 deletions application/libraries/Format.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Format {
*
* @var object
*/
private $_ci;
private $_CI;

/**
* Data to parse
Expand All @@ -83,10 +83,10 @@ class Format {
public function __construct($data = NULL, $from_type = NULL)
{
// Get the CodeIgniter reference
$this->_ci = &get_instance();
$this->_CI = &get_instance();

// Load the inflector helper
$this->_ci->load->helper('inflector');
$this->_CI->load->helper('inflector');

// If the provided data is already formatted we should probably convert it to an array
if ($from_type !== NULL)
Expand Down Expand Up @@ -283,20 +283,20 @@ public function to_html($data = NULL)
}

// Load the table library
$this->_ci->load->library('table');
$this->_CI->load->library('table');

$this->_ci->table->set_heading($headings);
$this->_CI->table->set_heading($headings);

foreach ($data as $row)
{
// Suppressing the "array to string conversion" notice.
// Keep the "evil" @ here.
$row = @ array_map('strval', $row);
// Suppressing the "array to string conversion" notice
// Keep the "evil" @ here
$row = @array_map('strval', $row);

$this->_ci->table->add_row($row);
$this->_CI->table->add_row($row);
}

return $this->_ci->table->generate();
return $this->_CI->table->generate();
}

/**
Expand Down Expand Up @@ -405,7 +405,7 @@ public function to_json($data = NULL)
}

// Get the callback parameter (if set)
$callback = $this->_ci->input->get('callback');
$callback = $this->_CI->input->get('callback');

if (empty($callback) === TRUE)
{
Expand Down
Loading

0 comments on commit 1a33312

Please sign in to comment.