Google Cloud Client Library for Ruby
Ruby C Python HTML DIGITAL Command Language JavaScript
Switch branches/tags
v0.20.0 v0.12.2 v0.12.1 v0.12.0 v0.11.0 v0.10.0 v0.9.0 v0.8.2 v0.8.1 v0.8.0 v0.7.2 v0.7.1 v0.7.0 v0.6.3 v0.6.2 v0.6.1 v0.6.0 v0.5.0 v0.4.1 v0.4.0 v0.3.1 v0.3.0 v0.2.0 v0.1.1 v0.1.0 stackdriver/v0.15.0 stackdriver/v0.14.0 stackdriver/v0.13.0 stackdriver/v0.12.0 stackdriver/v0.11.0 stackdriver/v0.10.0 stackdriver/v0.9.0 stackdriver/v0.8.0 stackdriver/v0.7.0 stackdriver/v0.6.0 stackdriver/v0.5.0 stackdriver/v0.4.1 stackdriver/v0.4.0 stackdriver/v0.3.0 stackdriver-vore/v1.1.0 stackdriver-core/v1.3.0 stackdriver-core/v1.2.0 stackdriver-core/v1.1.0 stackdriver-core/v1.0.0 stackdriver-core/v0.21.0 stackdirver/v0.3.0 google-cloud/v0.55.0 google-cloud/v0.54.0 google-cloud/v0.53.0 google-cloud/v0.52.0 google-cloud/v0.51.1 google-cloud/v0.51.0 google-cloud/v0.50.0 google-cloud/v0.49.0 google-cloud/v0.48.0 google-cloud/v0.47.0 google-cloud/v0.46.0 google-cloud/v0.45.0 google-cloud/v0.44.0 google-cloud/v0.43.0 google-cloud/v0.42.0 google-cloud/v0.41.0 google-cloud/v0.40.0 google-cloud/v0.39.0 google-cloud/v0.38.0 google-cloud/v0.37.0 google-cloud/v0.36.0 google-cloud/v0.35.0 google-cloud/v0.34.0 google-cloud/v0.33.0 google-cloud/v0.32.0 google-cloud/v0.31.0 google-cloud/v0.30.0 google-cloud/v0.29.0 google-cloud/v0.28.0 google-cloud/v0.27.0 google-cloud/v0.26.0 google-cloud/v0.25.0 google-cloud/v0.24.0 google-cloud/v0.23.0 google-cloud/v0.22.0 google-cloud/v0.21.1 google-cloud/v0.21.0 google-cloud/v0.20.1 google-cloud/v0.20.0 google-cloud-vision/v0.30.0 google-cloud-vision/v0.29.1 google-cloud-vision/v0.29.0 google-cloud-vision/v0.28.0 google-cloud-vision/v0.27.0 google-cloud-vision/v0.26.0 google-cloud-vision/v0.25.0 google-cloud-vision/v0.24.0 google-cloud-vision/v0.23.0 google-cloud-vision/v0.22.1 google-cloud-vision/v0.22.0 google-cloud-vision/v0.21.1 google-cloud-vision/v0.21.0 google-cloud-vision/v0.20.2 google-cloud-vision/v0.20.1
Nothing to show
Clone or download
TheRoyalTnetennba Release google-cloud-vision v0.30.0
* Add async_batch_annotate_files method to Google::Cloud::Vision::Project
Latest commit 5e4cb33 Jul 20, 2018
Permalink
Failed to load latest commit information.
.circleci Migrate to CircleCI 2.0 (#2190) Jul 20, 2018
acceptance/data Update BigQuery acceptance testing Jun 27, 2018
docs Release google-cloud-vision v0.30.0 Jul 20, 2018
gcloud Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-bigquery-data_transfer Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-bigquery Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-bigtable Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-container Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-core Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-dataproc Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-datastore Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-debugger Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-dialogflow Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-dlp Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-dns Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-env Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-error_reporting Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-firestore Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-kms fix docs versioning Jul 9, 2018
google-cloud-language Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-logging Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-monitoring Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-os_login Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-pubsub Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-redis Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-resource_manager Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-spanner Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-speech Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-storage Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-tasks Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-text_to_speech Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-trace Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-translate Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-video_intelligence Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
google-cloud-vision Release google-cloud-vision v0.30.0 Jul 20, 2018
google-cloud Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
integration Update Apache Licence URL Dec 16, 2017
stackdriver-core Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
stackdriver Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
.appveyor.yml Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
.gitignore Update Vision V1 Generated Files (#2145) Jun 21, 2018
.travis.yml Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
AUTHENTICATION.md Update authentication documentation Dec 29, 2017
CODE_OF_CONDUCT.md Add Code of Conduct Aug 25, 2015
CONTRIBUTING.md Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
Gemfile Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
LICENSE Update Apache Licence URL Dec 16, 2017
README.md Officially support only Ruby 2.3 and later (#2130) Jul 20, 2018
RELEASING.md Update RELEASING.MD May 30, 2018
Rakefile Release google-cloud-text_to_speech 0.1.0 Jul 9, 2018
Vagrantfile Switch vagrant to use ruby 2.3 Dec 28, 2015

README.md

Google Cloud Ruby Client

Idiomatic Ruby client for Google Cloud Platform services.

CircleCI Build Status Travis-CI Build Status AppVeyor Build Status Coverage Status Gem Version

This client supports the following Google Cloud Platform services at a General Availability (GA) quality level:

This client supports the following Google Cloud Platform services at a Beta quality level:

This client supports the following Google Cloud Platform services at an Alpha quality level:

The support for each service is distributed as a separate gem. However, for your convenience, the google-cloud gem lets you install the entire collection.

If you need support for other Google APIs, check out the Google API Ruby Client library.

Quick Start

$ gem install google-cloud

The google-cloud gem shown above provides all of the individual service gems in the google-cloud-ruby project, making it easy to explore Google Cloud Platform. To avoid unnecessary dependencies, you can also install the service gems independently.

Authentication

In general, the google-cloud-ruby library 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 keyfile for the account (or the JSON itself) in environment variables. Additionally, Cloud SDK credentials can also be discovered automatically, but this is only recommended during development.

General instructions, environment variables, and configuration options are covered in the general Authentication guide for the google-cloud umbrella package. Specific instructions and environment variables for each individual service are linked from the README documents listed below for each service.

The preview examples below demonstrate how to provide the Project ID and Credentials JSON file path directly in code.

BigQuery (GA)

Quick Start

$ gem install google-cloud-bigquery

Preview

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.create_dataset "my_dataset"

table = dataset.create_table "my_table" do |t|
  t.name = "My Table",
  t.description = "A description of my table."
  t.schema do |s|
    s.string "first_name", mode: :required
    s.string "last_name", mode: :required
    s.integer "age", mode: :required
  end
end

# Load data into the table from Google Cloud Storage
table.load "gs://my-bucket/file-name.csv"

# Run a query
data = dataset.query "SELECT first_name FROM my_table"

data.each do |row|
  puts row[:first_name]
end

BigQuery Data Transfer API (Beta)

Quick Start

$ gem install google-cloud-bigquery-data_transfer

Preview

require "google/cloud/bigquery/data_transfer"

data_transfer_service_client = Google::Cloud::Bigquery::DataTransfer.new
formatted_parent = Google::Cloud::Bigquery::DataTransfer::V1::DataTransferServiceClient.project_path(project_id)

# Iterate over all results.
data_transfer_service_client.list_data_sources(formatted_parent).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
data_transfer_service_client.list_data_sources(formatted_parent).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Cloud Datastore (GA)

Follow the activation instructions to use the Google Cloud Datastore API with your project.

Quick Start

$ gem install google-cloud-datastore

Preview

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new(
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"
)

# Create a new task to demo datastore
task = datastore.entity "Task", "sampleTask" do |t|
  t["type"] = "Personal"
  t["done"] = false
  t["priority"] = 4
  t["description"] = "Learn Cloud Datastore"
end

# Save the new task
datastore.save task

# Run a query for all completed tasks
query = datastore.query("Task").
  where("done", "=", false)
tasks = datastore.run query

Stackdriver Debugger (Beta)

Quick Start

$ gem install google-cloud-debugger

Preview

require "google/cloud/debugger"

debugger = Google::Cloud::Debugger.new
debugger.start

Cloud DNS (Alpha)

Quick Start

$ gem install google-cloud-dns

Preview

require "google/cloud/dns"

dns = Google::Cloud::Dns.new

# Retrieve a zone
zone = dns.zone "example-com"

# Update records in the zone
change = zone.update do |tx|
  tx.add     "www", "A",  86400, "1.2.3.4"
  tx.remove  "example.com.", "TXT"
  tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
                                           "20 mail2.example.com."]
  tx.modify "www.example.com.", "CNAME" do |r|
    r.ttl = 86400 # only change the TTL
  end
end

Container Engine (Alpha)

Quick Start

$ gem install google-cloud-container

Preview

require "google/cloud/container"

cluster_manager_client = Google::Cloud::Container.new
project_id_2 = project_id
zone = "us-central1-a"
response = cluster_manager_client.list_clusters(project_id_2, zone)

Cloud Dataproc (Alpha)

Quick Start

$ gem install google-cloud-dataproc

Preview

require "google/cloud/dataproc"

cluster_controller_client = Google::Cloud::Dataproc::ClusterController.new
project_id_2 = project_id
region = "global"

# Iterate over all results.
cluster_controller_client.list_clusters(project_id_2, region).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
cluster_controller_client.list_clusters(project_id_2, region).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Data Loss Prevention (Alpha)

Quick Start

$ gem install google-cloud-dlp

Preview

require "google/cloud/dlp"

dlp_service_client = Google::Cloud::Dlp.new
min_likelihood = :POSSIBLE
inspect_config = { min_likelihood: min_likelihood }
type = "text/plain"
value = "my phone number is 215-512-1212"
items_element = { type: type, value: value }
items = [items_element]
response = dlp_service_client.inspect_content(inspect_config, items)

Dialogflow API (Alpha)

Quick Start

$ gem install google-cloud-dialogflow

Stackdriver Error Reporting (Beta)

Quick Start

$ gem install google-cloud-error_reporting

Preview

require "google/cloud/error_reporting"

# Report an exception
begin
  fail "Boom!"
rescue => exception
  Google::Cloud::ErrorReporting.report exception
end

Cloud Firestore (Beta)

Quick Start

$ gem install google-cloud-firestore

Preview

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new(
  project_id: "my-project",
  credentials: "/path/to/keyfile.json"
)

city = firestore.col("cities").doc("SF")
city.set({ name: "San Francisco",
           state: "CA",
           country: "USA",
           capital: false,
           population: 860000 })

firestore.transaction do |tx|
  new_population = tx.get(city).data[:population] + 1
  tx.update(city, { population: new_population })
end

Stackdriver Logging (GA)

Quick Start

$ gem install google-cloud-logging

Preview

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

# List all log entries
logging.entries.each do |e|
  puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
end

# List only entries from a single log
entries = logging.entries filter: "log:syslog"

# Write a log entry
entry = logging.entry
entry.payload = "Job started."
entry.log_name = "my_app_log"
entry.resource.type = "gae_app"
entry.resource.labels[:module_id] = "1"
entry.resource.labels[:version_id] = "20150925t173233"

logging.write_entries entry

Cloud Natural Language API (Alpha)

Quick Start

$ gem install google-cloud-language

Preview

require "google/cloud/language"

language = Google::Cloud::Language.new(
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"
)

content = "Star Wars is a great movie. The Death Star is fearsome."
document = language.document content
annotation = document.annotate

annotation.entities.count #=> 3
annotation.sentiment.score #=> 0.10000000149011612
annotation.sentiment.magnitude #=> 1.100000023841858
annotation.sentences.count #=> 2
annotation.tokens.count #=> 13

Cloud OS Login (Alpha)

Quick Start

$ gem install google-cloud-os_login

Cloud Pub/Sub (Beta)

Quick Start

$ gem install google-cloud-pubsub

Preview

require "google/cloud/pubsub"

pubsub = Google::Cloud::Pubsub.new(
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"
)

# Retrieve a topic
topic = pubsub.topic "my-topic"

# Publish a new message
msg = topic.publish "new-message"

# Retrieve a subscription
sub = pubsub.subscription "my-topic-sub"

# Create a subscriber to listen for available messages
subscriber = sub.listen do |received_message|
  # process message
  received_message.acknowledge!
end

# Start background threads that will call the block passed to listen.
subscriber.start

# Shut down the subscriber when ready to stop receiving messages.
subscriber.stop.wait!

Cloud Redis API (Alpha)

Quick Start

$ gem install google-cloud-redis

Cloud Resource Manager (Alpha)

Quick Start

$ gem install google-cloud-resource_manager

Preview

require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new

# List all projects
resource_manager.projects.each do |project|
  puts projects.project_id
end

# Label a project as production
project = resource_manager.project "tokyo-rain-123"
project.update do |p|
  p.labels["env"] = "production"
end

# List only projects with the "production" label
projects = resource_manager.projects filter: "labels.env:production"

Stackdriver Trace (Beta)

Quick Start

$ gem install google-cloud-trace

Preview

require "google/cloud/trace"

trace = Google::Cloud::Trace.new

result_set = trace.list_traces Time.now - 3600, Time.now
result_set.each do |trace_record|
  puts "Retrieved trace ID: #{trace_record.trace_id}"
end

Cloud Spanner API (GA)

Quick Start

$ gem install google-cloud-spanner

Preview

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

db = spanner.client "my-instance", "my-database"

db.transaction do |tx|
  results = tx.execute "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end

Cloud Speech API (Alpha)

Quick Start

$ gem install google-cloud-speech

Preview

require "google/cloud/speech"

speech = Google::Cloud::Speech.new

audio = speech.audio "path/to/audio.raw",
                     encoding: :raw, sample_rate: 16000
results = audio.recognize

result = results.first
result.transcript #=> "how old is the Brooklyn Bridge"
result.confidence #=> 0.9826789498329163

Cloud Storage (GA)

Quick Start

$ gem install google-cloud-storage

Preview

require "google/cloud/storage"

storage = Google::Cloud::Storage.new(
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"
)

bucket = storage.bucket "task-attachments"

file = bucket.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.bucket "task-attachment-backups"
file.copy backup, file.name

Cloud Tasks API (Alpha)

Quick Start

$ gem install google-cloud-tasks

Preview

 require "google/cloud/tasks/v2beta2"

 cloud_tasks_client = Google::Cloud::Tasks::V2beta2.new
 formatted_parent = Google::Cloud::Tasks::V2beta2::CloudTasksClient.location_path("[PROJECT]", "[LOCATION]")

 # Iterate over all results.
 cloud_tasks_client.list_queues(formatted_parent).each do |element|
   # Process element.
 end

 # Or iterate over results one page at a time.
 cloud_tasks_client.list_queues(formatted_parent).each_page do |page|
   # Process each page at a time.
   page.each do |element|
     # Process element.
   end
 end

Cloud Text To Speech API (Alpha)

Quick Start

$ gem install google-cloud-text_to_speech

Preview

require "google/cloud/text_to_speech/v1"

text_to_speech_client = Google::Cloud::TextToSpeech::V1.new

input = {text: "Hello, world!"}
voice = {language_code: "en-US"}
audio_config = {audio_encoding: Google::Cloud::Texttospeech::V1::AudioEncoding::MP3}
response = text_to_speech_client.synthesize_speech input, voice, audio_config
File.open "hello.mp3", "w" do |file|
  file.write response.audio_content
end

Cloud Translation API (GA)

Quick Start

$ gem install google-cloud-translate

Preview

require "google/cloud/translate"

translate = Google::Cloud::Translate.new

translation = translate.translate "Hello world!", to: "la"

puts translation #=> Salve mundi!

translation.from #=> "en"
translation.origin #=> "Hello world!"
translation.to #=> "la"
translation.text #=> "Salve mundi!"

Cloud Vision API (Alpha)

Quick Start

$ gem install google-cloud-vision

Preview

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

image = vision.image "path/to/landmark.jpg"

landmark = image.landmark
landmark.description #=> "Mount Rushmore"

Stackdriver Monitoring API (Beta)

Quick Start

$ gem install google-cloud-monitoring

Preview

 require "google/cloud/monitoring/v3"

 MetricServiceClient = Google::Cloud::Monitoring::V3::MetricServiceClient

 metric_service_client = MetricServiceClient.new
 formatted_name = MetricServiceClient.project_path(project_id)

 # Iterate over all results.
 metric_service_client.list_monitored_resource_descriptors(formatted_name).each do |element|
   # Process element.
 end

 # Or iterate over results one page at a time.
 metric_service_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
   # Process each page at a time.
   page.each do |element|
     # Process element.
   end
 end

Cloud Video Intelligence API (GA)

Quick Start

$ gem install google-cloud-video_intelligence

Preview

 require "google/cloud/video_intelligence/v1beta2"

 video_intelligence_service_client = Google::Cloud::VideoIntelligence.new
 input_uri = "gs://cloud-ml-sandbox/video/chicago.mp4"
 features_element = :LABEL_DETECTION
 features = [features_element]

 # Register a callback during the method call.
 operation = video_intelligence_service_client.annotate_video(input_uri: input_uri, features: features) do |op|
   raise op.results.message if op.error?
   op_results = op.results
   # Process the results.

   metadata = op.metadata
   # Process the metadata.
 end

 # Or use the return value to register a callback.
 operation.on_done do |op|
   raise op.results.message if op.error?
   op_results = op.results
   # Process the results.

   metadata = op.metadata
   # Process the metadata.
 end

 # Manually reload the operation.
 operation.reload!

 # Or block until the operation completes, triggering callbacks on
 # completion.
 operation.wait_until_done!

Supported Ruby Versions

These libraries are currently supported on Ruby 2.3+.

Google provides official support for Ruby versions that are actively supported by Ruby Core—that is, Ruby versions that are either in normal maintenance or in security maintenance, and not end of life. Currently, this means Ruby 2.3 and later. Older versions of Ruby may still work, but are unsupported and not recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby support schedule.

Versioning

This library follows Semantic Versioning.

Please note it is currently under active development. Any release versioned 0.x.y is subject to backwards incompatible changes at any time.

GA: Libraries defined at the GA (general availability) quality level are stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.

Please note that the auto-generated portions of the GA libraries (the ones in modules such as v1 or v2) are considered to be of Beta quality, even if the libraries that wrap them are GA.

Beta: Libraries defined at a Beta quality level are expected to be mostly stable and we're working towards their release candidate. We will address issues and requests with a higher priority.

Alpha: Libraries defined at an Alpha quality level are still a work-in-progress and are more likely to get backwards-incompatible updates.

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.

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.