Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Created April 23, 2017 21:02
Show Gist options
  • Save beccasaurus/4d5c58e652e364d7883626bf63828e6d to your computer and use it in GitHub Desktop.
Save beccasaurus/4d5c58e652e364d7883626bf63828e6d to your computer and use it in GitHub Desktop.
6 LOC :: Google Cloud Client Library Samples
require "google/cloud/datastore"
datastore = Google::Cloud::Datastore.new
query = datastore.query("Dog").limit(5)
datastore.run(query).each do |dog|
puts dog["name"]
end
require "google/cloud/dns"
dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.records.each do |record|
puts record.name
end
require "google/cloud/language"
speech = Google::Cloud::Language.new
document = language.document "The dog barked."
document.annotate.sentences.each do |sentence|
puts sentence.sentiment.score
end
require "google/cloud/pubsub"
pubsub = Google::Cloud::Language.new
subscription = pubsub.subscription "notifications"
subscription.pull.each do |message|
puts message.data
end
require "google/cloud/speech"
speech = Google::Cloud::Speech.new
audio = speech.audio "audio.wav"
audio.recognize.each do |result|
puts result.transcript
end
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "dogs-images"
bucket.files.each do |file|
puts file.name
end
require "google/cloud/vision"
vision = Google::Cloud::Vision.new
image = vision.image "dog.png"
image.labels.each do |label|
puts label.description
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment