responseCode != 200) error($http); return json_decode($http->body); } function api_post($url, $param) { global $host; global $key; global $token; $http = http_post_fields($host . $url, $param, array(), array("headers" => array("Api-Key" => $key, "Authorization" => $token))); return check_error(http_parse_message($http)); } function api_get($url, $param) { global $host; global $key; global $token; $f = true; foreach ($param as $k => $v) { if ($f) { $f = false; $url .= "?"; } else $url .= "&"; $url .= urlencode($k) . "=" . urlencode($v); } $http = http_get($host . $url, array("headers" => array("Api-Key" => $key, "Authorization" => $token))); return check_error(http_parse_message($http)); } function add_status($status, $long, $lat, $r) { $params = array("status" => $status); if ($long !== null) $params["longitude"] = $long; if ($lat !== null) $params["latitude"] = $lat; $s = api_post("status", $params); if ($s->user_id != $r->id) die("[ KO ] Users ids don't match"); if (($long !== null && $s->longitude != $long) || ($long === null && $s->longitude != null)) die("[ KO ] Longitudes don't match"); if (($lat !== null && $s->latitude != $lat) || ($lat === null && $s->latitude != null)) die("[ KO ] Latitudes don't match"); echo "[ OK ] Status added\n"; } function mk_status($status, $long, $lat) { return array("status" => $status, "long" => $long, "lat" => $lat); } $username = "check_" . rand(); $password = md5(rand()); $user_pass = array("username" => $username, "password" => $password); $r = api_post("user", $user_pass); echo "[ OK ] User " . $r->username . " (" . $r->id . ") created\n"; $l = api_post("user/login", $user_pass); if ($l->username != $r->username) die("[ KO ] Usernames don't match"); if ($l->id != $r->id) die("[ KO ] Users ids don't match"); $token = $r->token; echo "[ OK ] User " . $r->username . " (" . $r->id . ") logged in\n"; $status = array(mk_status("check status null null", null, null), mk_status("check status 42 null", 42, null), mk_status("check status null 42", null, 42), mk_status("check status 42.42 42", 42.42, 42)); foreach ($status as $st) add_status($st['status'], $st['long'], $st['lat'], $r); $f = api_get("status/feed", array()); if (count($f) != count($status)) die("[ KO ] Did not found " . count($status). " status (Was the database cleared?)\n"); echo "[ OK ] All the status were added\n"; api_post("status/" . $f[0]->id . "/confirm", array("confirmation" => 1)); echo "[ OK ] Status confirmed once\n"; api_post("status/" . $f[0]->id . "/confirm", array("confirmation" => 0)); echo "[ OK ] Status confirmed tiwce\n"; ?>