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/upload.rb,
lib/gcloud/backoff.rb,
lib/gcloud/logging.rb,
lib/gcloud/storage.rb,
lib/gcloud/version.rb,
lib/gcloud/bigquery.rb,
lib/gcloud/dns/zone.rb,
lib/gcloud/datastore.rb,
lib/gcloud/translate.rb,
lib/gcloud/dns/change.rb,
lib/gcloud/dns/errors.rb,
lib/gcloud/dns/record.rb,
lib/gcloud/grpc_utils.rb,
lib/gcloud/credentials.rb,
lib/gcloud/dns/project.rb,
lib/gcloud/bigquery/job.rb,
lib/gcloud/dns/importer.rb,
lib/gcloud/logging/sink.rb,
lib/gcloud/pubsub/topic.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/logging/entry.rb,
lib/gcloud/translate/api.rb,
lib/gcloud/bigquery/table.rb,
lib/gcloud/dns/connection.rb,
lib/gcloud/logging/logger.rb,
lib/gcloud/logging/metric.rb,
lib/gcloud/pubsub/message.rb,
lib/gcloud/pubsub/project.rb,
lib/gcloud/pubsub/service.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/logging/project.rb,
lib/gcloud/logging/service.rb,
lib/gcloud/storage/project.rb,
lib/gcloud/bigquery/dataset.rb,
lib/gcloud/bigquery/project.rb,
lib/gcloud/datastore/commit.rb,
lib/gcloud/datastore/entity.rb,
lib/gcloud/datastore/errors.rb,
lib/gcloud/logging/resource.rb,
lib/gcloud/resource_manager.rb,
lib/gcloud/storage/file/acl.rb,
lib/gcloud/translate/errors.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/logging/sink/list.rb,
lib/gcloud/pubsub/topic/list.rb,
lib/gcloud/storage/file/list.rb,
lib/gcloud/bigquery/query_job.rb,
lib/gcloud/logging/entry/list.rb,
lib/gcloud/pubsub/credentials.rb,
lib/gcloud/pubsub/topic/batch.rb,
lib/gcloud/storage/bucket/acl.rb,
lib/gcloud/storage/connection.rb,
lib/gcloud/translate/language.rb,
lib/gcloud/bigquery/connection.rb,
lib/gcloud/bigquery/query_data.rb,
lib/gcloud/bigquery/table/list.rb,
lib/gcloud/logging/credentials.rb,
lib/gcloud/logging/metric/list.rb,
lib/gcloud/pubsub/subscription.rb,
lib/gcloud/storage/bucket/cors.rb,
lib/gcloud/storage/bucket/list.rb,
lib/gcloud/storage/credentials.rb,
lib/gcloud/translate/detection.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/translate/connection.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/translate/translation.rb,
lib/gcloud/bigquery/dataset/access.rb,
lib/gcloud/logging/entry/operation.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/logging/entry/http_request.rb,
lib/gcloud/logging/resource_descriptor.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/logging/resource_descriptor/list.rb,
lib/gcloud/resource_manager/project/updater.rb

Overview

# Google Cloud

Gcloud is the official library for interacting with the Google Cloud Platform. Google Cloud Platform is a set of modular cloud-based services that allow you to create anything from simple websites to complex applications.

Gcloud’s goal is to provide a API that is familiar and comfortable to Rubyists. Authentication is handled by providing project and credential information, or if you are running on Google Compute Engine this configuration is taken care of for you.

You can learn more about various options for connection on the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Defined Under Namespace

Modules: Bigquery, Datastore, Dns, GCE, GRPCUtils, Logging, Pubsub, ResourceManager, Storage, Translate, Upload Classes: AbortedError, AlreadyExistsError, Backoff, CanceledError, Credentials, DataLossError, DeadlineExceededError, Error, FailedPreconditionError, InternalError, InvalidArgumentError, NotFoundError, OutOfRangeError, PermissionDeniedError, ResourceExhaustedError, UnauthenticatedError, UnavailableError, UnimplementedError, UnknownError

Constant Summary collapse

VERSION =
"0.8.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bigquery(project = nil, keyfile = nil, scope: nil) ⇒ Gcloud::Bigquery::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud/bigquery"

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

Parameters:

  • project (String) (defaults to: nil)

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

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/gcloud/bigquery.rb', line 49

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) ⇒ Gcloud::Datastore::Dataset

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

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

Parameters:

Returns:



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

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) ⇒ Gcloud::Dns::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud"

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

zone = dns.zone "example-com"

Parameters:

  • project (String) (defaults to: nil)

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

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

Returns:



50
51
52
53
54
55
56
57
58
# File 'lib/gcloud/dns.rb', line 50

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

.logging(project = nil, keyfile = nil, scope: nil) ⇒ Gcloud::Logging::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud/logging"

gcloud = Gcloud.new
logging = gcloud.logging
# ...

Parameters:

  • project (String) (defaults to: nil)

    Project identifier for the Logging service you are connecting to.

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/gcloud/logging.rb', line 49

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

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

