Skip to content

Commit

Permalink
remove get prefix on getters and add reload method to buckets/objects (
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsupplee authored and jdpedrie committed Jun 2, 2016
1 parent 0b6d591 commit ffd7cc3
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 202 deletions.
10 changes: 5 additions & 5 deletions src/BigQuery/BigQueryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __construct(array $config = [])
* $isComplete = $queryResults->isComplete(); // check the query's status
* }
*
* foreach ($queryResults->getRows() as $row) {
* foreach ($queryResults->rows() as $row) {
* echo $row['name'];
* }
* ```
Expand Down Expand Up @@ -159,15 +159,15 @@ public function runQuery($query, array $options = [])
* $job = $bigQuery->runQueryAsJob('SELECT * FROM [bigquery-public-data:usa_names.usa_1910_2013]');
*
* $isComplete = false;
* $queryResults = $job->getQueryResults();
* $queryResults = $job->queryResults();
*
* while (!$isComplete) {
* sleep(1); // let's wait for a moment...
* $queryResults->reload(); // trigger a network request
* $isComplete = $queryResults->isComplete(); // check the query's status
* }
*
* foreach ($queryResults->getRows() as $row) {
* foreach ($queryResults->rows() as $row) {
* echo $row['name'];
* }
* ```
Expand Down Expand Up @@ -227,7 +227,7 @@ public function job($id)
* ]);
*
* foreach ($jobs as $job) {
* var_dump($job->getId());
* var_dump($job->id());
* }
* ```
*
Expand Down Expand Up @@ -294,7 +294,7 @@ public function dataset($id)
* $datasets = $bigQuery->datasets();
*
* foreach ($datasets as $dataset) {
* var_dump($dataset->getId());
* var_dump($dataset->id());
* }
* ```
*
Expand Down
44 changes: 20 additions & 24 deletions src/BigQuery/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ class Dataset
private $connection;

/**
* @var array The dataset's metadata.
* @var array The dataset's identity.
*/
private $data;
private $identity;

/**
* @var array The dataset's identity.
* @var array The dataset's metadata.
*/
private $identity;
private $info;

