gcloud

Idiomatic Ruby client for Google Cloud Platform services.

Travis Build Status Coverage Status

Ruby API Client library for Google Cloud

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.

Quick Start

$ gem install gcloud

Authorization

You need a Google Developers service account to use the Google Cloud services. To create a service account:

  1. Visit the Google Developers Console.
  2. Create a new project or click on an existing project.
  3. Navigate to APIs & auth > APIs section and turn on the following APIs (you may need to enable billing in order to use these services):
    • Google Cloud Datastore API
    • Google Cloud Storage
    • Google Cloud Storage JSON API
  4. Navigate to APIs & auth > Credentials and then:
    • If you want to use a new service account, click on Create new Client ID and select Service account. After the account is created, you will be prompted to download the JSON key file that the library uses to authorize your requests.
    • If you want to generate a new key for an existing service account, click on Generate new JSON key and download the JSON key file.

You will use the Project ID and JSON file to connect to services with gcloud.

Datastore

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.

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

Storage

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.

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

Supported Ruby Versions

gcloud is supported on Ruby 1.9.3+.

Versioning

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.

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Support

Please report bugs at the project on Github. Don't hesitate to ask questions about the client or APIs on StackOverflow.