-
Notifications
You must be signed in to change notification settings - Fork 209
Add new "quickstart" samples. #77
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
Merged
Merged
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
97b97e9
Add "quickstart" samples.
jmdobry beab134
Tweak Datastore quickstart sample.
jmdobry 318d761
Tweak Datastore quickstart sample.
jmdobry bb13651
Change datastore quickstart sample to create a task.
jmdobry a44f362
Changes:
48b30fe
Changes:
4bcdf07
Changes:
4f1b02c
Changes:
e81e741
Changes:
2590342
Changes:
5e9c228
Changes:
740c7cd
Simplify print statement in Vision quickstart.
jmdobry ca30bc2
Changes:
b41be6a
Changes:
252f7a0
Changes:
88e99a5
Changes:
c82d70c
Changes:
b426429
Changes:
135527c
Changes:
99c4689
Changes:
c389c77
Changes:
019932c
Changes:
87386ef
Changes:
2d1367f
Changes:
71a0f2f
Changes:
c2994e0
Changes:
73fdf64
Removed extra spaces in logging/quickstart.rb
97f366e
Removed %Q{} and used single-quotes instead
3249d27
Removed spaces from assignment in trasnlate
e522da5
Removed multiple label lookup in Vision quickstart_spec.rb (using cat)!
01cd1d8
Added wait_until helper function and removed direct call to sleep
183ef4b
Changes:
7b31107
Merge branch 'master' of github.com:GoogleCloudPlatform/ruby-docs-sam…
a450c94
Changes:
4881ae7
Modified expectation to attempt to fix Travis CI
1e97352
Refactor Logging Quickstart spec and fix by adding order clause to en…
a06b18a
Merge pull request #90 from GoogleCloudPlatform/logging-quickstart-spec
frankyn c0586e7
Removed some spacing found by Vim
73b620b
Changed %{} to %Q{} to be more explicit.
0a17905
Removed order from filter. Using full project path
0e6e529
Modified quickstart spec test to check poliarity
b7eef07
Language Removed _client, _test_client, and shabang line
3447327
Speech quickstart changed fileName -> file_name
ff23358
Vision quickstart: changed fileName -> file_name
64953d3
Vision quickstart spec: added better description
5796925
Language/quickstart.rb Remove unwanted spacing.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,4 @@ Commands: | |
| query <query> | ||
| query_job <query> | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START bigquery_quickstart] | ||
| # Imports the Google Cloud client library | ||
| require "google/cloud" | ||
|
|
||
| # Your Google Cloud Platform project ID | ||
| project_id = "YOUR_PROJECT_ID" | ||
|
|
||
| # Instantiates a client | ||
| gcloud = Google::Cloud.new project_id | ||
| bigquery = gcloud.bigquery | ||
|
|
||
| # The name for the new dataset | ||
| dataset_name = "my_new_dataset" | ||
|
|
||
| # Creates the new dataset | ||
| dataset = bigquery.create_dataset dataset_name | ||
|
|
||
| puts "Dataset #{dataset.dataset_id} created." | ||
| # [END bigquery_quickstart] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "rspec" | ||
| require "google/cloud" | ||
|
|
||
| describe "BigQuery Quickstart" do | ||
|
|
||
| it "creates a new dataset" do | ||
| gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"] | ||
| bigquery = gcloud.bigquery | ||
|
|
||
| if bigquery.dataset "my_new_dataset" | ||
| bigquery.dataset("my_new_dataset").delete | ||
| end | ||
|
|
||
| expect(bigquery.dataset "my_new_dataset").to be nil | ||
| expect(Google::Cloud).to receive(:new). | ||
| with("YOUR_PROJECT_ID"). | ||
| and_return(gcloud) | ||
|
|
||
| expect { | ||
| load File.expand_path("../quickstart.rb", __dir__) | ||
| }.to output( | ||
| "Dataset my_new_dataset created\.\n" | ||
| ).to_stdout | ||
|
|
||
| expect(bigquery.dataset "my_new_dataset").not_to be nil | ||
| end | ||
|
|
||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START datastore_quickstart] | ||
| # Imports the Google Cloud client library | ||
| require "google/cloud" | ||
|
|
||
| # Your Google Cloud Platform project ID | ||
| project_id = "YOUR_PROJECT_ID" | ||
|
|
||
| # Instantiates a client | ||
| gcloud = Google::Cloud.new project_id | ||
| datastore = gcloud.datastore | ||
|
|
||
| # The kind for the new entity | ||
| kind = "Task" | ||
| # The name/ID for the new entity | ||
| name = "sampletask1" | ||
| # The Cloud Datastore key for the new entity | ||
| task_key = datastore.key kind, name | ||
|
|
||
| # Prepares the new entity | ||
| task = datastore.entity task_key do |t| | ||
| t["description"] = "Buy milk" | ||
| end | ||
|
|
||
| # Saves the entity | ||
| datastore.save task | ||
|
|
||
| puts "Saved #{task.key.name}: #{task['description']}" | ||
| # [END datastore_quickstart] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "rspec" | ||
| require "google/cloud" | ||
|
|
||
| describe "Datastore Quickstart" do | ||
|
|
||
| it "creates a new entity" do | ||
| gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"] | ||
| datastore = gcloud.datastore | ||
| task_key = datastore.key "Task", "sampletask1" | ||
|
|
||
| if datastore.find task_key | ||
| task = datastore.find task_key | ||
| datastore.delete task | ||
| end | ||
|
|
||
| expect(datastore.find task_key).to be nil | ||
| expect(Google::Cloud).to receive(:new).with("YOUR_PROJECT_ID"). | ||
| and_return(gcloud) | ||
|
|
||
| expect { | ||
| load File.expand_path("../quickstart.rb", __dir__) | ||
| }.to output { | ||
| "Saved Task: Buy milk\n" | ||
| }.to_stdout | ||
|
|
||
| task_key = datastore.find(task_key) | ||
| expect(task_key).not_to be nil | ||
| expect(task_key["description"]).to eq "Buy milk" | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START language_quickstart] | ||
| # Imports the Google Cloud client library | ||
| require "google/cloud" | ||
|
|
||
| # Your Google Cloud Platform project ID | ||
| project_id = "YOUR_PROJECT_ID" | ||
|
|
||
| # Instantiates a client | ||
| gcloud = Google::Cloud.new project_id | ||
| language_client = gcloud.language | ||
|
|
||
| # The text to analyze | ||
| text = "Hello, world!" | ||
| document = language_client.document text | ||
|
|
||
| # Detects the sentiment of the text | ||
| sentiment = document.sentiment | ||
|
|
||
| puts "Text: #{text}" | ||
| puts "Sentiment: #{sentiment.polarity}, #{sentiment.magnitude}" | ||
| # [END language_quickstart] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/ruby | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove shabang line |
||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "rspec" | ||
| require "google/cloud" | ||
|
|
||
| describe "Language Quickstart" do | ||
|
|
||
| it "detect sentiment" do | ||
| gcloud_test_client = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| expect(Google::Cloud).to receive(:new).with("YOUR_PROJECT_ID"). | ||
| and_return(gcloud_test_client) | ||
|
|
||
| expect { | ||
| load File.expand_path("../quickstart.rb", __dir__) | ||
| }.to output( | ||
| /Text: Hello, world!\nSentiment: 1.0/ | ||
| ).to_stdout | ||
| end | ||
|
|
||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START logging_quickstart] | ||
| # Imports the Google Cloud client library | ||
| require "google/cloud" | ||
|
|
||
| # Your Google Cloud Platform project ID | ||
| project_id = "YOUR_PROJECT_ID" | ||
|
|
||
| # Instantiates a client | ||
| gcloud = Google::Cloud.new project_id | ||
| logging = gcloud.logging | ||
|
|
||
| # Prepares a log entry | ||
| entry = logging.entry | ||
| # The data to log | ||
| entry.payload = "Hello, world!" | ||
| # The name of the log to write to | ||
| entry.log_name = "my-log" | ||
| # The resource associated with the data | ||
| entry.resource.type = "global" | ||
|
|
||
| # Writes the log entry | ||
| logging.write_entries entry | ||
|
|
||
| puts "Logged #{entry.payload}" | ||
| # [END logging_quickstart] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Copyright 2016 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require "rspec" | ||
| require "google/cloud" | ||
|
|
||
| describe "Logging Quickstart" do | ||
|
|
||
| # Simple wait method. Test for condition 5 times, delaying 1 second each time | ||
| def wait_until times: 5, delay: 1, &condition | ||
| times.times do | ||
| return if condition.call | ||
| sleep delay | ||
| end | ||
| raise "Condition not met. Waited #{times} times with #{delay} sec delay" | ||
| end | ||
|
|
||
| before do | ||
| @gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"] | ||
| @logging = @gcloud.logging | ||
| @entry = @logging.entry | ||
| @log_name = "projects/#{ENV["GOOGLE_CLOUD_PROJECT"]}/logs/" + | ||
| "quickstart_log_#{Time.now.to_i}" | ||
|
|
||
| @entry.log_name = @log_name | ||
| end | ||
|
|
||
| after do | ||
| begin | ||
| @logging.delete_log @log_name | ||
| rescue Google::Cloud::NotFoundError | ||
| end | ||
| end | ||
|
|
||
| def test_log_entries | ||
| @logging.entries filter: %Q{logName="#{@log_name}"} | ||
| end | ||
|
|
||
| it "logs a new entry" do | ||
| expect(Google::Cloud).to receive(:new).with("YOUR_PROJECT_ID"). | ||
| and_return(@gcloud) | ||
| expect(@gcloud).to receive(:logging).and_return(@logging) | ||
| expect(@logging).to receive(:entry).and_return(@entry) | ||
| allow(@entry).to receive(:log_name=).with("my-log") | ||
|
|
||
| expect(test_log_entries).to be_empty | ||
|
|
||
| expect { | ||
| load File.expand_path("../quickstart.rb", __dir__) | ||
| }.to output( | ||
| "Logged Hello, world!\n" | ||
| ).to_stdout | ||
|
|
||
| entries = [] | ||
|
|
||
| wait_until { entries = test_log_entries; entries.any? } | ||
|
|
||
| expect(entries).not_to be_empty | ||
| expect(entries.length).to eq 1 | ||
|
|
||
| entry = entries.first | ||
| expect(entry.payload).to eq "Hello, world!" | ||
| end | ||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
language_client-->language