PHP code example of wilddogserver / huang

1. Go to this page and download the library: Download wilddogserver/huang library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wilddogserver / huang example snippets


const DEFAULT_URL = 'https://testing.wilddogio.com/';
const DEFAULT_TOKEN = 'xVUeUTLjTye5cS4ugiG6C5BStV0deHgfsCi6SG6W';
const DEFAULT_PATH = '/wilddog/example';

$wilddog = new \Wilddog\WilddogLib(DEFAULT_URL, DEFAULT_TOKEN);

// --- storing an array ---
$test = array(
    "foo" => "bar",
    "i_love" => "lamp",
    "id" => 42
);
$dateTime = new DateTime();
$wilddog->set(DEFAULT_PATH . '/' . $dateTime->format('c'), $test);

// --- storing a string ---
$wilddog->set(DEFAULT_PATH . '/name/contact001', "John Doe");

// --- reading the stored string ---
$name = $wilddog->get(DEFAULT_PATH . '/name/contact001');


// -- Wilddog API
//注意: 所有数据API操作需要判断返回是否成功
$wilddog->set($path, $value);   // 存储数据
$value = $wilddog->get($path);  // 读取数据
$wilddog->delete($path);        // 删除数据
$wilddog->update($path, $data); // 更新数据
$wilddog->push($path, $data);   // push数据

// -- Wilddog PHP Library API
$wilddog->setToken($token);     // 设置用户token
$wilddog->setBaseURI($uri);     // 设置uri路径
$wilddog->setTimeOut($seconds); // 设置超时时间

public function setWilddogValue($path, $value) {
  $wilddog = new Wilddog('https://testing.wilddogio.com', 'xVUeUTLjTye5cS4ugiG6C5BStV0deHgfsCi6SG6W');
  $wilddog->set($path, $value);
}

public function setWilddogValue($path, $value, $wilddog) {
    $result = $wilddog->set($path, $value)
    if ($result == null && $value != null) {
        //若为null 则需要判断是否出现了异常
        //只有set的$value为null时 set($path,$value)返回null
        //其他情况为请求异常 需要用户进行判断重试
    }
}


  re_once '<path>/lib/wilddogStub.php';

  class MyClass extends PHPUnit_Framework_TestCase
  {
    public function testSetWilddogValue() {
      $myClass = new MyClass();
      $wilddogStub = new WilddogStub($uri, $token);
      $myClass->setWilddogValue($path, $value, $wilddogStub);
    }
  }
bash
$ phpunit test/wilddogTest.php
bash
$ phpunit test/wilddogStubTest.php