Import refactored library. See MIGRATING.MD for details

This commit is contained in:
Steven Bazyl committed 2015-06-23 15:15:14 -07:00
1 parent 9b7809174d
commit f584a2cec8
373 files changed
+255715 -474

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'googleauth'
require 'google/apis/calendar_v3'
Calendar = Google::Apis::CalendarV3
calendar = Calendar::CalendarService.new
calendar.authorization = Google::Auth.get_application_default([Calendar::AUTH_CALENDAR])
# Create an event, adding any emails listed in the command line as attendees
event = Calendar::Event.new(summary: 'A sample event',
location: '1600 Amphitheatre Parkway, Mountain View, CA 94045',
attendees: ARGV.map { |email| Calendar::EventAttendee.new(email: email) },
start: Calendar::EventDateTime.new(date_time: DateTime.parse('2015-12-31T20:00:00')),
end: Calendar::EventDateTime.new(date_time: DateTime.parse('2016-01-01T02:00:00')))
event = calendar.insert_event('primary', event, send_notifications: true)
puts "Created event '#{event.summary}' (#{event.id})"
# List upcoming events
events = calendar.list_events('primary', max_results: 10, single_events: true,
order_by: 'startTime', time_min: Time.now.iso8601)
puts "Upcoming events:"
events.items.each do |evt|
start = event.start.date || event.start.date_time
puts "- #{event.summary} (#{start}) (ID: #{event.id})"
end
# Delete the event we created earlier
calendar.delete_event('primary', event.id, send_notifications: true)
puts "Event deleted"
+40
View File
@@ -0,0 +1,40 @@
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'tempfile'
require 'googleauth'
require 'google/apis/drive_v2'
Drive = Google::Apis::DriveV2
drive = Drive::DriveService.new
drive.authorization = Google::Auth.get_application_default([Drive::AUTH_DRIVE])
# Insert a file
file = drive.insert_file({title: 'drive.rb'}, upload_source: 'drive.rb')
puts "Created file #{file.title} (#{file.id})"
# Search for it
files = drive.list_files(q: "title = 'drive.rb'")
puts "Search results:"
files.items.each do |file|
puts "- File: #{file.title} (#{file.id})"
end
# Read it back
tmp = drive.get_file(file.id, download_dest: Tempfile.new('drive'))
# Delete it
drive.delete_file(file.id)
puts "File deleted"
+52
View File
@@ -0,0 +1,52 @@
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'googleauth'
require 'google/apis/pubsub_v1beta2'
Pubsub = Google::Apis::PubsubV1beta2
pubsub = Pubsub::PubsubService.new
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
project = ARGV[0] || 'YOUR_PROJECT_NAME'
topic = "projects/#{project}/topics/foo"
subscription = "projects/#{project}/subscriptions/bar"
# Create topic & subscription
pubsub.create_topic(topic)
pubsub.create_subscription(subscription, Pubsub::Subscription.new(topic: topic))
# Publish messages
request = Pubsub::PublishRequest.new(messages: [])
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'Hello')
request.messages << Pubsub::Message.new(attributes: { "language" => "en" }, data: 'World')
pubsub.publish(topic, request)
# Pull messages
response = pubsub.pull(subscription, Pubsub::PullRequest.new(max_messages: 5))
response.received_messages.each do |received_message|
data = received_message.message.data
puts "Received #{data}"
end
# Acknowledge receipt
ack_ids = response.received_messages.map{ |msg| msg.ack_id }
pubsub.acknowledge(subscription, Pubsub::AcknowledgeRequest.new(ack_ids: ack_ids))
# Delete the subscription & topic
pubsub.delete_subscription(subscription)
pubsub.delete_topic(topic)
+28
View File
@@ -0,0 +1,28 @@
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'tempfile'
require 'googleauth'
require 'google/apis/translate_v2'
Google::Apis.logger.level = Logger::DEBUG
Translate = Google::Apis::TranslateV2
translate = Translate::TranslateService.new
translate.key = ARGV[0] || 'YOUR_API_KEY'
result = translate.list_translations(source: 'en', target: 'es', q: 'Hello world!')
puts result.translations.first.translated_text