yt 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/HISTORY.md +1 -0
- data/README.md +1 -1
- data/lib/yt/models/status.rb +6 -1
- data/lib/yt/models/timestamp.rb +12 -0
- data/lib/yt/models/video.rb +7 -8
- data/lib/yt/version.rb +1 -1
- data/spec/requests/as_account/video_spec.rb +129 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a618a834dfa7b3cecfc38f24ea9d7c7f42db9ca3
|
4
|
+
data.tar.gz: 8136067b0f3568ac059e4eacfe0eb812c3c9c4e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adb13cd19177496972a8f43bf663716ce250ca8e0d53d8aa570efe82ae4b5b97371d9697bb3f90bdec1a1aa6d082f13a79096c9af777a70fe6f27e2a577819f9
|
7
|
+
data.tar.gz: 212188da7ddfd9dd7c17b62c6568ff51e1fcdc55cc63da4b13552bae96140338723a2fce7b82f025273bd3e538405fbb4da81fcf1d678f621feb4fc58da573e3
|
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
@@ -7,6 +7,7 @@ v0.9 - 2014/07/28
|
|
7
7
|
* Let 'update' methods understand both under_score and camelCased parameters
|
8
8
|
* Add claim.third_party?
|
9
9
|
* Add actual_start_time, actual_end_time, scheduled_start_time, scheduled_end_time for live-streaming videos
|
10
|
+
* Add privacy_status, public_stats_viewable, publish_at to the options that Video#update accepts
|
10
11
|
|
11
12
|
v0.8 - 2014/07/18
|
12
13
|
-----------------
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ To install on your system, run
|
|
41
41
|
|
42
42
|
To use inside a bundled Ruby project, add this line to the Gemfile:
|
43
43
|
|
44
|
-
gem 'yt', '~> 0.9.
|
44
|
+
gem 'yt', '~> 0.9.5'
|
45
45
|
|
46
46
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
47
47
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
data/lib/yt/models/status.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yt/models/timestamp'
|
2
|
+
|
1
3
|
module Yt
|
2
4
|
module Models
|
3
5
|
# Contains information about the status of a resource. The details of the
|
@@ -247,8 +249,9 @@ module Yt
|
|
247
249
|
# @return [nil] if the resource is not a private video scheduled to be
|
248
250
|
# published.
|
249
251
|
def scheduled_at
|
250
|
-
@scheduled_at ||=
|
252
|
+
@scheduled_at ||= Yt::Timestamp.parse @data['publishAt'] if scheduled?
|
251
253
|
end
|
254
|
+
alias publish_at scheduled_at
|
252
255
|
|
253
256
|
# Returns whether the video is scheduled to be published.
|
254
257
|
# @return [Boolean] if the resource is a video, whether it is currently
|
@@ -295,6 +298,7 @@ module Yt
|
|
295
298
|
def embeddable?
|
296
299
|
@embeddable ||= @data['embeddable']
|
297
300
|
end
|
301
|
+
alias embeddable embeddable?
|
298
302
|
|
299
303
|
# Public stats (Video only)
|
300
304
|
|
@@ -308,6 +312,7 @@ module Yt
|
|
308
312
|
def has_public_stats_viewable?
|
309
313
|
@public_stats_viewable ||= @data['publicStatsViewable']
|
310
314
|
end
|
315
|
+
alias public_stats_viewable has_public_stats_viewable?
|
311
316
|
|
312
317
|
private
|
313
318
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Yt
|
2
|
+
module Models
|
3
|
+
# Extend Time to have .to_json return the format needed to submit
|
4
|
+
# timestamp to YouTube API.
|
5
|
+
# Only needed while we support ActiveSupport 3.
|
6
|
+
class Timestamp < Time
|
7
|
+
def as_json(options = nil)
|
8
|
+
utc.iso8601(3)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/yt/models/video.rb
CHANGED
@@ -11,11 +11,11 @@ module Yt
|
|
11
11
|
delegate :deleted?, :failed?, :processed?, :rejected?, :uploaded?,
|
12
12
|
:uses_unsupported_codec?, :has_failed_conversion?, :empty?, :invalid?,
|
13
13
|
:too_small?, :aborted?, :claimed?, :infringes_copyright?, :duplicate?,
|
14
|
-
:scheduled_at, :scheduled?, :too_long?, :violates_terms_of_use?,
|
14
|
+
:scheduled_at, :publish_at, :scheduled?, :too_long?, :violates_terms_of_use?,
|
15
15
|
:inappropriate?, :infringes_trademark?, :belongs_to_closed_account?,
|
16
16
|
:belongs_to_suspended_account?, :licensed_as_creative_commons?,
|
17
17
|
:licensed_as_standard_youtube?, :has_public_stats_viewable?,
|
18
|
-
:embeddable?, to: :status
|
18
|
+
:public_stats_viewable, :embeddable, :embeddable?, :license, to: :status
|
19
19
|
|
20
20
|
# @!attribute [r] content_detail
|
21
21
|
# @return [Yt::Models::ContentDetail] the video’s content details.
|
@@ -83,14 +83,11 @@ module Yt
|
|
83
83
|
!@id.nil?
|
84
84
|
end
|
85
85
|
|
86
|
-
# @todo Update the status, not just the snippet. This requires some
|
87
|
-
# caution, as the whole status object needs to be updated, not just
|
88
|
-
# privacyStatus, but also embeddable, license, publicStatsViewable,
|
89
|
-
# and publishAt
|
90
86
|
def update(attributes = {})
|
91
87
|
super attributes do |data|
|
92
88
|
@id = data['id']
|
93
89
|
@snippet = Snippet.new data: data['snippet'] if data['snippet']
|
90
|
+
@status = Status.new data: data['status'] if data['status']
|
94
91
|
true
|
95
92
|
end
|
96
93
|
end
|
@@ -161,10 +158,12 @@ module Yt
|
|
161
158
|
private
|
162
159
|
|
163
160
|
# @see https://developers.google.com/youtube/v3/docs/videos/update
|
164
|
-
# @todo: Add
|
161
|
+
# @todo: Add recording details keys
|
165
162
|
def update_parts
|
166
163
|
snippet_keys = [:title, :description, :tags, :category_id]
|
167
|
-
|
164
|
+
status_keys = [:privacy_status, :embeddable, :license,
|
165
|
+
:public_stats_viewable, :publish_at]
|
166
|
+
{snippet: {keys: snippet_keys}, status: {keys: status_keys}}
|
168
167
|
end
|
169
168
|
end
|
170
169
|
end
|
data/lib/yt/version.rb
CHANGED
@@ -194,6 +194,96 @@ describe Yt::Video, :device_app do
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
+
# note: 'scheduled' videos cannot be set to 'unlisted'
|
198
|
+
context 'given I update the privacy status' do
|
199
|
+
before { video.update publish_at: nil if video.scheduled? }
|
200
|
+
let!(:new_privacy_status) { old_privacy_status == 'private' ? 'unlisted' : 'private' }
|
201
|
+
|
202
|
+
context 'passing the parameter in underscore syntax' do
|
203
|
+
let(:attrs) { {privacy_status: new_privacy_status} }
|
204
|
+
|
205
|
+
specify 'only updates the privacy status' do
|
206
|
+
expect(update).to be true
|
207
|
+
expect(video.privacy_status).not_to eq old_privacy_status
|
208
|
+
expect(video.title).to eq old_title
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'passing the parameter in camel-case syntax' do
|
213
|
+
let(:attrs) { {privacyStatus: new_privacy_status} }
|
214
|
+
|
215
|
+
specify 'only updates the privacy status' do
|
216
|
+
expect(update).to be true
|
217
|
+
expect(video.privacy_status).not_to eq old_privacy_status
|
218
|
+
expect(video.title).to eq old_title
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'given I update the embeddable status' do
|
224
|
+
let!(:old_embeddable) { video.embeddable? }
|
225
|
+
let!(:new_embeddable) { !old_embeddable }
|
226
|
+
|
227
|
+
let(:attrs) { {embeddable: new_embeddable} }
|
228
|
+
|
229
|
+
# @note: This test is a reflection of another irrational behavior of
|
230
|
+
# YouTube API. Although 'embeddable' can be passed as an 'update'
|
231
|
+
# attribute according to the documentation, it simply does not work.
|
232
|
+
# The day YouTube fixes it, then this test will finally fail and will
|
233
|
+
# be removed, documenting how to update 'embeddable' too.
|
234
|
+
# @see https://developers.google.com/youtube/v3/docs/videos/update
|
235
|
+
# @see https://code.google.com/p/gdata-issues/issues/detail?id=4861
|
236
|
+
specify 'does not update the embeddable status' do
|
237
|
+
expect(update).to be true
|
238
|
+
expect(video.embeddable?).to eq old_embeddable
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context 'given I update the license' do
|
243
|
+
let!(:old_license) { video.license }
|
244
|
+
let!(:new_license) { old_license == 'youtube' ? 'creativeCommon' : 'youtube' }
|
245
|
+
let(:attrs) { {license: new_license} }
|
246
|
+
|
247
|
+
# @note: This test is a reflection of another irrational behavior of
|
248
|
+
# YouTube API. Although 'license' can be passed as an 'update'
|
249
|
+
# attribute according to the documentation, it simply does not work.
|
250
|
+
# The day YouTube fixes it, then this test will finally fail and will
|
251
|
+
# be removed, documenting how to update 'embeddable' too.
|
252
|
+
# @see https://developers.google.com/youtube/v3/docs/videos/update
|
253
|
+
# @see https://code.google.com/p/gdata-issues/issues/detail?id=4861
|
254
|
+
specify 'does not update the embeddable status' do
|
255
|
+
expect(update).to be true
|
256
|
+
expect(video.license).to eq old_license
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context 'given I update the public stats viewable setting' do
|
261
|
+
let!(:old_public_stats_viewable) { video.has_public_stats_viewable? }
|
262
|
+
let!(:new_public_stats_viewable) { !old_public_stats_viewable }
|
263
|
+
|
264
|
+
context 'passing the parameter in underscore syntax' do
|
265
|
+
let(:attrs) { {public_stats_viewable: new_public_stats_viewable} }
|
266
|
+
|
267
|
+
specify 'only updates the public stats viewable setting' do
|
268
|
+
expect(update).to be true
|
269
|
+
expect(video.has_public_stats_viewable?).to eq new_public_stats_viewable
|
270
|
+
expect(video.privacy_status).to eq old_privacy_status
|
271
|
+
expect(video.title).to eq old_title
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'passing the parameter in camel-case syntax' do
|
276
|
+
let(:attrs) { {publicStatsViewable: new_public_stats_viewable} }
|
277
|
+
|
278
|
+
specify 'only updates the public stats viewable setting' do
|
279
|
+
expect(update).to be true
|
280
|
+
expect(video.has_public_stats_viewable?).to eq new_public_stats_viewable
|
281
|
+
expect(video.privacy_status).to eq old_privacy_status
|
282
|
+
expect(video.title).to eq old_title
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
197
287
|
it 'returns valid reports for video-related metrics' do
|
198
288
|
# Some reports are only available to Content Owners.
|
199
289
|
# See content ownere test for more details about what the methods return.
|
@@ -219,4 +309,43 @@ describe Yt::Video, :device_app do
|
|
219
309
|
expect{video.viewer_percentage}.not_to raise_error
|
220
310
|
end
|
221
311
|
end
|
312
|
+
|
313
|
+
# @note: This test is separated from the block above because, for some
|
314
|
+
# undocumented reasons, if an existing video was private, then set to
|
315
|
+
# unlisted, then set to private again, YouTube _sometimes_ raises a
|
316
|
+
# 400 Error when trying to set the publishAt timestamp.
|
317
|
+
# Therefore, just to test the updating of publishAt, we use a brand new
|
318
|
+
# video (set to private), rather than reusing an existing one as above.
|
319
|
+
context 'given one of my own *private* videos that I want to update' do
|
320
|
+
before { @tmp_video = $account.upload_video 'https://bit.ly/yt_test', title: old_title, privacy_status: old_privacy_status }
|
321
|
+
let(:id) { @tmp_video.id }
|
322
|
+
let!(:old_title) { "Yt Test Update publishAt Video #{rand}" }
|
323
|
+
let!(:old_privacy_status) { 'private' }
|
324
|
+
after { video.delete}
|
325
|
+
|
326
|
+
let!(:new_scheduled_at) { Yt::Timestamp.parse("#{rand 30 + 1} Jan 2020", Time.now) }
|
327
|
+
|
328
|
+
context 'passing the parameter in underscore syntax' do
|
329
|
+
let(:attrs) { {publish_at: new_scheduled_at} }
|
330
|
+
|
331
|
+
specify 'only updates the timestamp to publish the video' do
|
332
|
+
expect(video.update attrs).to be true
|
333
|
+
expect(video.scheduled_at).to eq new_scheduled_at
|
334
|
+
expect(video.privacy_status).to eq old_privacy_status
|
335
|
+
expect(video.title).to eq old_title
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context 'passing the parameter in camel-case syntax' do
|
340
|
+
let(:attrs) { {publishAt: new_scheduled_at} }
|
341
|
+
|
342
|
+
specify 'only updates the timestamp to publish the video' do
|
343
|
+
expect(video.update attrs).to be true
|
344
|
+
expect(video.scheduled_at).to eq new_scheduled_at
|
345
|
+
expect(video.privacy_status).to eq old_privacy_status
|
346
|
+
expect(video.title).to eq old_title
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
222
351
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Baccigalupo
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/yt/models/statistics_set.rb
|
188
188
|
- lib/yt/models/status.rb
|
189
189
|
- lib/yt/models/subscription.rb
|
190
|
+
- lib/yt/models/timestamp.rb
|
190
191
|
- lib/yt/models/url.rb
|
191
192
|
- lib/yt/models/user_info.rb
|
192
193
|
- lib/yt/models/video.rb
|