apikey = $apikey; $this->apipassword = $apipassword; $this->apiserver = $apiserver; } function request ($action, $data = null) { if (func_num_args () != 1 and func_num_args() != 2) throw new \Exception ( "VSMClient:request needs two or three arguments"); $method = 'POST'; $hdr = null; $bdy = new \http\Message\Body(); $bdy->addForm([ 'username' => $this->apikey, 'password' => $this->apipassword, 'action' => $action, 'data' => yaml_emit ($data) ]); $req = new \http\Client\Request ( $method, $this->apiserver, $hdr, $bdy); $client = new \http\Client(); $client->enqueue ($req); $client->send (); $resp = $client->getResponse(); $yaml = $resp->getBody(); $rdata = yaml_parse ($yaml); if (! array_key_exists('status', $rdata)) throw new \Exception ('response does not have status'); if ($rdata["status"] == "failed") throw new \Exception ("server reported: " . $rdata['error']); // if (array_key_exists('list', $rdata)) // return $rdata["list"]; return $rdata; } } }