예제 #1
0
function process_api_request($function_to_run, $permission_needed)
{
    global $is_logged_in;
    $lock = false;
    try {
        verify_api_request($permission_needed);
        log_api($function_to_run);
        get_user_lock($lock = $is_logged_in);
        $ret = $function_to_run();
    } catch (Exception $e) {
        $error = $e->getMessage();
        addlog(LOG_API, sprintf("[%s] API error: \"%s\": %s: %s", getenv("REMOTE_ADDR"), $error, $function_to_run, file_get_contents("php://input")));
        $ret = array("error" => $error);
    }
    if ($lock) {
        release_lock($lock);
    }
    echo json_encode($ret);
}
예제 #2
0
<?php

require_once "../config.php";
require_once ABSPATH . "/util.php";
log_api('ticker');
list($high, $low, $avg, $vwap, $vol, $last, $buy, $sell) = get_ticker_data();
echo '{"ticker": {';
echo '"high": ' . $high . ', ';
echo '"low": ' . $low . ', ';
echo '"avg": ' . $avg . ', ';
echo '"vwap": ' . $vwap . ', ';
echo '"vol": ' . $vol . ', ';
echo '"last": ' . $last . ', ';
echo '"buy": ' . $buy . ', ';
echo '"sell": ' . $sell . '}}';
예제 #3
0
<?php

$docRoot = getenv("DOCUMENT_ROOT");
require_once $docRoot . "/mobi-config/mobi_web_constants.php";
require_once WEBROOT . "api/api_header.php";

log_api('shuttles');

require_once LIBDIR . "GTFSReader.php";
$data = Array();
$command = $_REQUEST['command'];

switch ($command) {
 case 'stops':
   $data = ShuttleSchedule::getAllStops();
   break;
 case 'stopInfo':
   $stop_id = $_REQUEST['id'];
   $time = time();

   $data['stops'] = ShuttleSchedule::getTimesForStop($stop_id);
   $data['now'] = $time;

   break;
 case 'routes': // static info about all routes
   $route_ids = ShuttleSchedule::getActiveRoutes();
   foreach ($route_ids as $route_id) {
     $routeInfo = get_route_metadata($route_id);

     if (!$_REQUEST['compact']) {
       $routeInfo['stops'] = ShuttleSchedule::list_stop_times($route_id);
예제 #4
0
<?php

$docRoot = getenv("DOCUMENT_ROOT");
require_once $docRoot . '/mobi-config/mobi_web_constants.php';
require_once WEBROOT . "api/api_header.php";
require_once LIBDIR . "NewsOffice.php";
log_api('newsoffice');

$news_office = new NewsOffice();

$channel_id = $_REQUEST['channel'] ? $_REQUEST['channel'] : 0;

$story_id = isset($_REQUEST['story_id']) ? $_REQUEST['story_id'] : NULL;

echo $news_office->get_news_xml($channel_id, $story_id)->saveXML();;

?>
예제 #5
0
<?

define('MAP_SERVER_URL', 'http://maps.mit.edu/ArcGIS/rest/services/Mobile/WhereIs_MobileAll/MapServer');

$docRoot = getenv("DOCUMENT_ROOT");
require_once $docRoot . "/mobi-config/mobi_web_constants.php";
require_once WEBROOT . "api/api_header.php";

log_api('map');

switch ($_REQUEST['f']) {
 case 'json':
   $filename = '/var/local/maptiles/service.json';
   if (!file_exists($filename)) {
     $json = file_get_contents(MAP_SERVER_URL . '?f=json');
     $fh = open($filename, 'w');
     fwrite($fh, $json);
     fclose($fh);
   } else {
     $json = file_get_contents($filename);
   }

   if ($json) {
     echo $json;
   }
   break;
}

switch ($_REQUEST['command']) {
 case 'categories':
   require_once LIBDIR . "campus_map.php";
예제 #6
0
<?php

require_once "../config.php";
require_once ABSPATH . "/util.php";
log_api('getDepth');
function fetch_depth($rate_query, $field, $have, $want)
{
    $ret = array();
    $minimum_btc_amount = numstr_to_internal(MINIMUM_BTC_AMOUNT);
    $minimum_fiat_amount = numstr_to_internal(MINIMUM_FIAT_AMOUNT);
    if ($have == "BTC") {
        $big_enough = "amount >= {$minimum_btc_amount}  AND want_amount >= {$minimum_fiat_amount}";
    } else {
        $big_enough = "amount >= {$minimum_fiat_amount} AND want_amount >= {$minimum_btc_amount} ";
    }
    $query = "\n    SELECT\n        {$rate_query} AS rate,\n        {$field} as amount\n    FROM\n        orderbook\n    WHERE\n        type='{$have}'\n        AND want_type='{$want}'\n        AND status='OPEN'\n        AND {$big_enough}\n    ORDER BY\n        rate DESC\n    ";
    $result = do_query($query);
    while ($row = mysql_fetch_assoc($result)) {
        $amount = internal_to_numstr($row['amount']);
        $rate = $row['rate'];
        //bitcoincharts uses NUMERIC(18,8)
        if ($rate < 1000000000) {
            array_push($ret, "[{$rate}, {$amount}]");
        }
    }
    return implode($ret, ", ");
}
printf('{"asks": [%s], "bids": [%s]}', fetch_depth("initial_want_amount / initial_amount", "amount", "BTC", CURRENCY), fetch_depth("initial_amount / initial_want_amount", "want_amount", CURRENCY, "BTC"));
예제 #7
0
<?php

require_once "../config.php";
require_once ABSPATH . "/util.php";
log_api('getTrades');
echo '[';
$query = "\n    SELECT\n        UNIX_TIMESTAMP(transactions.timest) AS timest,\n        txid,\n        IF(\n            type='BTC',\n            b_amount/a_amount,\n            a_amount/b_amount\n        ) AS rate,\n        IF(\n            type='BTC',\n            a_amount,\n            b_amount\n        ) AS amount\n    FROM\n        transactions\n    JOIN\n        orderbook\n    ON\n        transactions.a_orderid=orderbook.orderid\n    WHERE\n        b_amount > 0\n        AND a_amount > 0\n        AND transactions.timest BETWEEN NOW() - INTERVAL 1 DAY AND NOW()\n    ";
$result = do_query($query);
$first = true;
while ($row = mysql_fetch_assoc($result)) {
    if ($first) {
        $first = false;
    } else {
        echo ', ';
    }
    echo '{"date": ';
    echo $row['timest'];
    echo ', "price": ';
    echo $row['rate'];
    echo ', "amount": ';
    echo internal_to_numstr($row['amount']);
    echo ', "tid": ';
    echo $row['txid'];
    echo '}';
}
echo ']';
?>

예제 #8
0
<?
require_once("api_header.php");

$module = $_REQUEST['module'];
log_api($module);

switch ($module) {
 case 'emergency':
   require('emergency.php');
   break;

 case 'people':
   require('people.php');
   break;

 case 'stellar':
   require('stellar.php');
   break;

 case 'calendar':
   require('calendar.php');
   break;

 case 'push':
   require('apns_push.php');
   break;

 default:
   $data = Array('error' => 'not a valid query');
   echo json_encode($data);
   break;