Module: Gcloud

Defined in:
lib/gcloud.rb,
lib/gcloud/dns.rb,
lib/gcloud/gce.rb,
lib/gcloud/errors.rb,
lib/gcloud/pubsub.rb,
lib/gcloud/search.rb,
lib/gcloud/upload.rb,
lib/gcloud/backoff.rb,
lib/gcloud/storage.rb,
lib/gcloud/version.rb,
lib/gcloud/bigquery.rb,
lib/gcloud/dns/zone.rb,
lib/gcloud/datastore.rb,
lib/gcloud/dns/change.rb,
lib/gcloud/dns/errors.rb,
lib/gcloud/dns/record.rb,
lib/gcloud/credentials.rb,
lib/gcloud/dns/project.rb,
lib/gcloud/bigquery/job.rb,
lib/gcloud/dns/importer.rb,
lib/gcloud/pubsub/topic.rb,
lib/gcloud/search/index.rb,
lib/gcloud/storage/file.rb,
lib/gcloud/bigquery/data.rb,
lib/gcloud/bigquery/view.rb,
lib/gcloud/datastore/key.rb,
lib/gcloud/dns/zone/list.rb,
lib/gcloud/pubsub/errors.rb,
lib/gcloud/search/errors.rb,
lib/gcloud/search/fields.rb,
lib/gcloud/search/result.rb,
lib/gcloud/bigquery/table.rb,
lib/gcloud/dns/connection.rb,
lib/gcloud/pubsub/message.rb,
lib/gcloud/pubsub/project.rb,
lib/gcloud/search/project.rb,
lib/gcloud/storage/bucket.rb,
lib/gcloud/storage/errors.rb,
lib/gcloud/bigquery/errors.rb,
lib/gcloud/datastore/proto.rb,
lib/gcloud/datastore/query.rb,
lib/gcloud/dns/change/list.rb,
lib/gcloud/dns/credentials.rb,
lib/gcloud/dns/record/list.rb,
lib/gcloud/search/document.rb,
lib/gcloud/storage/project.rb,
lib/gcloud/bigquery/dataset.rb,
lib/gcloud/bigquery/project.rb,
lib/gcloud/datastore/entity.rb,
lib/gcloud/datastore/errors.rb,
lib/gcloud/resource_manager.rb,
lib/gcloud/storage/file/acl.rb,
lib/gcloud/bigquery/copy_job.rb,
lib/gcloud/bigquery/job/list.rb,
lib/gcloud/bigquery/load_job.rb,
lib/gcloud/datastore/dataset.rb,
lib/gcloud/pubsub/connection.rb,
lib/gcloud/pubsub/topic/list.rb,
lib/gcloud/search/api_client.rb,
lib/gcloud/search/connection.rb,
lib/gcloud/search/index/list.rb,
lib/gcloud/storage/file/list.rb,
lib/gcloud/bigquery/query_job.rb,
lib/gcloud/pubsub/credentials.rb,
lib/gcloud/search/credentials.rb,
lib/gcloud/search/field_value.rb,
lib/gcloud/search/result/list.rb,
lib/gcloud/storage/bucket/acl.rb,
lib/gcloud/storage/connection.rb,
lib/gcloud/bigquery/connection.rb,
lib/gcloud/bigquery/query_data.rb,
lib/gcloud/bigquery/table/list.rb,
lib/gcloud/pubsub/subscription.rb,
lib/gcloud/search/field_values.rb,
lib/gcloud/storage/bucket/cors.rb,
lib/gcloud/storage/bucket/list.rb,
lib/gcloud/storage/credentials.rb,
lib/gcloud/bigquery/credentials.rb,
lib/gcloud/bigquery/extract_job.rb,
lib/gcloud/datastore/connection.rb,
lib/gcloud/datastore/properties.rb,
lib/gcloud/dns/zone/transaction.rb,
lib/gcloud/search/document/list.rb,
lib/gcloud/bigquery/dataset/list.rb,
lib/gcloud/bigquery/table/schema.rb,
lib/gcloud/datastore/credentials.rb,
lib/gcloud/datastore/transaction.rb,
lib/gcloud/proto/datastore_v1.pb.rb,
lib/gcloud/storage/file/verifier.rb,
lib/gcloud/bigquery/dataset/access.rb,
lib/gcloud/pubsub/received_message.rb,
lib/gcloud/resource_manager/errors.rb,
lib/gcloud/bigquery/insert_response.rb,
lib/gcloud/pubsub/subscription/list.rb,
lib/gcloud/resource_manager/manager.rb,
lib/gcloud/resource_manager/project.rb,
lib/gcloud/resource_manager/connection.rb,
lib/gcloud/resource_manager/credentials.rb,
lib/gcloud/resource_manager/project/list.rb,
lib/gcloud/datastore/dataset/query_results.rb,
lib/gcloud/datastore/dataset/lookup_results.rb,
lib/gcloud/resource_manager/project/updater.rb

