stefanvinding/geckoboard-datasets

Geckoboard数据集REST客户端

2.0 2020-01-30 13:24 UTC

This package is not auto-updated.

Last update: 2024-09-20 10:55:15 UTC


README

1. 这是什么?

PHP 7.2+的REST客户端库,允许对新的Geckoboard Dataset API执行CRUD操作。

2. 它是如何工作的?

2.1 创建/更新数据集

使用助手

     $schema =
     [
        ['name' => 'MyAmount'    , 'type' => 'number'  , 'optional' => true                           ],
        ['name' => 'MyText'      , 'type' => 'string'                                                 ],
        ['name' => 'MyDate'      , 'type' => 'datetime', 'optional' => true                           ],
        ['name' => 'Danish Krone', 'type' => 'money'   , 'optional' => false, 'currency_code' => 'DKK']
     ];
     
     
     // Create / Update "mydataset" and set "MyDate" as unique field
     \Stefanvinding\Geckoboard\Dataset\Helper::factory(['key' => 'YOUR API KEY HERE'])->createDataset('mydataset', $schema, 'MyDate');

使用低级API

     $schema = (new \Stefanvinding\Geckoboard\Dataset\Row())->addTypes([
        new \Stefanvinding\Geckoboard\Dataset\Type\TypeNumber('MyAmount', true),
        new \Stefanvinding\Geckoboard\Dataset\Type\TypeString('MyText'),
        new \Stefanvinding\Geckoboard\Dataset\Type\TypeDatetime('MyDate', true),
        new \Stefanvinding\Geckoboard\Dataset\Type\TypeMoney('Danish Krone', 'DKK', true)             
     ]);
     
     (new \Stefanvinding\Geckoboard\Dataset\Request(['key' => 'YOUR API KEY HERE']))->createDataset('mydataset', $schema, 'MyDate');

2.2 删除数据集

使用助手

    \Stefanvinding\Geckoboard\Dataset\Helper::factory(['key' => 'YOUR API KEY HERE'])->deleteDataset('mydataset');

使用低级API

    (new \Stefanvinding\Geckoboard\Dataset\Request(['key' => 'YOUR API KEY HERE']))->deleteDataset('mydataset');

2.3 向数据集中追加数据

使用助手

    $records = 
    [
        [
            ['name' => 'MyDate'      , 'type' => 'datetime', 'value' => date('Y-m-d\TH:i:s\Z')],
            ['name' => 'MyAmount'    , 'type' => 'number'  , 'value' => rand(1, 10000)        ],
            ['name' => 'MyText'      , 'type' => 'String'  , 'value' => uniqid()              ],
            ['name' => 'Danish Krone', 'type' => 'money'   , 'value' => rand(1, 10000)        ]
        ],
        // Add more records ....            
    ];
          
    // Unique by "MyDate" field
    \Stefanvinding\Geckoboard\Dataset\Helper::factory(['key' => 'YOUR API KEY HERE'])->appendData('mydataset', $records, ['MyDate']);

使用低级API

    $records =
    [
        (new \Stefanvinding\Geckoboard\Dataset\Row())->addTypes([
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeDatetime('MyDate'))->setValue(date('Y-m-d\TH:i:s\Z')),
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeNumber('MyAmount'))->setValue(rand(1, 1000))         ,
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeString('MyText'))->setValue(uniqid())                ,               
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeMoney('Danish Krone'))->setValue(rand(1, 10000))
        ]),                                
        // Add more records ....            
    ];
           
    // Unique by "MyDate" field
    (new \Stefanvinding\Geckoboard\Dataset\Request(['key' => 'YOUR API KEY HERE']))->appendData('mydataset', $records, ['MyDate']);

2.4 替换数据集中的数据

使用助手

    $records = 
    [
        [
            ['name' => 'MyDate'      , 'type' => 'datetime', 'value' => date('Y-m-d\TH:i:s\Z')],
            ['name' => 'MyAmount'    , 'type' => 'number'  , 'value' => rand(1, 10000)        ],
            ['name' => 'MyText'      , 'type' => 'String'  , 'value' => uniqid()              ],
            ['name' => 'Danish Krone', 'type' => 'money'   , 'value' => rand(1, 10000)        ]
        ],
        // Add more records ....            
    ];
                 
    \Stefanvinding\Geckoboard\Dataset\Helper::factory(['key' => 'YOUR API KEY HERE'])->replaceData('mydataset', $records);

使用低级API

    $records =
    [
        (new \Stefanvinding\Geckoboard\Dataset\Row())->addTypes([
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeDatetime('MyDate'))->setValue(date('Y-m-d\TH:i:s\Z')),
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeNumber('MyAmount'))->setValue(rand(1, 1000))         ,
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeString('MyText'))->setValue(uniqid())                ,               
                    (new \Stefanvinding\Geckoboard\Dataset\Type\TypeMoney('Danish Krone'))->setValue(rand(1, 10000))
        ]),                                
        // Add more records ....            
    ];
           
    (new \Stefanvinding\Geckoboard\Dataset\Request(['key' => 'YOUR API KEY HERE']))->replaceData('mydataset', $records);

3. 测试

  1. 将您的API密钥添加到tests/BaseTest.php中
  2. 运行PHPUnit ("vendor/phpunit/phpunit/phpunit")

支持者