/**
* @param ConnectionInterface $connection Represents a connection to
* BigQuery.
* @param string $id The dataset's ID.
* @param string $projectId The project's ID.
* @param array $data The dataset's metadata.
* @param array $info The dataset's metadata.
*/
public function __construct(ConnectionInterface $connection, $id, $projectId, array $data = [])
public function __construct(ConnectionInterface $connection, $id, $projectId, array $info = [])
{
$this->connection = $connection;
$this->data = $data;
$this->info = $info;
$this->identity = [
'datasetId' => $id,
'projectId' => $projectId
Expand Down Expand Up @@ -121,9 +121,9 @@ public function delete(array $options = [])
public function update(array $metadata, array $options = [])
{
$options += $metadata;
$this->data = $this->connection->patchDataset($options + $this->identity);
$this->info = $this->connection->patchDataset($options + $this->identity);

return $this->data;
return $this->info;
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public function table($id)
* $tables = $dataset->tables();
*
* foreach ($tables as $table) {
* var_dump($table->getId());
* var_dump($table->id());
* }
* ```
*
Expand Down Expand Up @@ -236,7 +236,7 @@ public function createTable($id, array $options = [])
*
* Example:
* ```
* $info = $dataset->getInfo();
* $info = $dataset->info();
* echo $info['friendlyName'];
* ```
*
Expand All @@ -245,13 +245,13 @@ public function createTable($id, array $options = [])
* @param array $options Configuration options.
* @return array
*/
public function getInfo(array $options = [])
public function info(array $options = [])
{
if (!$this->data) {
if (!$this->info) {
$this->reload($options);
}

return $this->data;
return $this->info;
}

/**
Expand All @@ -260,7 +260,7 @@ public function getInfo(array $options = [])
* Example:
* ```
* $dataset->reload();
* $info = $dataset->getInfo();
* $info = $dataset->info();
* echo $info['friendlyName'];
* ```
*
Expand All @@ -271,24 +271,20 @@ public function getInfo(array $options = [])
*/
public function reload(array $options = [])
{
if (!$this->data) {
$this->data = $this->connection->getDataset($options + $this->identity);
}

return $this->data;
return $this->info = $this->connection->getDataset($options + $this->identity);
}

/**
* Retrieves the dataset's ID.
*
* Example:
* ```
* echo $dataset->getId();
* echo $dataset->id();
* ```
*
* @return string
*/
public function getId()
public function id()
{
return $this->identity['datasetId'];
}
Expand All @@ -300,12 +296,12 @@ public function getId()
*
* Example:
* ```
* echo $dataset->getIdentity()['projectId'];
* echo $dataset->identity()['projectId'];
* ```
*
* @return array
*/
public function getIdentity()
public function identity()
{
return $this->identity;
}
Expand Down
38 changes: 19 additions & 19 deletions src/BigQuery/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ class Job
private $connection;

/**
* @var array The job's metadata
* @var array The job's identity.
*/
private $data;
private $identity;

/**
* @var array The job's identity.
* @var array The job's metadata
*/
private $identity;
private $info;

/**
* @param ConnectionInterface $connection Represents a connection to
* BigQuery.
* @param string $id The job's ID.
* @param string $projectId The project's ID.
* @param array $data The job's metadata.
* @param array $info The job's metadata.
*/
public function __construct(ConnectionInterface $connection, $id, $projectId, array $data = [])
public function __construct(ConnectionInterface $connection, $id, $projectId, array $info = [])
{
$this->connection = $connection;
$this->data = $data;
$this->info = $info;
$this->identity = [
'jobId' => $id,
'projectId' => $projectId
Expand Down Expand Up @@ -114,7 +114,7 @@ public function cancel(array $options = [])
* Example:
* ```
* $job = $bigQuery->runQueryAsJob('SELECT * FROM [bigquery-public-data:usa_names.usa_1910_2013]');
* $queryResults = $job->getQueryResults();
* $queryResults = $job->queryResults();
* ```
*
* @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults
Expand All @@ -130,7 +130,7 @@ public function cancel(array $options = [])
* }
* @return array
*/
public function getQueryResults(array $options = [])
public function queryResults(array $options = [])
{
$response = $this->connection->getQueryResults($options + $this->identity);

Expand Down Expand Up @@ -164,7 +164,7 @@ public function getQueryResults(array $options = [])
*/
public function isComplete(array $options = [])
{
return $this->getInfo($options)['status']['state'] === 'DONE';
return $this->info($options)['status']['state'] === 'DONE';
}

/**
Expand All @@ -173,7 +173,7 @@ public function isComplete(array $options = [])
*
* Example:
* ```
* $info = $job->getInfo();
* $info = $job->info();
* echo $info['statistics']['startTime'];
* ```
*
Expand All @@ -182,13 +182,13 @@ public function isComplete(array $options = [])
* @param array $options Configuration options.
* @return array
*/
public function getInfo(array $options = [])
public function info(array $options = [])
{
if (!$this->data) {
if (!$this->info) {
$this->reload($options);
}

return $this->data;
return $this->info;
}

/**
Expand All @@ -209,20 +209,20 @@ public function getInfo(array $options = [])
*/
public function reload(array $options = [])
{
return $this->data = $this->connection->getJob($options + $this->identity);
return $this->info = $this->connection->getJob($options + $this->identity);
}

/**
* Retrieves the job's ID.
*
* Example:
* ```
* echo $job->getId();
* echo $job->id();
* ```
*
* @return string
*/
public function getId()
public function id()
{
return $this->identity['jobId'];
}
Expand All @@ -234,12 +234,12 @@ public function getId()
*
* Example:
* ```
* echo $job->getIdentity()['projectId'];
* echo $job->identity()['projectId'];
* ```
*
* @return array
*/
public function getIdentity()
public function identity()
{
return $this->identity;
}
Expand Down
Loading

0 comments on commit ffd7cc3

Please sign in to comment.