summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-02-10 23:32:23 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-02-10 23:32:23 +0100
commitcb2df59b45d4cb35790472f76b06c59b22c6213b (patch)
tree806c5853512d3ea1a50778d11f6265985c73af13
parentc8ff6f56b9b971f88fed840c2af50df11b7dc948 (diff)
api: Require the version to start with v
Makes the URL easier to understand (especially the v1 case). Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/api.php7
-rw-r--r--application/tests/test_api_v1.php4
2 files changed, 9 insertions, 2 deletions
diff --git a/application/controllers/api.php b/application/controllers/api.php
index 3297f0614..837f62e89 100644
--- a/application/controllers/api.php
+++ b/application/controllers/api.php
@@ -22,6 +22,13 @@ class Api extends MY_Controller {
$requested_version = $this->uri->segment(2);
$controller = $this->uri->segment(3);
$function = $this->uri->segment(4);
+
+ if (!preg_match("/^v([0-9]+)(.[0-9]+){0,2}$/", $requested_version)) {
+ throw new \exceptions\PublicApiException("api/invalid-version", "Invalid API version requested");
+ }
+
+ $requested_version = substr($requested_version, 1);
+
$major = intval(explode(".", $requested_version)[0]);
if (!preg_match("/^[a-zA-Z-_]+$/", $controller)) {
diff --git a/application/tests/test_api_v1.php b/application/tests/test_api_v1.php
index 7fe06ca36..bba0f9180 100644
--- a/application/tests/test_api_v1.php
+++ b/application/tests/test_api_v1.php
@@ -23,7 +23,7 @@ class test_api_v1 extends Test {
private function uploadFile($apikey, $file)
{
- $ret = $this->CallAPI("POST", "$this->server/api/1.0.0/file/upload", array(
+ $ret = $this->CallAPI("POST", "$this->server/api/v1.0.0/file/upload", array(
"apikey" => $apikey,
"file[1]" => curl_file_create($file),
));
@@ -59,7 +59,7 @@ class test_api_v1 extends Test {
private function callEndpoint($verb, $endpoint, $data)
{
- return $this->CallAPI($verb, "$this->server/api/1.0.0/$endpoint", $data);
+ return $this->CallAPI($verb, "$this->server/api/v1.0.0/$endpoint", $data);
}
public function test_callPrivateEndpointsWithoutApikey()