Overview

– Copyright 2015 Google Inc. All rights reserved.

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.

Defined Under Namespace

Modules: Bigquery, Datastore, Dns, GCE, Pubsub, ResourceManager, Search, Storage, Upload Classes: Backoff, Credentials, Error

Constant Summary collapse

VERSION =
"0.6.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bigquery(project = nil, keyfile = nil, scope: nil) ⇒ Object

Creates a new Project instance connected to the BigQuery service. Each call creates a new connection.

Parameters

project

Identifier for a BigQuery project. If not present, the default project for the credentials is used. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/bigquery

Returns

Gcloud::Bigquery::Project

Example

require "gcloud/bigquery"

bigquery = Gcloud.bigquery
dataset = bigquery.dataset "my_dataset"
table = dataset.table "my_table"


55
56
57
58
59
60
61
62
63
# File 'lib/gcloud/bigquery.rb', line 55

def self.bigquery project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Bigquery::Project.default_project
  if keyfile.nil?
    credentials = Gcloud::Bigquery::Credentials.default scope: scope
  else
    credentials = Gcloud::Bigquery::Credentials.new keyfile, scope: scope
  end
  Gcloud::Bigquery::Project.new project, credentials
end

.datastore(project = nil, keyfile = nil, scope: nil) ⇒ Object

Creates a new object for connecting to the Datastore service. Each call creates a new connection.

Parameters

project

Dataset identifier for the Datastore you are connecting to. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scopes are:

  • https://www.googleapis.com/auth/datastore

  • https://www.googleapis.com/auth/userinfo.email

Returns

Gcloud::Datastore::Dataset

Example

require "gcloud/datastore"

dataset = Gcloud.datastore "my-todo-project",
                           "/path/to/keyfile.json"

entity = dataset.entity "Task" do |t|
  t["description"] = "Get started with Google Cloud"
  t["completed"] = false
end

dataset.save entity


65
66
67
68
69
70
71
72
73
# File 'lib/gcloud/datastore.rb', line 65

def self.datastore project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Datastore::Dataset.default_project
  if keyfile.nil?
    credentials = Gcloud::Datastore::Credentials.default scope: scope
  else
    credentials = Gcloud::Datastore::Credentials.new keyfile, scope: scope
  end
  Gcloud::Datastore::Dataset.new project, credentials
end

.dns(project = nil, keyfile = nil, scope: nil) ⇒ Object

Creates a new Project instance connected to the DNS service. Each call creates a new connection.

Parameters

project

Identifier for a DNS project. If not present, the default project for the credentials is used. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/ndev.clouddns.readwrite

Returns

Gcloud::Dns::Project

Example

require "gcloud"

dns = Gcloud.dns "my-dns-project",
                 "/path/to/keyfile.json"

zone = dns.zone "example-com"


56
57
58
59
60
61
62
63
64
# File 'lib/gcloud/dns.rb', line 56

def self.dns project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Dns::Project.default_project
  if keyfile.nil?
    credentials = Gcloud::Dns::Credentials.default scope: scope
  else
    credentials = Gcloud::Dns::Credentials.new keyfile, scope: scope
  end
  Gcloud::Dns::Project.new project, credentials
end

.new(project = nil, keyfile = nil) ⇒ Object

Creates a new object for connecting to Google Cloud.

Parameters

project

Project identifier for the Pub/Sub service you are connecting to. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

Returns

Gcloud

Example

require "gcloud"

gcloud  = Gcloud.new
dataset = gcloud.datastore
pubsub  = gcloud.pubsub
storage = gcloud.storage


59
60
61
62
63
64
65
66
67
# File 'lib/gcloud.rb', line 59

def self.new project = nil, keyfile = nil
  gcloud = Object.new
  gcloud.instance_eval do
    @project = project
    @keyfile = keyfile
  end
  gcloud.extend Gcloud
  gcloud
