Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added JSONP support to the API

  • Loading branch information...
commit 2f88526fb024f40443d3563aa39d1336e95f67eb 1 parent 608fb82
@anastasds anastasds authored
Showing with 11 additions and 4 deletions.
  1. +9 −2 api.php
  2. +2 −2 php/api.class.php
View
11 api.php
@@ -18,10 +18,12 @@
**Requests**
- Send a request to `http://ureddit.com/api` with any parameters as HTTP GET variables. You must always supply a `type` variable and, for all types listed below except `catalog`, you must provide an `id` variable.
+ Send a request to `http://ureddit.com/api` with any parameters as HTTP GET parameters. You must always supply a `type` paramater and, for all types listed below except `catalog`, you must provide an `id` parameter.
**Parameters**
+The following values can be provided for the `type` parameter
+
* `catalog`: returns a list of category `id`s.
* `category`: requires `id`. Returns the category name and a list of the `id`s of all classes in that category.
* `class`: requires `id`. Returns all class information, including the roster (a list of user `id`s), lectures (a list of lecture `id`s), and teachers (a list of user `id`s).
@@ -29,6 +31,10 @@
* `link`: requires `id`. Returns the link title and URL.
* `user`: requires `id`. Returns the user username, registration date, and schedule.
+**JSONP**
+
+Add a `jsonp` GET parameter whose value is the name of the callback function in which the JSON is to be wrapped (e.g. `jsonp=parseFunction`) and the response will be formatted as per the JSONP standard.
+
**Output**
All data is returned encoded in JSON.
@@ -46,7 +52,8 @@
{
$type = isset($_GET['type']) ? $_GET['type'] : NULL;
$id = isset($_GET['id']) ? $_GET['id'] : NULL;
- $api = new api($dbpdo, $type, $id);
+ $jsonp = isset($_GET['jsonp']) ? $_GET['jsonp'] : '';
+ $api = new api($dbpdo, $jsonp, $type, $id);
}
?>
View
4 php/api.class.php
@@ -16,7 +16,7 @@ function log_api_request($type, $id)
));
}
- function __construct($dbpdo, $type, $id = NULL)
+ function __construct($dbpdo, $jsonp, $type, $id = NULL)
{
$this->dbpdo = $dbpdo;
$response = array();
@@ -127,7 +127,7 @@ function __construct($dbpdo, $type, $id = NULL)
break;
}
- echo json_encode($response);
+ echo $jsonp ? $jsonp . '(' . json_encode($response) . ');' : json_encode($response);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.