예제 #1
0
 public function testUpload()
 {
     $writer = new \Keboola\TableauServerWriter\Writer(TSW_SERVER_URL, TSW_USERNAME, TSW_PASSWORD, TSW_SITE, TSW_PROJECT_ID);
     $dataSourceName = 'test-' . uniqid();
     $dataSourceId = $writer->publishDatasource($dataSourceName, 'tests/test.tde');
     $this->assertNotEmpty($dataSourceId);
     $result = $writer->getDatasource($dataSourceId);
     $this->assertArrayHasKey('name', $result);
     $this->assertEquals($dataSourceName, $result['name']);
     $writer->deleteDatasource($dataSourceId);
     try {
         $writer->getDatasource($dataSourceId);
         $this->fail('Datasource should not exist any more');
     } catch (\Exception $e) {
         if ($e->getCode() != 404) {
             $this->fail('Datasource should not exist any more, API call should return code 404 but returned: ' . $e->getCode());
         }
     }
     $writer->logout();
 }
예제 #2
0
    }
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
require_once dirname(__FILE__) . "/../vendor/autoload.php";
$arguments = getopt("d::", array("data::"));
if (!isset($arguments['data'])) {
    print "Data folder not set.";
    exit(1);
}
$config = Yaml::parse(file_get_contents($arguments['data'] . "/config.yml"));
try {
    if (!filter_var($config['parameters']['server_url'], FILTER_VALIDATE_URL) !== false) {
        print "{$config['parameters']['server_url']} is not a valid URL";
        exit(1);
    }
    $writer = new \Keboola\TableauServerWriter\Writer($config['parameters']['server_url'], $config['parameters']['username'], isset($config['parameters']['#password']) ? $config['parameters']['#password'] : $config['parameters']['password'], isset($config['parameters']['site']) ? $config['parameters']['site'] : null);
    if (!empty($config['parameters']['project_id'])) {
        $writer->setProjectId($config['parameters']['project_id']);
    } elseif (!empty($config['parameters']['project_name'])) {
        $projectId = $writer->getProjectId($config['parameters']['project_name']);
        if (!$projectId) {
            print "Project with name {$config['parameters']['project_name']} does not exist on the server";
            exit(1);
        }
        $writer->setProjectId($projectId);
    }
    if (!empty($config['parameters']['get_projects'])) {
        print json_encode($writer->listProjects());
    } else {
        $filesCount = 0;
        foreach (glob($arguments['data'] . "/in/files/*") as $filename) {