end

.pubsub(project = nil, keyfile = nil, scope: nil) ⇒ Object

Creates a new object for connecting to the Pub/Sub service. Each call creates a new connection.

Parameters

project

Project identifier for the Pub/Sub service you are connecting to. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/pubsub

Returns

Gcloud::Pubsub::Project

Example

require "gcloud/pubsub"

pubsub = Gcloud.pubsub

topic = pubsub.topic "my-topic"
topic.publish "task completed"


57
58
59
60
61
62
63
64
65
# File 'lib/gcloud/pubsub.rb', line 57

def self.pubsub project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Pubsub::Project.default_project
  if keyfile.nil?
    credentials = Gcloud::Pubsub::Credentials.default scope: scope
  else
    credentials = Gcloud::Pubsub::Credentials.new keyfile, scope: scope
  end
  Gcloud::Pubsub::Project.new project, credentials
end

.resource_manager(keyfile = nil, scope: nil) ⇒ Object

Creates a new Project instance connected to the Resource Manager service. Each call creates a new connection.

Parameters

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/cloud-platform

Returns

Gcloud::ResourceManager::Manager

Example

require "gcloud/resource_manager"

resource_manager = Gcloud.resource_manager
resource_manager.projects.each do |project|
  puts projects.project_id
end


53
54
55
56
57
58
59
60
61
# File 'lib/gcloud/resource_manager.rb', line 53

def self.resource_manager keyfile = nil, scope: nil
  if keyfile.nil?
    credentials = Gcloud::ResourceManager::Credentials.default scope: scope
  else
    credentials = Gcloud::ResourceManager::Credentials.new keyfile,
                                                           scope: scope
  end
  Gcloud::ResourceManager::Manager.new credentials
end

.search(project = nil, keyfile = nil, scope: nil) ⇒ Object

Creates a new Project instance connected to the Search service. Each call creates a new connection.

Parameters

project

Identifier for a Search project. If not present, the default project for the credentials is used. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

+scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scopes are:

  • https://www.googleapis.com/auth/cloudsearch

  • https://www.googleapis.com/auth/userinfo.email

Returns

Gcloud::Search::Project



47
48
49
50
51
52
53
54
55
# File 'lib/gcloud/search.rb', line 47

def self.search project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Search::Project.default_project
  if keyfile.nil?
    credentials = Gcloud::Search::Credentials.default scope: scope
  else
    credentials = Gcloud::Search::Credentials.new keyfile, scope: scope
  end
  Gcloud::Search::Project.new project, credentials
end

.storage(project = nil, keyfile = nil, scope: nil) ⇒ Object

Creates a new object for connecting to the Storage service. Each call creates a new connection.

Parameters

project

Project identifier for the Storage service you are connecting to. (String)

keyfile

Keyfile downloaded from Google Cloud. If file path the file must be readable. (String or Hash)

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/devstorage.full_control

Returns

Gcloud::Storage::Project

Example

require "gcloud/storage"

storage = Gcloud.storage "my-todo-project",
                         "/path/to/keyfile.json"

bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"


58
59
60
61
62
63
64
65
66
# File 'lib/gcloud/storage.rb', line 58

def self.storage project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Storage::Project.default_project
  if keyfile.nil?
    credentials = Gcloud::Storage::Credentials.default scope: scope
  else
    credentials = Gcloud::Storage::Credentials.new keyfile, scope: scope
  end
  Gcloud::Storage::Project.new project, credentials
end

Instance Method Details

#bigquery(scope: nil) ⇒ Object

Creates a new object for connecting to the BigQuery service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/bigquery

Returns

Gcloud::Bigquery::Project

Examples

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery
dataset = bigquery.dataset "my-dataset"
table = dataset.table "my-table"
table.data.each do |row|
  puts row
end

The default scope can be overridden with the scope option:

require "gcloud"

gcloud  = Gcloud.new
platform_scope = "https://www.googleapis.com/auth/cloud-platform"
bigquery = gcloud.bigquery scope: platform_scope


244
245
246
247
# File 'lib/gcloud.rb', line 244

def bigquery scope: nil
  require "gcloud/bigquery"
  Gcloud.bigquery @project, @keyfile, scope: scope
end

#datastore(scope: nil) ⇒ Object

Creates a new object for connecting to the Datastore service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scopes are:

  • https://www.googleapis.com/auth/datastore

  • https://www.googleapis.com/auth/userinfo.email

