Gcloud
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.
Methods
Constants
- VERSION
Public Class Methods
bigquery(project = nil, keyfile = nil, options = {})
¶
↑
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
orHash
) options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scope is:
-
https://www.googleapis.com/auth/bigquery
-
Returns¶ ↑
Example¶ ↑
require "gcloud/bigquery" bigquery = Gcloud.bigquery dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table"
datastore(project = nil, keyfile = nil, options = {})
¶
↑
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
orHash
) options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scopes are:
-
https://www.googleapis.com/auth/datastore
-
https://www.googleapis.com/auth/userinfo.email
-
Returns¶ ↑
Example¶ ↑
require "gcloud/datastore" dataset = Gcloud.datastore "my-todo-project", "/path/to/keyfile.json" entity = Gcloud::Datastore::Entity.new entity.key = Gcloud::Datastore::Key.new "Task" entity["description"] = "Get started with Google Cloud" entity["completed"] = false dataset.save entity
new(project = nil, keyfile = nil)
¶
↑
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
orHash
)
Returns¶ ↑
Example¶ ↑
require "gcloud" gcloud = Gcloud.new dataset = gcloud.datastore pubsub = gcloud.pubsub storage = gcloud.storage
pubsub(project = nil, keyfile = nil, options = {})
¶
↑
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
orHash
) options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scope is:
-
https://www.googleapis.com/auth/pubsub
-
Returns¶ ↑
Example¶ ↑
require "gcloud/pubsub" pubsub = Gcloud.pubsub topic = pubsub.topic "my-topic" topic.publish "task completed"
storage(project = nil, keyfile = nil, options = {})
¶
↑
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
orHash
) options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scope is:
-
https://www.googleapis.com/auth/devstorage.full_control
-
Returns¶ ↑
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"
Public Instance Methods
bigquery(options = {})
¶
↑
Creates a new object for connecting to the BigQuery service. Each call creates a new connection.
Parameters¶ ↑
options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scope is:
-
https://www.googleapis.com/auth/bigquery
-
Returns¶ ↑
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
datastore(options = {})
¶
↑
Creates a new object for connecting to the Datastore service. Each call creates a new connection.
Parameters¶ ↑
options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scopes are:
-
https://www.googleapis.com/auth/datastore
-
https://www.googleapis.com/auth/userinfo.email
-
Returns¶ ↑
Examples¶ ↑
require "gcloud" gcloud = Gcloud.new dataset = gcloud.datastore entity = Gcloud::Datastore::Entity.new entity.key = Gcloud::Datastore::Key.new "Task" entity["description"] = "Get started with Google Cloud" entity["completed"] = false 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
pubsub(options = {})
¶
↑
Creates a new object for connecting to the Pub/Sub service. Each call creates a new connection.
Parameters¶ ↑
options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scope is:
-
https://www.googleapis.com/auth/pubsub
-
Returns¶ ↑
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
storage(options = {})
¶
↑
Creates a new object for connecting to the Storage service. Each call creates a new connection.
Parameters¶ ↑
options
-
An optional Hash for controlling additional behavior. (
Hash
) options[: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
orArray
)The default scope is:
-
https://www.googleapis.com/auth/devstorage.full_control
-
Returns¶ ↑
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