Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added JSONP support to the API

  • Loading branch information...
commit 2f88526fb024f40443d3563aa39d1336e95f67eb 1 parent 608fb82
Anastas Stoyanovsky authored

Showing 2 changed files with 11 additions and 4 deletions. Show diff stats Hide diff stats

  1. 11  api.php
  2. 4  php/api.class.php
11  api.php
@@ -18,10 +18,12 @@
18 18
 
19 19
 **Requests**
20 20
 
21  
-  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.
  21
+  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.
22 22
 
23 23
 **Parameters**
24 24
 
  25
+The following values can be provided for the `type` parameter
  26
+
25 27
   * `catalog`: returns a list of category `id`s.
26 28
   * `category`: requires `id`. Returns the category name and a list of the `id`s of all classes in that category.
27 29
   * `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 @@
29 31
   * `link`: requires `id`. Returns the link title and URL.
30 32
   * `user`: requires `id`. Returns the user username, registration date, and schedule.
31 33
 
  34
+**JSONP**
  35
+
  36
+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.
  37
+
32 38
 **Output**
33 39
 
34 40
 All data is returned encoded in JSON.
@@ -46,7 +52,8 @@
46 52
   {
47 53
     $type = isset($_GET['type']) ? $_GET['type'] : NULL;
48 54
     $id = isset($_GET['id']) ? $_GET['id'] : NULL;
49  
-    $api = new api($dbpdo, $type, $id);
  55
+    $jsonp = isset($_GET['jsonp']) ? $_GET['jsonp'] : '';
  56
+    $api = new api($dbpdo, $jsonp, $type, $id);
50 57
   }
51 58
 
52 59
 ?>
4  php/api.class.php
@@ -16,7 +16,7 @@ function log_api_request($type, $id)
16 16
 												       ));
17 17
   }
18 18
 
19  
-  function __construct($dbpdo, $type, $id = NULL)
  19
+  function __construct($dbpdo, $jsonp, $type, $id = NULL)
20 20
   {
21 21
     $this->dbpdo = $dbpdo;
22 22
     $response = array();
@@ -127,7 +127,7 @@ function __construct($dbpdo, $type, $id = NULL)
127 127
 	break;
128 128
       }
129 129
 
130  
-    echo json_encode($response);
  130
+    echo $jsonp ? $jsonp . '(' . json_encode($response) . ');' : json_encode($response);
131 131
   }
132 132
 
133 133
 }

0 notes on commit 2f88526

Please sign in to comment.
Something went wrong with that request. Please try again.