Skip to content

Commit 97b97e9

Browse files
committed
Add "quickstart" samples.
1 parent c312fc5 commit 97b97e9

File tree

11 files changed

+396
-0
lines changed

11 files changed

+396
-0
lines changed

bigquery/quickstart.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START bigquery_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
bigquery_client = gcloud.bigquery
26+
27+
# The name for the new dataset
28+
dataset_name = "my_new_dataset"
29+
30+
# Creates the new dataset
31+
dataset = bigquery_client.create_dataset dataset_name
32+
33+
puts "Dataset #{dataset.dataset_id} created."
34+
# [END bigquery_quickstart]
35+
end
36+
37+
if __FILE__ == $PROGRAM_NAME
38+
run_quickstart
39+
end

datastore/quickstart.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START datastore_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
datastore_client = gcloud.datastore
26+
27+
# The kind of the entity to retrieve
28+
kind = "Task"
29+
# The id of the entity to retrieve
30+
id = 1234567890
31+
# The Datastore key for the entity
32+
task_key = datastore_client.key kind, id
33+
34+
# Retrieves the entity
35+
entity = datastore_client.find task_key
36+
37+
puts "Got entity: #{entity.key.id}"
38+
# [END datastore_quickstart]
39+
end
40+
41+
if __FILE__ == $PROGRAM_NAME
42+
run_quickstart
43+
end
44+

language/quickstart.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START language_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
language_client = gcloud.language
26+
27+
# The text to analyze
28+
text = "Hello, world!"
29+
document = language_client.document text
30+
31+
# Detects the sentiment of the text
32+
sentiment = document.sentiment
33+
34+
puts "Text: #{text}"
35+
puts "Sentiment: #{sentiment.polarity}, #{sentiment.magnitude}"
36+
# [END language_quickstart]
37+
end
38+
39+
if __FILE__ == $PROGRAM_NAME
40+
run_quickstart
41+
end

logging/quickstart.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START logging_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
logging_client = gcloud.logging
26+
27+
# Prepares a log entry
28+
entry = logging.entry
29+
# The data to log
30+
entry.payload = "Hello, world!"
31+
# The name of the log to write to
32+
entry.log_name = "my-log"
33+
# The resource associated with the data
34+
entry.resource.type = "global"
35+
36+
# Writes the log entry
37+
logging_client.write_entries entry
38+
39+
puts "Logged #{entry.payload}"
40+
# [END logging_quickstart]
41+
end
42+
43+
if __FILE__ == $PROGRAM_NAME
44+
run_quickstart
45+
end

pubsub/quickstart.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START pubsub_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
pubsub_client = gcloud.pubsub
26+
27+
# The name for the new topic
28+
topic_name = "my-new-topic"
29+
30+
# Creates the new topic
31+
topic = pubsub_client.create_topic topic_name
32+
33+
puts "Topic #{topic.name} created."
34+
# [END pubsub_quickstart]
35+
end
36+
37+
if __FILE__ == $PROGRAM_NAME
38+
run_quickstart
39+
end

speech/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
source "https://rubygems.org"
1616

1717
gem "google-api-client"
18+
gem "google-cloud-speech"
1819

1920
group :test do
2021
gem "rspec"

speech/Gemfile.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ GEM
1414
mime-types (>= 1.6)
1515
representable (~> 2.3.0)
1616
retriable (~> 2.0)
17+
google-cloud-core (0.20.1)
18+
google-cloud-speech (0.20.0)
19+
google-cloud-core (~> 0.20.0)
20+
google-gax (~> 0.5.0)
21+
google-protobuf (~> 3.0)
22+
googleapis-common-protos (~> 1.3)
23+
grpc (~> 1.0)
24+
google-gax (0.5.1)
25+
googleauth (~> 0.5.1)
26+
grpc (~> 1.0)
27+
rly (~> 0.2.3)
28+
google-protobuf (3.1.0)
29+
googleapis-common-protos (1.3.4)
30+
google-protobuf (~> 3.0)
31+
grpc (~> 1.0)
1732
googleauth (0.5.1)
1833
faraday (~> 0.9)
1934
jwt (~> 1.4)
@@ -22,6 +37,9 @@ GEM
2237
multi_json (~> 1.11)
2338
os (~> 0.9)
2439
signet (~> 0.7)
40+
grpc (1.0.0)
41+
google-protobuf (~> 3.0)
42+
googleauth (~> 0.5.1)
2543
httpclient (2.8.2.4)
2644
hurley (0.2)
2745
jwt (1.5.6)
@@ -39,6 +57,7 @@ GEM
3957
representable (2.3.0)
4058
uber (~> 0.0.7)
4159
retriable (2.1.0)
60+
rly (0.2.3)
4261
rspec (3.5.0)
4362
rspec-core (~> 3.5.0)
4463
rspec-expectations (~> 3.5.0)
@@ -64,6 +83,7 @@ PLATFORMS
6483

6584
DEPENDENCIES
6685
google-api-client
86+
google-cloud-speech
6787
rspec
6888

6989
BUNDLED WITH

speech/quickstart.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START speech_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
speech_client = gcloud.speech
26+
27+
# The name of the audio file to transcribe
28+
fileName = "./audio_files/audio.raw"
29+
30+
# The audio file's encoding and sample rate
31+
audio = speech_client.audio fileName,
32+
encoding: :raw, sample_rate: 16000
33+
34+
# Detects speech in the audio file
35+
results = audio.recognize
36+
result = results.first
37+
38+
puts "Transcription: #{result.transcript}"
39+
# [END speech_quickstart]
40+
end
41+
42+
if __FILE__ == $PROGRAM_NAME
43+
run_quickstart
44+
end

storage/quickstart.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START storage_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Google Cloud Platform project ID
21+
project_id = "YOUR_PROJECT_ID"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new project_id
25+
storage_client = gcloud.storage
26+
27+
# The name for the new bucket
28+
bucket_name = "my-new-bucket"
29+
30+
# Creates the new bucket
31+
bucket = storage_client.create_bucket bucket_name
32+
33+
puts "Bucket #{bucket.name} created."
34+
# [END storage_quickstart]
35+
end
36+
37+
if __FILE__ == $PROGRAM_NAME
38+
run_quickstart
39+
end

translate/quickstart.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def run_quickstart
16+
# [START translate_quickstart]
17+
# Imports the Google Cloud client library
18+
require "google/cloud"
19+
20+
# Your Translate API key
21+
api_key = "YOUR_API_KEY"
22+
23+
# Instantiates a client
24+
gcloud = Google::Cloud.new
25+
translate_client = gcloud.translate api_key
26+
27+
# The text to translate
28+
text = "Hello, world!"
29+
# The target language
30+
target = "ru"
31+
32+
# Translates some text into Russian
33+
translation = translate_client.translate text, to: target
34+
35+
puts "Text: #{text}"
36+
puts "Translation: #{translation}"
37+
# [END translate_quickstart]
38+
end
39+
40+
if __FILE__ == $PROGRAM_NAME
41+
run_quickstart
42+
end

0 commit comments

Comments
 (0)