私はできる限りこれを説明しようとしていますが、何か不明な点がある場合は質問してください。センサーに関する多くの情報を取得する API を使用しています。
これはクラス内のメソッドです
public function getSensors()
{
$params = array();
return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/sensors/list', $params, 'GET')->getBody());
そして私のindex.phpで
$params = array('id'=> XXXXXX);
$response = $consumer->sendRequest(constant('REQUEST_URI').'/sensor/info', $params,'GET');
echo json_decode($response->getBody());
これにより、次のような情報の塊が得られます。
{"id":"xxxxx","client":"xxxx","name":"xxxxx","lastUpdated": xxxx}
この情報の一部のみを使用したい。
これは getBody() メソッドです。
public function getBody() {
if (self::METHOD_POST == $this->method && (!empty($this->postParams) || !empty($this->uploads))) {
if (0 === strpos($this->headers['content-type'], 'application/x-www-form-urlencoded')) {
$body = http_build_query($this->postParams, '', '&');
if (!$this->getConfig('use_brackets')) {
$body = preg_replace('/%5B\d+%5D=/', '=', $body);
}
// support RFC 3986 by not encoding '~' symbol (request #15368)
return str_replace('%7E', '~', $body);
} elseif (0 === strpos($this->headers['content-type'], 'multipart/form-data')) {
require_once 'HTTP/Request2/MultipartBody.php';
return new HTTP_Request2_MultipartBody(
$this->postParams, $this->uploads, $this->getConfig('use_brackets')
);
}
}
return $this->body;
}