Idiomatic Ruby client for Google Cloud Platform services.
This client supports the following Google Cloud Platform services:
If you need support for other Google APIs, check out the Google API Ruby Client library.
$ gem install gcloud
Gcloud uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables. Additionally, Cloud SDK credentials can also be discovered automatically, but this is only recommended during development.
Instructions and configuration options are covered in the Authentication guide. The examples in Quick Start will demonstrate providing the Project ID and Credentials JSON file path in code.
Google Cloud Datastore (docs) is a fully managed, schemaless database for storing non-relational data. Cloud Datastore automatically scales with your users and supports ACID transactions, high availability of reads and writes, strong consistency for reads and ancestor queries, and eventual consistency for all other queries.
Follow the activation instructions to use the Google Cloud Datastore API with your project.
See the gcloud-ruby Datastore API documentation to learn how to interact with the Cloud Datastore using this library.
require 'gcloud/datastore'
dataset = Gcloud.datastore "my-todo-project-id",
"/path/to/keyfile.json"
# Create a new task to demo datastore
demo_task = Gcloud::Datastore::Entity.new
demo_task.key = Gcloud::Datastore::Key.new "Task", "datastore-demo"
demo_task[:description] = "Demonstrate Datastore functionality"
demo_task[:completed] = false
# Save the new task
dataset.save demo_task
# Run a query for all completed tasks
query = Gcloud::Datastore::Query.new.kind("Task").
where("completed", "=", true)
completed_tasks = dataset.run query
Google Cloud Storage (docs) allows you to store data on Google infrastructure with very high reliability, performance and availability, and can be used to distribute large data objects to users via direct download.
See the gcloud-ruby Storage API documentation to learn how to connect to Cloud Storage using this library.
require 'gcloud/storage'
storage = Gcloud.storage "my-todo-project-id",
"/path/to/keyfile.json"
bucket = storage.find_bucket "task-attachments"
file = bucket.find_file "path/to/my-file.ext"
# Download the file to the local file system
file.download "/tasks/attachments/#{file.name}"
# Copy the file to a backup bucket
backup = storage.find_bucket "task-attachment-backups"
file.copy backup, file.name
gcloud is supported on Ruby 1.9.3+.
This library follows Semantic Versioning.
It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
Contributions to this library are always welcome and highly encouraged.
See CONTRIBUTING for more information on how to get started.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
Please report bugs at the project on Github. Don't hesitate to ask questions about the client or APIs on StackOverflow.