Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new "quickstart" samples. #174

Merged
merged 22 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
331c184
Add Pub/Sub quickstart sample.
jmdobry Sep 27, 2016
78c821b
adds tests for quickstarts, adds logging quickstart, and fixes review…
bshaffer Sep 30, 2016
16982ac
updates logging quickstart to log entry
bshaffer Sep 30, 2016
8196545
Merge branch 'master' into quickstarts
bshaffer Oct 4, 2016
0158ed9
moves logging to api subdirectory
bshaffer Oct 4, 2016
09e2cb1
moves dataset->delete to teardown
bshaffer Oct 4, 2016
9340a8b
adds composer autoloading to quickstarts
bshaffer Oct 4, 2016
ac14b65
updates datastore quickstart to use query instead of entity
bshaffer Oct 4, 2016
27e54e5
updates datastore sample to use lookup
bshaffer Oct 5, 2016
fd64f8b
removes project ID from logging, skips tests if ADC is not set
bshaffer Oct 5, 2016
124566c
moves topic deletion to teardown
bshaffer Oct 5, 2016
59f9085
fixes cs
bshaffer Oct 5, 2016
21eaaa6
adds project ID and tests to pubsub sample
bshaffer Oct 5, 2016
d187637
changes datastore entity back to Task
bshaffer Oct 5, 2016
8850d29
Added missing print statements. Added Language, Speech, and Vision qu…
jmdobry Oct 6, 2016
dc00f27
Address comments.
jmdobry Oct 6, 2016
b7bda05
Change datastore quickstart sample to create a task.
jmdobry Oct 6, 2016
a772cd1
Add missing print statment.
jmdobry Oct 7, 2016
ff6a9c4
adds tests for language/speech/vision quickstarts
bshaffer Oct 7, 2016
eda129e
updates all quickstarts to use google-cloud 0.10
bshaffer Oct 7, 2016
4a2c81f
adds projectId back to bigquery, storage, logging, and datastore quic…
bshaffer Oct 8, 2016
bc4e224
Merge branch 'master' into quickstarts
bshaffer Oct 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions datastore/quickstart/quickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
# Instantiates a client
$datastore = new DatastoreClient();

# The kind of the entity to retrieve
# The kind for the new entity
$kind = 'Task';

# The name/ID of the entity to retrieve
# The name/ID for the new entity
$name = 'sampletask1';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"buymilktask"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, what would be the point of the description field in that case?


# The Datastore key for the entity
# The Cloud Datastore key for the new entity
$taskKey = $datastore->key($kind, $name);

# Retrieves the task
$task = $datastore->lookup($taskKey);
# Prepares the new entity
$task = $datastore->entity($taskKey, ['description' => 'Buy milk']);

echo 'Fetched task: ' . $task->key();
# Saves the entity
$datastore->upsert($task);

echo 'Saved ' . $task->key() . ': ' . $task['description'];
Copy link
Contributor

@bshaffer bshaffer Oct 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output will look like this:

Saved [ [Task: simpletask1] ]: Buy Milk

A little weird, but seems ok to me :D

Copy link
Member Author

@jmdobry jmdobry Oct 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't for the life of me get it to just print simpletask1 (which is what I did in other languages).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah, you would have to call $task->key()->path()[0]['name'], which isn't worth it

# [END datastore_quickstart]
return $task;
1 change: 1 addition & 0 deletions datastore/quickstart/test/quickstartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public function testQuickstart()
// Make sure it looks correct
$this->assertInstanceOf('Google\Cloud\Datastore\Entity', $entity);
$this->assertEquals('sampletask1', $entity->key()->path()[0]['name']);
$this->assertEquals('Buy milk', $entity['description']);
}
}