rémi's most favoritest idiomatic bits from Google Cloud Client Libraries
task = datastore.entity "Task" do |t|
t["type"] = "Personal"
t["done"] = false
t["priority"] = 4
t["description"] = "Learn Cloud Datastore"
end
datastore.query("Task").where("done", "=", false).order("created").limit(5)
bucket.new_file "cat.png"
bucket.create_file "cat.png"
bucket.upload_file "cat.png"
(pending release... merged into master...)
bucket.create_file StringIO.new("Haha! I'm not a file!")
text = StringIO.new
bucket.file("README").download text
job = bigquery.query_job "SELECT COUNT(word) as count FROM " \
"publicdata.samples.shakespeare"
job.wait_until_done!
if job.failed?
puts job.error
else
puts job.query_results.first
end
subscription = pubsub.subscription "cool-things"
subscription.listen do |message|
puts "Hey! So there I was, just sitting here blocking..."
puts "When I heard this cool thing! #{message.data}"
end
Don't know Ruby? That's okay. I dare you not to easily comprehend this...
require "google/cloud/dns"
dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
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
logger = logging.logger "my_app_log", resource, env: :production
logger.info "Job started"
logger.info { "Job started" }
logger.debug?
Huh. That looks familiar for some reason...
dataset.create_table "people" do |schema|
schema.string "name"
schema.integer "age"
end
And rémi's top most favoritest Google Cloud Client Library idiom is ...
🥁 🥁 🥁 🥁 🥁 🥁 🥁 🥁 🥁
gem "stackdriver"
Railtie that just works
Using Sinatra or Rack? That's okay!
Just use the middleware!
use Google::Cloud::Logging::Middleware
use Google::Cloud::ErrorReporting::Middleware