Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
4 api/.htaccess
@@ -0,0 +1,4 @@
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule ^(.*)$ index.php/$1 [L]
View
25 api/index.php
@@ -0,0 +1,25 @@
+<?php
+
+// Application base path
+define('APPPATH', '../');
+
+// Include necessary path for class loading
+set_include_path(implode(PATH_SEPARATOR, array(
+ realpath(APPPATH . '/lib'),
+ realpath(APPPATH . '/lib/Sparrow'),
+ realpath(APPPATH . '/includes'),
+ realpath(APPPATH . '/resources'),
+ get_include_path(),
+)));
+
+// Load app engine
+include_once 'App.php';
+
+// Initiate engine and run!
+App::init(APPPATH . '/config/app.ini');
+
+// handle request
+$request = new Request($_REQUEST);
+$resource = $request->loadResource();
+$response = $resource->exec($request);
+$response->output();
View
3  config/app.ini
@@ -10,5 +10,4 @@ db.port = 3307
[urls]
url.host = localhost
-url.base = /cwc2012/
-
+url.base = /
View
BIN  docs/battle_round_1.pdf
Binary file not shown
View
BIN  docs/battle_round_2.pdf
Binary file not shown
View
17 lib/Request.php
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * Process the incoming HTTP request
+ */
+class Request {
+
+ public $uri;
+ public $supportedHttpMethods = array('GET', 'POST');
+ public $defaultMethod = 'GET';
+ public $requestData;
+ public $resources = array();
+
+ public function __construct($requestData = array()) {}
+ public function loadResource() {}
+
+}
View
12 lib/Resource.php
@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * Base resource class
+ */
+abstract class Resource {
+
+ private $parameters;
+ public function __construct($parameters) {}
+ public function exec($request) {}
+
+}
View
22 lib/Response.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Provides the data of the outgoing HTTP response
+ */
+class Response {
+
+ const OK = 200;
+ const CREATED = 201;
+ const UNAUTHORIZED = 401;
+ const NOTFOUND = 404;
+
+ public $request;
+ public $code = Response::OK;
+ public $headers = array();
+ public $body;
+
+ public function __construct($request) {}
+ public function addHeader($header, $value) {}
+ public function output() {}
+
+}
View
16 resources/EventResource.php
@@ -0,0 +1,16 @@
+<?php
+
+class EventResource extends Resource
+{
+ public function __construct() {
+ return '/events';
+ }
+
+ public function get($request) {
+ $events = App::getRepository('Event')->getActiveEvents();
+ $response = new Response($request);
+ $response->addHeader('Content-type', 'application/json');
+ $response->body = json_encode($events);
+ return $response;
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.