protected function process($request, $dataType = 'json') { $this->lastRequest = $request; $response = $this->dispatcher->dispatch($request); $rawData = $response->getRaw(); if (empty($rawData)) { throw new ClientRequestException($request->getURL() . ' gab einen leeren string zurück'); } if ($dataType == 'json') { $json = $rawData; $data = json_decode($json); if ($data == FALSE) { throw new ClientRequestException($request->getURL() . ': konnte nicht als json dekodiert werden: ' . $json); } if ($data->status == 'ok') { if (isset($data->debug)) { $this->debug = $data->debug; } $this->lastResponse = $data; return $data->content; } else { throw new ClientRequestException('Client-Request: ' . $request->getURL() . ' ist fehlgeschlagen.'); } } else { $this->lastResponse = $rawData; return $rawData; } }
public function dispatch($method, array $parameters = array()) { $json = json_encode($this->buildParameters($parameters)); $url = $this->buildApiUrl($method); $response = $this->service->dispatch($this->request = $this->service->createRequest('POST', $url, $json, array('Content-Type' => 'application/json; charset=utf-8'))); return $this->processResponse($response, $this->request); }
/** * @param string $url muss mit anfangen * @return string raw */ public function send($command) { $this->request = new \Psc\URL\Request('http://' . $this->host . ':' . $this->port . '/' . ltrim($command, '/')); $this->log('sende: ' . $this->request->getURL()); $this->response = $this->dispatcher->dispatch($this->request); return $this->response->getRaw(); }