Returns

Gcloud::Datastore::Dataset

Examples

require "gcloud"

gcloud  = Gcloud.new
dataset = gcloud.datastore

entity = dataset.entity "Task" do |t|
  t["description"] = "Get started with Google Cloud"
  t["completed"] = false
end

dataset.save entity

You shouldn’t need to override the default scope, but it is possible to do so with the scope option:

require "gcloud"

gcloud  = Gcloud.new
platform_scope = "https://www.googleapis.com/auth/cloud-platform"
dataset = gcloud.datastore scope: platform_scope


113
114
115
116
# File 'lib/gcloud.rb', line 113

def datastore scope: nil
  require "gcloud/datastore"
  Gcloud.datastore @project, @keyfile, scope: scope
end

#dns(scope: nil) ⇒ Object

Creates a new object for connecting to the DNS service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/ndev.clouddns.readwrite

Returns

Gcloud::Dns::Project

Examples

require "gcloud"

gcloud = Gcloud.new
dns = gcloud.dns
zone = dns.zone "example-zone"
zone.records.each do |record|
  puts record.name
end

The default scope can be overridden with the scope option:

require "gcloud"

gcloud  = Gcloud.new
readonly_scope = "https://www.googleapis.com/auth/ndev.clouddns.readonly"
dns = gcloud.dns scope: readonly_scope


288
289
290
291
# File 'lib/gcloud.rb', line 288

def dns scope: nil
  require "gcloud/dns"
  Gcloud.dns @project, @keyfile, scope: scope
end

#pubsub(scope: nil) ⇒ Object

Creates a new object for connecting to the Pub/Sub service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/pubsub

Returns

Gcloud::Pubsub::Project

Examples

require "gcloud"

gcloud = Gcloud.new
pubsub = gcloud.pubsub
topic = pubsub.topic "my-topic"
topic.publish "task completed"

The default scope can be overridden with the scope option:

require "gcloud"

gcloud  = Gcloud.new
platform_scope = "https://www.googleapis.com/auth/cloud-platform"
pubsub = gcloud.pubsub scope: platform_scope


199
200
201
202
# File 'lib/gcloud.rb', line 199

def pubsub scope: nil
  require "gcloud/pubsub"
  Gcloud.pubsub @project, @keyfile, scope: scope
end

#resource_manager(scope: nil) ⇒ Object

Creates a new object for connecting to the Resource Manager service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/cloud-platform

Returns

Gcloud::ResourceManager::Manager

Examples

require "gcloud"

gcloud = Gcloud.new
resource_manager = gcloud.resource_manager
resource_manager.projects.each do |project|
  puts projects.project_id
end

The default scope can be overridden with the scope option:

require "gcloud"

gcloud  = Gcloud.new
readonly_scope = "https://www.googleapis.com/auth/cloudresourcemanager.readonly"
resource_manager = gcloud.resource_manager scope: readonly_scope


335
336
337
338
# File 'lib/gcloud.rb', line 335

def resource_manager scope: nil
  require "gcloud/resource_manager"
  Gcloud.resource_manager @keyfile, scope: scope
end

#search(scope: nil) ⇒ Object

Creates a new object for connecting to the Search service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scopes are:

  • https://www.googleapis.com/auth/cloudsearch

  • https://www.googleapis.com/auth/userinfo.email

Returns

Gcloud::Search::Project

Examples

require "gcloud"


367
368
369
370
# File 'lib/gcloud.rb', line 367

def search scope: nil
  require "gcloud/search"
  Gcloud.search @project, @keyfile, scope: scope
end

#storage(scope: nil) ⇒ Object

Creates a new object for connecting to the Storage service. Each call creates a new connection.

Parameters

scope

The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. (String or Array)

The default scope is:

  • https://www.googleapis.com/auth/devstorage.full_control

Returns

Gcloud::Storage::Project

Examples

require "gcloud"

gcloud  = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"

The default scope can be overridden with the scope option. For more information see Storage OAuth 2.0 Authentication.

require "gcloud"

gcloud  = Gcloud.new
readonly_scope = "https://www.googleapis.com/auth/devstorage.read_only"
readonly_storage = gcloud.storage scope: readonly_scope


157
158
159
160
# File 'lib/gcloud.rb', line 157

def storage scope: nil
  require "gcloud/storage"
  Gcloud.storage @project, @keyfile, scope: scope
end