Creates a new object for connecting to Google Cloud.

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud"

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

Parameters:

  • project (String) (defaults to: nil)

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

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

Returns:



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

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) ⇒ Gcloud::Pubsub::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud/pubsub"

pubsub = Gcloud.pubsub

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

Parameters:

  • project (String) (defaults to: nil)

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

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gcloud/pubsub.rb', line 50

def self.pubsub project = nil, keyfile = nil, scope: nil
  project ||= Gcloud::Pubsub::Project.default_project
  if ENV["PUBSUB_EMULATOR_HOST"]
    ps = Gcloud::Pubsub::Project.new project, :this_channel_is_insecure
    ps.service.host = ENV["PUBSUB_EMULATOR_HOST"]
    return ps
  end
  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) ⇒ Gcloud::ResourceManager::Manager

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud/resource_manager"

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

Parameters:

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

Returns:



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

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

.storage(project = nil, keyfile = nil, scope: nil) ⇒ Gcloud::Storage::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

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"

Parameters:

  • project (String) (defaults to: nil)

    Project identifier for the Storage service you are connecting to.

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

Returns:



51
52
53
54
55
56
57
58
59
# File 'lib/gcloud/storage.rb', line 51

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

.translate(key = nil) ⇒ Gcloud::Translate::Api

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

Unlike other Cloud Platform services, which authenticate using a project ID and OAuth 2.0 credentials, Google Translate API requires a public API access key. (This may change in future releases of Google Translate API.) Follow the general instructions at [Identifying your application to Google](cloud.google.com/translate/v2/using_rest#auth), and the specific instructions for [Server keys](cloud.google.com/translate/v2/using_rest#creating-server-api-keys).

Examples:

require "gcloud"

translate = Gcloud.translate "api-key-abc123XYZ789"

translation = translate.translate "Hello world!", to: "la"
translation.text #=> "Salve mundi!"

Using API Key from the environment variable.

require "gcloud"

ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"

translate = Gcloud.translate

translation = translate.translate "Hello world!", to: "la"
translation.text #=> "Salve mundi!"

Parameters:

  • key (String) (defaults to: nil)

    a public API access key (not an OAuth 2.0 token)

Returns:



54
55
56
# File 'lib/gcloud/translate.rb', line 54

def self.translate key = nil
  Gcloud::Translate::Api.new key
end

Instance Method Details

#bigquery(scope: nil) ⇒ Gcloud::Bigquery::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

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

Parameters:

Returns:



224
225
226
227
# File 'lib/gcloud.rb', line 224

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

#datastore(scope: nil) ⇒ Gcloud::Datastore::Dataset

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

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 you can:

require "gcloud"

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

Parameters:

Returns:



104
105
106
107
# File 'lib/gcloud.rb', line 104

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

#dns(scope: nil) ⇒ Gcloud::Dns::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

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

Parameters:

Returns:



264
265
266
267
# File 'lib/gcloud.rb', line 264

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

#logging(scope: nil) ⇒ Gcloud::Logging::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

Examples:

require "gcloud"

gcloud = Gcloud.new
logging = gcloud.logging
# ...

The default scope can be overridden with the ‘scope` option:

require "gcloud"

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

Parameters:

Returns:



346
347
348
349
# File 'lib/gcloud.rb', line 346

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

#pubsub(scope: nil) ⇒ Gcloud::Pubsub::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

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

Parameters:

Returns:



183
184
185
186
# File 'lib/gcloud.rb', line 183

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

#resource_manager(scope: nil) ⇒ Gcloud::ResourceManager::Manager

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

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

Parameters:

Returns:



307
308
309
310
# File 'lib/gcloud.rb', line 307

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

#storage(scope: nil) ⇒ Gcloud::Storage::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).

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:

require "gcloud"

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

Parameters:

Returns:

See Also:



145
146
147
148
# File 'lib/gcloud.rb', line 145

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

#translate(key = nil) ⇒ Gcloud::Translate::Api

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

Unlike other Cloud Platform services, which authenticate using a project ID and OAuth 2.0 credentials, Google Translate API requires a public API access key. (This may change in future releases of Google Translate API.) Follow the general instructions at [Identifying your application to Google](cloud.google.com/translate/v2/using_rest#auth), and the specific instructions for [Server keys](cloud.google.com/translate/v2/using_rest#creating-server-api-keys).

Examples:

require "gcloud"

gcloud = Gcloud.new
translate = gcloud.translate "api-key-abc123XYZ789"

translation = translate.translate "Hello world!", to: "la"
translation.text #=> "Salve mundi!"

Using API Key from the environment variable.

require "gcloud"

ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"

gcloud = Gcloud.new
translate = gcloud.translate

translation = translate.translate "Hello world!", to: "la"
translation.text #=> "Salve mundi!"

Parameters:

  • key (String) (defaults to: nil)

    a public API access key (not an OAuth 2.0 token)

Returns:



387
388
389
390
# File 'lib/gcloud.rb', line 387

def translate key = nil
  require "gcloud/translate"
  Gcloud.translate key
end