Skip to content

Commit 9d507af

Browse files
author
remi Taylor
committed
Merge branch 'master' of github.com:GoogleCloudPlatform/ruby-docs-samples into cloud-sql-flex-updates
2 parents e42bfc8 + 8c33a06 commit 9d507af

29 files changed

Lines changed: 778 additions & 54 deletions

appengine/endpoints/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Run the application:
2222

2323
$ bundle exec ruby app.rb -p 8080
2424

25-
In your web browser, go to the following address: http://localhost:8080.
26-
2725
### Using the echo client
2826

2927
With the app running locally, you can execute the simple echo client using:
@@ -104,3 +102,16 @@ Now you can use the client ID to make requests to the API:
104102
--host https://YOUR-PROJECT-ID.appspot.com \
105103
--api_key YOUR-API-KEY \
106104
--client_secrets_file /path/to/client_secrets.json
105+
106+
## Viewing the Endpoints graphs
107+
108+
By using Endpoints, you get access to several metrics that are displayed graphically in the Cloud Console.
109+
110+
To view the Endpoints graphs:
111+
112+
1. Go to the [Endpoints section in Cloud Console](https://console.cloud.google.com/endpoints) of the project you deployed your API to.
113+
2. Click on your API to view more detailed information about the metrics collected.
114+
115+
## Swagger UI
116+
117+
The Swagger UI is an open source Swagger project that allows you to explore your API through a UI. Find out more about it on the [Swagger site](http://swagger.io/swagger-ui/).

appengine/endpoints/app.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,12 @@
1919

2020
require "base64"
2121
require "json"
22-
require "yaml"
2322
require "sinatra"
2423

2524
before do
2625
content_type :json
2726
end
2827

29-
# Shows the index page.
30-
get "/" do
31-
content_type :html
32-
send_file "index.html"
33-
end
34-
35-
# Serves up the Swagger spec for the API.
36-
get "/api-docs" do
37-
YAML.load_file("swagger.yaml").to_json
38-
end
39-
4028
# Simple echo service.
4129
post "/echo" do
4230
message = JSON.parse(request.body.read)["message"]

appengine/endpoints/index.html

Lines changed: 0 additions & 19 deletions
This file was deleted.

appengine/endpoints/spec/endpoint_sample_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@
1313
@app.set :environment, :production
1414
end
1515

16-
it "GET / renders home page" do
17-
get "/"
18-
19-
expect(last_response.status).to eq 200
20-
expect(last_response.content_type).to eq "text/html;charset=utf-8"
21-
expect(last_response.body).to include "Endpoints Sample"
22-
end
23-
24-
it "GET /api-docs renders Swagger specification" do
25-
get "/api-docs"
26-
27-
expect(last_response.status).to eq 200
28-
expect(last_response.content_type).to eq "application/json"
29-
expect(last_response.body).to include '"title":"Endpoints Example"'
30-
end
31-
3216
it "POST /echo renders message from request body" do
3317
post "/echo", '{"message":"hello from test"}'
3418

bigquery/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ Commands:
3636
query <query>
3737
query_job <query>
3838
```
39+

bigquery/quickstart.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
# [START bigquery_quickstart]
16+
# Imports the Google Cloud client library
17+
require "google/cloud"
18+
19+
# Your Google Cloud Platform project ID
20+
project_id = "YOUR_PROJECT_ID"
21+
22+
# Instantiates a client
23+
gcloud = Google::Cloud.new project_id
24+
bigquery = gcloud.bigquery
25+
26+
# The name for the new dataset
27+
dataset_name = "my_new_dataset"
28+
29+
# Creates the new dataset
30+
dataset = bigquery.create_dataset dataset_name
31+
32+
puts "Dataset #{dataset.dataset_id} created."
33+
# [END bigquery_quickstart]
34+

bigquery/spec/bigquery_sample_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def wait_until times: 5, delay: 1, &condition
219219
"Importing data from file: #{csv_file.path}\n"
220220
)
221221
expect(captured_output).to match(
222-
/Waiting for load job to complete: job_\w+/
222+
/Waiting for load job to complete: job/
223223
)
224224
expect(captured_output).to include "Data imported"
225225

@@ -255,7 +255,7 @@ def wait_until times: 5, delay: 1, &condition
255255
"gs://#{@bucket.name}/bigquery-test.csv"
256256
)
257257
expect(captured_output).to match(
258-
/Waiting for load job to complete: job_\w+/
258+
/Waiting for load job to complete: job/
259259
)
260260
expect(captured_output).to include "Data imported"
261261

@@ -323,7 +323,7 @@ def wait_until times: 5, delay: 1, &condition
323323
"gs://#{@bucket.name}/bigquery-test.csv"
324324
)
325325
expect(captured_output).to match(
326-
/Waiting for extract job to complete: job_\w+/
326+
/Waiting for extract job to complete: job/
327327
)
328328
expect(captured_output).to include "Data exported"
329329

bigquery/spec/quickstart_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
require "rspec"
16+
require "google/cloud"
17+
18+
describe "BigQuery Quickstart" do
19+
20+
it "creates a new dataset" do
21+
gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"]
22+
bigquery = gcloud.bigquery
23+
24+
if bigquery.dataset "my_new_dataset"
25+
bigquery.dataset("my_new_dataset").delete
26+
end
27+
28+
expect(bigquery.dataset "my_new_dataset").to be nil
29+
expect(Google::Cloud).to receive(:new).
30+
with("YOUR_PROJECT_ID").
31+
and_return(gcloud)
32+
33+
expect {
34+
load File.expand_path("../quickstart.rb", __dir__)
35+
}.to output(
36+
"Dataset my_new_dataset created\.\n"
37+
).to_stdout
38+
39+
expect(bigquery.dataset "my_new_dataset").not_to be nil
40+
end
41+
42+
end
43+

bigquery/tables.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def create_table project_id:, dataset_id:, table_id:
3131
end
3232

3333
def list_tables project_id:, dataset_id:
34-
# [START list_datasets]
34+
# [START list_tables]
3535
# project_id = "Your Google Cloud project ID"
3636
# dataset_id = "ID of the dataset to create table in"
3737

datastore/quickstart.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
# [START datastore_quickstart]
16+
# Imports the Google Cloud client library
17+
require "google/cloud"
18+
19+
# Your Google Cloud Platform project ID
20+
project_id = "YOUR_PROJECT_ID"
21+
22+
# Instantiates a client
23+
gcloud = Google::Cloud.new project_id
24+
datastore = gcloud.datastore
25+
26+
# The kind for the new entity
27+
kind = "Task"
28+
# The name/ID for the new entity
29+
name = "sampletask1"
30+
# The Cloud Datastore key for the new entity
31+
task_key = datastore.key kind, name
32+
33+
# Prepares the new entity
34+
task = datastore.entity task_key do |t|
35+
t["description"] = "Buy milk"
36+
end
37+
38+
# Saves the entity
39+
datastore.save task
40+
41+
puts "Saved #{task.key.name}: #{task['description']}"
42+
# [END datastore_quickstart]
43+

0 commit comments

Comments
 (0)