/** * @cover MoBagel\MoBagelClient::sendReport */ public function testSendReport() { $response = \MoBagel\MoBagel::registerDevice(static::PRODUCT_KEY); $body = $response->getBody()->getContents(); $object = json_decode($body); $deviceKey = $object->data->attributes->key; $content = ["state" => "normal"]; $response = \MoBagel\MoBagel::sendReport($deviceKey, $content); $statusCode = $response->getStatusCode(); $this->assertEquals(201, $statusCode, 'Send report fail.'); }
<?php /** * MoBagel PHP SDK. * * @link https://mobagel.com * * @copyright Copyright (c) 2016 MoBagel * @license MoBagel Platform */ require 'vendor/autoload.php'; echo "This is MoBagel PHP SDK sample, you can learn how to `register device` and `report state` in this sample code\n"; // setup your product key $productKey = "1111111111222222222233333333334444444444555555555566666666667777"; echo "\nRegister device...\n"; // register a new device $response = \MoBagel\MoBagel::registerDevice($productKey); $body = $response->getBody()->getContents(); echo "Data response:\n"; print_r($body); $object = json_decode($body); $deviceKey = $object->data->attributes->key; echo "\n\n\nSend report...\n"; // use device key to report $contents = ["state" => "normal"]; $response = \MoBagel\MoBagel::sendReport($deviceKey, $contents); $body = $response->getBody()->getContents(); echo "Data response:\n"; print_r($body);