コード例 #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
ファイル: run.php プロジェクト: keboola/tableau-server-writer
        $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) {
            $fileInfo = pathinfo($filename);
            if (!isset($fileInfo['extension']) || $fileInfo['extension'] != 'manifest') {
                $manifest = Yaml::parse(file_get_contents($filename . '.manifest'));
                $writer->publishDatasource($manifest['name'], $filename);
                $filesCount++;
            }
        }
        print "Uploaded {$filesCount} files.";
    }
    $writer->logout();
    exit(0);
} catch (\GuzzleHttp\Exception\RequestException $e) {
    print $e->getMessage();
    exit(1);
} catch (\Keboola\TableauServerWriter\Exception $e) {
    //@TODO Handle errors
    print $e->getMessage();
    exit(1);
} catch (\Exception $e) {