| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | 
							- <?php
 - $host = "https://api.vdm.rthoni.com/";
 - $key = "demo42";
 - 
 - header("Content-Type: text/plain");
 - 
 - $token = "";
 - function error($http)
 - {
 -   echo "[ KO ] ";
 -   var_dump($http);
 -   die();
 - }
 - 
 - function check_error($http)
 - {
 -   if ($http->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";
 - 
 - ?>
 
 
  |