google-api-client 0.9.pre4 → 0.9.pre5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/README.md +11 -1
- data/api_names.yaml +1 -0
- data/api_names_out.yaml +163 -98
- data/generated/google/apis/admin_datatransfer_v1.rb +1 -1
- data/generated/google/apis/analytics_v3.rb +1 -1
- data/generated/google/apis/analytics_v3/classes.rb +7 -0
- data/generated/google/apis/analytics_v3/representations.rb +1 -0
- data/generated/google/apis/analytics_v3/service.rb +42 -0
- data/generated/google/apis/appstate_v1.rb +1 -1
- data/generated/google/apis/bigquery_v2.rb +1 -1
- data/generated/google/apis/bigquery_v2/classes.rb +23 -66
- data/generated/google/apis/bigquery_v2/representations.rb +1 -17
- data/generated/google/apis/bigquery_v2/service.rb +6 -6
- data/generated/google/apis/cloudbilling_v1.rb +1 -1
- data/generated/google/apis/cloudmonitoring_v2beta2.rb +1 -1
- data/generated/google/apis/deploymentmanager_v2.rb +1 -1
- data/generated/google/apis/deploymentmanager_v2/classes.rb +5 -4
- data/generated/google/apis/doubleclicksearch_v2.rb +1 -1
- data/generated/google/apis/drive_v2.rb +1 -1
- data/generated/google/apis/drive_v2/service.rb +4 -3
- data/generated/google/apis/drive_v3.rb +1 -1
- data/generated/google/apis/games_configuration_v1configuration.rb +1 -1
- data/generated/google/apis/games_management_v1management.rb +1 -1
- data/generated/google/apis/games_v1.rb +1 -1
- data/generated/google/apis/genomics_v1.rb +1 -1
- data/generated/google/apis/gmail_v1.rb +1 -1
- data/generated/google/apis/gmail_v1/classes.rb +2 -2
- data/generated/google/apis/plus_domains_v1.rb +1 -1
- data/generated/google/apis/plus_v1.rb +1 -1
- data/generated/google/apis/plus_v1/classes.rb +0 -497
- data/generated/google/apis/plus_v1/representations.rb +0 -121
- data/generated/google/apis/plus_v1/service.rb +0 -101
- data/generated/google/apis/replicapoolupdater_v1beta1.rb +1 -1
- data/generated/google/apis/replicapoolupdater_v1beta1/classes.rb +4 -4
- data/generated/google/apis/webmasters_v3.rb +3 -3
- data/generated/google/apis/webmasters_v3/service.rb +2 -2
- data/generated/google/apis/youtube_v3.rb +1 -1
- data/generated/google/apis/youtube_v3/classes.rb +942 -64
- data/generated/google/apis/youtube_v3/representations.rb +307 -0
- data/generated/google/apis/youtube_v3/service.rb +443 -1
- data/google-api-client.gemspec +1 -0
- data/lib/google/apis/core/api_command.rb +2 -2
- data/lib/google/apis/core/base_service.rb +2 -0
- data/lib/google/apis/core/http_client_adapter.rb +82 -0
- data/lib/google/apis/core/http_command.rb +16 -1
- data/lib/google/apis/core/json_representation.rb +3 -2
- data/lib/google/apis/core/upload.rb +7 -1
- data/lib/google/apis/options.rb +4 -2
- data/lib/google/apis/version.rb +1 -1
- data/samples/Gemfile +7 -0
- data/samples/README.md +51 -0
- data/samples/google-api-samples +32 -0
- data/samples/lib/base_cli.rb +94 -0
- data/samples/lib/samples/analytics.rb +62 -0
- data/samples/lib/samples/calendar.rb +83 -0
- data/samples/lib/samples/drive.rb +82 -0
- data/samples/lib/samples/gmail.rb +50 -0
- data/samples/lib/samples/pubsub.rb +114 -0
- data/samples/lib/samples/translate.rb +44 -0
- data/samples/lib/samples/you_tube.rb +44 -0
- data/spec/google/apis/core/api_command_spec.rb +39 -0
- data/spec/google/apis/core/http_command_spec.rb +9 -0
- data/spec/google/apis/core/upload_spec.rb +14 -0
- data/spec/google/apis/options_spec.rb +0 -8
- data/spec/integration_tests/adsense_spec.rb +1 -0
- data/spec/integration_tests/pubsub_spec.rb +3 -3
- data/spec/integration_tests/url_shortener_spec.rb +14 -0
- data/spec/spec_helper.rb +33 -6
- data/{samples/translate/translate.rb → spec/spec_helper/load_path_spec.rb} +15 -6
- metadata +30 -6
- data/samples/calendar/calendar.rb +0 -43
- data/samples/drive/drive.rb +0 -47
- data/samples/pubsub/pubsub.rb +0 -51
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright 2016 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'google/apis/calendar_v3'
|
16
|
+
require 'base_cli'
|
17
|
+
|
18
|
+
|
19
|
+
module Samples
|
20
|
+
# Examples for the Google Calendar API
|
21
|
+
#
|
22
|
+
# Sample usage:
|
23
|
+
#
|
24
|
+
# $ ./google-api-samples calendar list --limit 10
|
25
|
+
class Calendar < BaseCli
|
26
|
+
Calendar = Google::Apis::CalendarV3
|
27
|
+
|
28
|
+
desc 'schedule', 'Create an event'
|
29
|
+
method_option :summary, type: :string, required: true
|
30
|
+
method_option :start, type: :string, required: true
|
31
|
+
method_option :end , type: :string, required: true
|
32
|
+
method_option :attendees, type: :array
|
33
|
+
def schedule
|
34
|
+
calendar = Calendar::CalendarService.new
|
35
|
+
calendar.authorization = user_credentials_for(Calendar::AUTH_CALENDAR)
|
36
|
+
|
37
|
+
event = {
|
38
|
+
summary: options[:summary],
|
39
|
+
attendees: Array(options[:attenddes]).map { |email| { email: email } },
|
40
|
+
start: {
|
41
|
+
date_time: DateTime.parse(options[:start])
|
42
|
+
},
|
43
|
+
end: {
|
44
|
+
date_time: DateTime.parse(options[:end])
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
event = calendar.insert_event('primary', event, send_notifications: true)
|
49
|
+
say "Created event '#{event.summary}' (#{event.id})"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'list', 'List upcoming events'
|
53
|
+
method_option :limit, type: :numeric
|
54
|
+
def list()
|
55
|
+
calendar = Calendar::CalendarService.new
|
56
|
+
calendar.authorization = user_credentials_for(Calendar::AUTH_CALENDAR)
|
57
|
+
|
58
|
+
page_token = nil
|
59
|
+
limit = options[:limit] || 1000
|
60
|
+
now = Time.now.iso8601
|
61
|
+
begin
|
62
|
+
result = calendar.list_events('primary',
|
63
|
+
max_results: [limit, 100].min,
|
64
|
+
single_events: true,
|
65
|
+
order_by: 'startTime',
|
66
|
+
time_min: now,
|
67
|
+
page_token: page_token,
|
68
|
+
fields: 'items(id,summary,start),next_page_token')
|
69
|
+
|
70
|
+
result.items.each do |event|
|
71
|
+
time = event.start.date_time || event.start.date
|
72
|
+
say "#{time}, #{event.summary}"
|
73
|
+
end
|
74
|
+
limit -= result.items.length
|
75
|
+
if result.next_page_token
|
76
|
+
page_token = result.next_page_token
|
77
|
+
else
|
78
|
+
page_token = nil
|
79
|
+
end
|
80
|
+
end while !page_token.nil? && limit > 0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright 2016 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'google/apis/drive_v3'
|
16
|
+
require 'base_cli'
|
17
|
+
|
18
|
+
|
19
|
+
module Samples
|
20
|
+
# Examples for the Google Drive API
|
21
|
+
#
|
22
|
+
# Sample usage:
|
23
|
+
#
|
24
|
+
# $ ./google-api-samples drive upload ~/myvideo.mov
|
25
|
+
class Drive < BaseCli
|
26
|
+
Drive = Google::Apis::DriveV3
|
27
|
+
|
28
|
+
desc 'upload FILE', 'Upload a file to Google Drive'
|
29
|
+
method_option :name, type: :string
|
30
|
+
def upload(file)
|
31
|
+
drive = Drive::DriveService.new
|
32
|
+
drive.authorization = user_credentials_for(Drive::AUTH_DRIVE)
|
33
|
+
|
34
|
+
metadata = {
|
35
|
+
name: options[:name] || file
|
36
|
+
}
|
37
|
+
result = drive.create_file(metadata, upload_source: file)
|
38
|
+
say "Upload complete"
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'download FILE_ID', 'Download a file from Google Drive'
|
42
|
+
method_option :out, type: :string
|
43
|
+
def download(file_id)
|
44
|
+
drive = Drive::DriveService.new
|
45
|
+
drive.authorization = user_credentials_for(Drive::AUTH_DRIVE)
|
46
|
+
|
47
|
+
dest = options[:out] || StringIO.new
|
48
|
+
drive.get_file(file_id, download_dest: dest)
|
49
|
+
|
50
|
+
if dest.is_a?(StringIO)
|
51
|
+
dest.rewind
|
52
|
+
STDOUT.write(dest.read)
|
53
|
+
else
|
54
|
+
say "File downloaded to #{options[:out]}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'list QUERY', 'Search for files'
|
59
|
+
method_option :limit, type: :numeric
|
60
|
+
def list(query)
|
61
|
+
drive = Drive::DriveService.new
|
62
|
+
drive.authorization = user_credentials_for(Drive::AUTH_DRIVE)
|
63
|
+
|
64
|
+
page_token = nil
|
65
|
+
limit = options[:limit] || 1000
|
66
|
+
begin
|
67
|
+
result = drive.list_files(q: query,
|
68
|
+
page_size: [limit, 100].min,
|
69
|
+
page_token: page_token,
|
70
|
+
fields: 'files(id,name),next_page_token')
|
71
|
+
|
72
|
+
result.files.each { |file| puts "#{file.id}, #{file.name}" }
|
73
|
+
limit -= result.files.length
|
74
|
+
if result.next_page_token
|
75
|
+
page_token = result.next_page_token
|
76
|
+
else
|
77
|
+
page_token = nil
|
78
|
+
end
|
79
|
+
end while !page_token.nil? && limit > 0
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright 2016 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'google/apis/gmail_v1'
|
16
|
+
require 'base_cli'
|
17
|
+
require 'rmail'
|
18
|
+
|
19
|
+
module Samples
|
20
|
+
# Examples for the Gmail API
|
21
|
+
#
|
22
|
+
# Sample usage:
|
23
|
+
#
|
24
|
+
# $ ./google-api-samples gmail send 'Hello there!' \
|
25
|
+
# --to='recipient@example.com' --from='user@example.com' \
|
26
|
+
# --subject='Hello'
|
27
|
+
#
|
28
|
+
class Gmail < BaseCli
|
29
|
+
Gmail = Google::Apis::GmailV1
|
30
|
+
|
31
|
+
desc 'send TEXT', 'Send a message with the gmail API'
|
32
|
+
method_option :to, type: :string, required: true
|
33
|
+
method_option :from, type: :string, required: true
|
34
|
+
method_option :subject, type: :string, required: true
|
35
|
+
def send(body)
|
36
|
+
gmail = Gmail::GmailService.new
|
37
|
+
gmail.authorization = user_credentials_for(Gmail::AUTH_SCOPE)
|
38
|
+
|
39
|
+
message = RMail::Message.new
|
40
|
+
message.header['To'] = options[:to]
|
41
|
+
message.header['From'] = options[:from]
|
42
|
+
message.header['Subject'] = options[:subject]
|
43
|
+
message.body = body
|
44
|
+
|
45
|
+
gmail.send_user_message('me',
|
46
|
+
upload_source: StringIO.new(message.to_s),
|
47
|
+
content_type: 'message/rfc822')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# Copyright 2016 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'google/apis/pubsub_v1'
|
16
|
+
require 'base_cli'
|
17
|
+
|
18
|
+
|
19
|
+
module Samples
|
20
|
+
# Examples for the Google Cloud Pub/Sub API.
|
21
|
+
#
|
22
|
+
# Sample usage session:
|
23
|
+
#
|
24
|
+
# $ ./google-api-samples pubsub create_topic mytopic --project=623040240964
|
25
|
+
# # ./google-api-samples pubsub subscribe mysub --topic=mytopic --project=623040240964
|
26
|
+
# $ ./google-api-samples pubsub publish 'Hello!' --topic=mytopic --project=623040240964
|
27
|
+
# $ ./google-api-samples pubsub pull mysub --project=623040240964
|
28
|
+
# Received: Hello!
|
29
|
+
# $ ./google-api-samples pubsub unsubscribe mysub --project=623040240964
|
30
|
+
# $ ./google-api-samples pubsub delete_topic mytopic --project=623040240964
|
31
|
+
#
|
32
|
+
class PubSub < BaseCli
|
33
|
+
Pubsub = Google::Apis::PubsubV1
|
34
|
+
|
35
|
+
desc 'create_topic TOPIC_NAME', 'Create a topic'
|
36
|
+
method_option :project, type: :string, required: true
|
37
|
+
def create_topic(name)
|
38
|
+
pubsub = Pubsub::PubsubService.new
|
39
|
+
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
40
|
+
topic = "projects/#{options[:project]}/topics/#{name}"
|
41
|
+
|
42
|
+
pubsub.create_topic(topic)
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'delete_topic TOPIC_NAME', 'Delete a topic'
|
46
|
+
method_option :project, type: :string, required: true
|
47
|
+
def delete_topic(name)
|
48
|
+
pubsub = Pubsub::PubsubService.new
|
49
|
+
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
50
|
+
|
51
|
+
topic = "projects/#{options[:project]}/topics/#{name}"
|
52
|
+
|
53
|
+
pubsub.delete_topic(topic)
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'subscribe SUBSCRIPTION_NAME', 'Subscribe to a topic'
|
57
|
+
method_option :project, type: :string, required: true
|
58
|
+
method_option :topic, type: :string, required: true
|
59
|
+
def subscribe(name)
|
60
|
+
pubsub = Pubsub::PubsubService.new
|
61
|
+
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
62
|
+
|
63
|
+
topic = "projects/#{options[:project]}/topics/#{options[:topic]}"
|
64
|
+
subscription = "projects/#{options[:project]}/subscriptions/#{name}"
|
65
|
+
pubsub.create_subscription(subscription, Pubsub::Subscription.new(topic: topic))
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'unsubscribe subscription_name', 'Ububscribe from a topic'
|
69
|
+
method_option :project, type: :string, required: true
|
70
|
+
def unsubscribe(name)
|
71
|
+
pubsub = Pubsub::PubsubService.new
|
72
|
+
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
73
|
+
|
74
|
+
subscription = "projects/#{options[:project]}/subscriptions/#{name}"
|
75
|
+
pubsub.delete_subscription(subscription)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
desc 'publish MESSAGE', 'Publish a message to a topic'
|
80
|
+
method_option :project, type: :string, required: true
|
81
|
+
method_option :topic, type: :string, required: true
|
82
|
+
def publish(message)
|
83
|
+
pubsub = Pubsub::PubsubService.new
|
84
|
+
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
85
|
+
topic = "projects/#{options[:project]}/topics/#{options[:topic]}"
|
86
|
+
|
87
|
+
request = Pubsub::PublishRequest.new(messages: [])
|
88
|
+
request.messages << Pubsub::Message.new(data: message)
|
89
|
+
|
90
|
+
pubsub.publish_topic(topic, request)
|
91
|
+
end
|
92
|
+
|
93
|
+
desc 'pull SUBSCRIPTION_NAME', 'Pull message(s) from the topic'
|
94
|
+
method_option :project, type: :string, required: true
|
95
|
+
method_option :max, type: :numeric, default: 5
|
96
|
+
def pull(name)
|
97
|
+
pubsub = Pubsub::PubsubService.new
|
98
|
+
pubsub.authorization = Google::Auth.get_application_default([Pubsub::AUTH_PUBSUB])
|
99
|
+
|
100
|
+
subscription = "projects/#{options[:project]}/subscriptions/#{name}"
|
101
|
+
|
102
|
+
# Pull messages
|
103
|
+
response = pubsub.pull_subscription(subscription, Pubsub::PullRequest.new(max_messages: options[:max]))
|
104
|
+
response.received_messages.each do |received_message|
|
105
|
+
data = received_message.message.data
|
106
|
+
puts "Received: #{data}"
|
107
|
+
end
|
108
|
+
|
109
|
+
# Acknowledge receipt
|
110
|
+
ack_ids = response.received_messages.map{ |msg| msg.ack_id }
|
111
|
+
pubsub.acknowledge_subscription(subscription, Pubsub::AcknowledgeRequest.new(ack_ids: ack_ids))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright 2016 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'google/apis/translate_v2'
|
16
|
+
require 'base_cli'
|
17
|
+
|
18
|
+
|
19
|
+
module Samples
|
20
|
+
# Examples for the Google Translate API
|
21
|
+
#
|
22
|
+
# Sample usage:
|
23
|
+
#
|
24
|
+
# $ ./google-api-samples translate 'Hola!' --target='en'
|
25
|
+
# Hello
|
26
|
+
#
|
27
|
+
class Translate < BaseCli
|
28
|
+
Translate = Google::Apis::TranslateV2
|
29
|
+
|
30
|
+
desc 'translate PHRASE', 'Translate a phrase'
|
31
|
+
method_option :source, type: :string
|
32
|
+
method_option :target, type: :string, required: true
|
33
|
+
def translate(phrase)
|
34
|
+
translate = Translate::TranslateService.new
|
35
|
+
translate.key = api_key
|
36
|
+
|
37
|
+
result = translate.list_translations(phrase, options[:target], source: options[:source])
|
38
|
+
puts result.translations.first.translated_text
|
39
|
+
end
|
40
|
+
|
41
|
+
default_task :translate
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright 2016 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'google/apis/youtube_v3'
|
16
|
+
require 'base_cli'
|
17
|
+
|
18
|
+
|
19
|
+
module Samples
|
20
|
+
# Examples for the YouTube APIs
|
21
|
+
#
|
22
|
+
# Sample usage:
|
23
|
+
#
|
24
|
+
# $ ./google-api-samples youtube upload ~/myvideo.mov --title="So funny!"
|
25
|
+
#
|
26
|
+
class YouTube < BaseCli
|
27
|
+
YT = Google::Apis::YoutubeV3
|
28
|
+
|
29
|
+
desc 'upload FILE', 'Upload a video to YouTube'
|
30
|
+
method_option :title, type: :string
|
31
|
+
def upload(file)
|
32
|
+
youtube = YT::YouTubeService.new
|
33
|
+
youtube.authorization = user_credentials_for(YT::AUTH_YOUTUBE)
|
34
|
+
|
35
|
+
metadata = {
|
36
|
+
snippet: {
|
37
|
+
title: options[:title] || file
|
38
|
+
}
|
39
|
+
}
|
40
|
+
result = youtube.insert_video('snippet', metadata, upload_source: file)
|
41
|
+
say "Upload complete"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -151,6 +151,41 @@ EOF
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
+
context('with a client error response') do
|
155
|
+
let(:command) do
|
156
|
+
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
157
|
+
end
|
158
|
+
|
159
|
+
before(:example) do
|
160
|
+
json = <<EOF
|
161
|
+
{
|
162
|
+
"error": {
|
163
|
+
"errors": [
|
164
|
+
{
|
165
|
+
"domain": "global",
|
166
|
+
"reason": "timeRangeEmpty",
|
167
|
+
"message": "The specified time range is empty."
|
168
|
+
}
|
169
|
+
],
|
170
|
+
"code": 400,
|
171
|
+
"message": "The specified time range is empty."
|
172
|
+
}
|
173
|
+
}
|
174
|
+
EOF
|
175
|
+
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
176
|
+
.to_return(status: [400, 'Bad Request'], headers: { 'Content-Type' => 'application/json' }, body: json)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should raise client error' do
|
180
|
+
expect { command.execute(client) }.to raise_error(Google::Apis::ClientError)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should raise an error with the reason and message' do
|
184
|
+
expect { command.execute(client) }.to raise_error(
|
185
|
+
/timeRangeEmpty: The specified time range is empty/)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
154
189
|
context('with an empty error body') do
|
155
190
|
let(:command) do
|
156
191
|
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
@@ -166,5 +201,9 @@ EOF
|
|
166
201
|
it 'should raise client error' do
|
167
202
|
expect { command.execute(client) }.to raise_error(Google::Apis::ClientError)
|
168
203
|
end
|
204
|
+
|
205
|
+
it 'should use the default error message' do
|
206
|
+
expect { command.execute(client) }.to raise_error(/Invalid request/)
|
207
|
+
end
|
169
208
|
end
|
170
209
|
end
|