yt 0.6.1 → 0.6.2

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/HISTORY.md +3 -0
  5. data/README.md +5 -1
  6. data/TODO.md +0 -2
  7. data/bin/yt +2 -0
  8. data/lib/yt/actions/delete_all.rb +2 -2
  9. data/lib/yt/associations/authentications.rb +17 -2
  10. data/lib/yt/collections/base.rb +6 -0
  11. data/lib/yt/collections/statuses.rb +22 -0
  12. data/lib/yt/collections/subscriptions.rb +1 -1
  13. data/lib/yt/collections/videos.rb +6 -1
  14. data/lib/yt/models/account.rb +6 -12
  15. data/lib/yt/models/base.rb +28 -2
  16. data/lib/yt/models/channel.rb +37 -2
  17. data/lib/yt/models/playlist.rb +24 -0
  18. data/lib/yt/models/video.rb +19 -0
  19. data/lib/yt/version.rb +1 -1
  20. data/spec/associations/device_auth/account_spec.rb +31 -0
  21. data/spec/associations/device_auth/channel_spec.rb +114 -0
  22. data/spec/associations/device_auth/content_owner_spec.rb +8 -0
  23. data/spec/associations/device_auth/earnings_spec.rb +2 -0
  24. data/spec/associations/device_auth/playlist_spec.rb +136 -0
  25. data/spec/associations/device_auth/{ids_spec.rb → resource_spec.rb} +2 -2
  26. data/spec/associations/device_auth/video_spec.rb +42 -0
  27. data/spec/associations/no_auth/video_spec.rb +13 -0
  28. data/spec/associations/server_auth/channel_spec.rb +50 -0
  29. data/spec/associations/server_auth/playlist_spec.rb +36 -0
  30. data/spec/associations/server_auth/{ids_spec.rb → resource_spec.rb} +2 -2
  31. data/spec/associations/server_auth/video_spec.rb +22 -0
  32. data/spec/models/channel_spec.rb +7 -0
  33. metadata +25 -60
  34. data/lib/yt/associations.rb +0 -38
  35. data/lib/yt/associations/annotations.rb +0 -15
  36. data/lib/yt/associations/channels.rb +0 -20
  37. data/lib/yt/associations/details_sets.rb +0 -20
  38. data/lib/yt/associations/ids.rb +0 -20
  39. data/lib/yt/associations/partnered_channels.rb +0 -14
  40. data/lib/yt/associations/playlist_items.rb +0 -34
  41. data/lib/yt/associations/playlists.rb +0 -22
  42. data/lib/yt/associations/ratings.rb +0 -39
  43. data/lib/yt/associations/snippets.rb +0 -20
  44. data/lib/yt/associations/statuses.rb +0 -14
  45. data/lib/yt/associations/subscriptions.rb +0 -34
  46. data/lib/yt/associations/user_infos.rb +0 -21
  47. data/lib/yt/associations/videos.rb +0 -14
  48. data/spec/associations/device_auth/channels_spec.rb +0 -8
  49. data/spec/associations/device_auth/details_sets_spec.rb +0 -18
  50. data/spec/associations/device_auth/partnered_channels_spec.rb +0 -15
  51. data/spec/associations/device_auth/playlist_items_spec.rb +0 -79
  52. data/spec/associations/device_auth/playlists_spec.rb +0 -61
  53. data/spec/associations/device_auth/ratings_spec.rb +0 -28
  54. data/spec/associations/device_auth/snippets_spec.rb +0 -28
  55. data/spec/associations/device_auth/subscriptions_spec.rb +0 -35
  56. data/spec/associations/device_auth/user_infos_spec.rb +0 -12
  57. data/spec/associations/device_auth/videos_spec.rb +0 -20
  58. data/spec/associations/no_auth/annotations_spec.rb +0 -15
  59. data/spec/associations/server_auth/channels_spec.rb +0 -2
  60. data/spec/associations/server_auth/details_sets_spec.rb +0 -18
  61. data/spec/associations/server_auth/playlist_items_spec.rb +0 -17
  62. data/spec/associations/server_auth/playlists_spec.rb +0 -17
  63. data/spec/associations/server_auth/ratings_spec.rb +0 -2
  64. data/spec/associations/server_auth/snippets_spec.rb +0 -28
  65. data/spec/associations/server_auth/subscriptions_spec.rb +0 -2
  66. data/spec/associations/server_auth/user_infos_spec.rb +0 -2
  67. data/spec/associations/server_auth/videos_spec.rb +0 -20
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/playlists'
3
-
4
- describe Yt::Associations::Playlists, :device_app do
5
- let(:title) { 'Yt Test title' }
6
- let(:description) { 'Yt Test description' }
7
- let(:tags) { ['Yt Test Tag 1', 'Yt Test Tag 2'] }
8
- let(:privacy_status) { 'unlisted' }
9
- let(:params) { {title: title, description: description, tags: tags, privacy_status: privacy_status} }
10
-
11
- describe 'playlists' do
12
- before { $account.create_playlist params }
13
- after { $account.delete_playlists params }
14
-
15
- it { expect($account.playlists.count).to be > 0 }
16
- it { expect($account.playlists.first).to be_a Yt::Playlist }
17
- end
18
-
19
- describe 'create a playlist' do
20
- after { $account.delete_playlists params }
21
-
22
- it { expect($account.create_playlist params).to be_a Yt::Playlist }
23
- it { expect{$account.create_playlist params}.to change{$account.playlists.count}.by(1) }
24
- end
25
-
26
- describe 'delete a playlist' do
27
- let(:title) { "Yt Test Delete Playlist #{rand}" }
28
- before { @playlist = $account.create_playlist params }
29
-
30
- it { expect(@playlist.delete).to be true }
31
- end
32
-
33
- describe 'delete a set of playlists' do
34
- let(:title) { "Yt Test Delete All Playlists #{rand}" }
35
- before { $account.create_playlist params }
36
-
37
- it { expect($account.delete_playlists title: %r{#{params[:title]}}).to eq [true] }
38
- it { expect($account.delete_playlists params).to eq [true] }
39
- it { expect{$account.delete_playlists params}.to change{$account.playlists.count}.by(-1) }
40
- end
41
-
42
- describe 'update a playlist' do
43
- before { @playlist = $account.create_playlist params }
44
- after { @playlist.delete }
45
-
46
- context 'changes the attributes that are specified to be updated' do
47
- let(:new_attrs) { {title: "Yt Test Update Playlist #{rand}"} }
48
- it { expect(@playlist.update new_attrs).to eq true }
49
- it { expect{@playlist.update new_attrs}.to change{@playlist.title} }
50
- end
51
-
52
- context 'does not changes the attributes that are not specified to be updated' do
53
- let(:new_attrs) { {} }
54
- it { expect(@playlist.update new_attrs).to eq true }
55
- it { expect{@playlist.update new_attrs}.not_to change{@playlist.title} }
56
- it { expect{@playlist.update new_attrs}.not_to change{@playlist.description} }
57
- it { expect{@playlist.update new_attrs}.not_to change{@playlist.tags} }
58
- it { expect{@playlist.update new_attrs}.not_to change{@playlist.privacy_status} }
59
- end
60
- end
61
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/video'
3
-
4
- describe Yt::Associations::Ratings, :device_app do
5
- describe '#rating' do
6
- context 'given an existing video' do
7
- let(:video) { Yt::Video.new id: 'MESycYJytkU', auth: $account }
8
-
9
- context 'that I like' do
10
- before { video.like }
11
- it { expect(video).to be_liked }
12
- it { expect(video.dislike).to be true }
13
- end
14
-
15
- context 'that I dislike' do
16
- before { video.dislike }
17
- it { expect(video).not_to be_liked }
18
- it { expect(video.like).to be true }
19
- end
20
-
21
- context 'that I am indifferent to' do
22
- before { video.unlike }
23
- it { expect(video).not_to be_liked }
24
- it { expect(video.like).to be true }
25
- end
26
- end
27
- end
28
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/snippets'
3
- require 'yt/models/channel'
4
- require 'yt/models/video'
5
-
6
- describe Yt::Associations::Snippets, :device_app do
7
- describe '#snippet' do
8
- context 'given an existing video resource' do
9
- let(:video) { Yt::Video.new id: 'MESycYJytkU', auth: $account }
10
- it { expect(video.snippet).to be_a Yt::Snippet }
11
- end
12
-
13
- context 'given an unknown video resource' do
14
- let(:video) { Yt::Video.new id: 'not-a-video-id', auth: $account }
15
- it { expect{video.snippet}.to raise_error Yt::Errors::NoItems }
16
- end
17
-
18
- context 'given an existing channel resource' do
19
- let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow', auth: $account }
20
- it { expect(channel.snippet).to be_a Yt::Snippet }
21
- end
22
-
23
- context 'given an unknown channel resource' do
24
- let(:channel) { Yt::Channel.new id: 'not-a-channel-id', auth: $account }
25
- it { expect{channel.snippet}.to raise_error Yt::Errors::NoItems }
26
- end
27
- end
28
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/channel'
3
-
4
- describe Yt::Associations::Subscriptions, :device_app do
5
- describe '#subscription' do
6
- # NOTE: These tests are slow because we *must* wait some seconds between
7
- # subscribing and unsubscribing to a channel, otherwise YouTube will show
8
- # wrong (cached) data, such as a user is subscribed when he is not.
9
- context 'given an existing channel' do
10
- let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow', auth: $account }
11
-
12
- context 'that I am not subscribed to' do
13
- before { channel.unsubscribe }
14
- it { expect(channel.subscribed?).to be false }
15
- it { expect(channel.subscribe!).to be_truthy }
16
- end
17
-
18
- context 'that I am subscribed to' do
19
- before { channel.subscribe }
20
- it { expect(channel.subscribed?).to be true }
21
- it { expect(channel.unsubscribe!).to be_truthy }
22
- end
23
- end
24
-
25
- # NOTE: This test is just a reflection of YouTube irrational behavior of
26
- # raising a 500 error when you try to subscribe to your own channel, rather
27
- # than a more logical 4xx error. Hopefully this will get fixed and this
28
- # code (and test) removed.
29
- context 'given my own channel' do
30
- let(:channel) { Yt::Channel.new id: $account.channel.id, auth: $account }
31
-
32
- it { expect{channel.subscribe}.to raise_error Yt::Errors::ServerError }
33
- end
34
- end
35
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/user_infos'
3
-
4
- describe Yt::Associations::UserInfos, :device_app do
5
- describe '#user_info' do
6
- context 'given an existing account' do
7
- it { expect($account.user_info).to be_a Yt::UserInfo }
8
- end
9
-
10
- # Note: testing with an unknown account would fail before getting user info
11
- end
12
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/videos'
3
-
4
- describe Yt::Associations::Videos, :device_app do
5
- describe '#videos' do
6
- context 'given a channel with videos' do
7
- let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow', auth: $account }
8
- it { expect(channel.videos.count).to be > 0 }
9
- it { expect(channel.videos.first).to be_a Yt::Video }
10
- end
11
-
12
- # NOTE: with an unknown channel id, YouTube behaves weirdly: if the
13
- # wrong channel ID starts with "UC" then it returns 0 results, otherwise
14
- # it ignores the channel filter and returns 100,000 results.
15
- context 'given an unknown channel starting with UC' do
16
- let(:channel) { Yt::Channel.new id: 'UC-not-a-channel', auth: $account }
17
- it { expect(channel.videos.count).to be 0 }
18
- end
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/annotations'
3
- require 'yt/models/video'
4
-
5
- describe Yt::Associations::Annotations do
6
- subject(:annotations) { video.annotations }
7
-
8
- describe '#annotations' do
9
- context 'given an existing video with annotations' do
10
- let(:video) { Yt::Video.new id: 'MESycYJytkU' }
11
- it { expect(annotations.count).to be > 0 }
12
- it { expect(annotations.first).to be_a Yt::Annotation }
13
- end
14
- end
15
- end
@@ -1,2 +0,0 @@
1
- # Channels cannot be tested with a server app because
2
- # only authenticated clients can have channels
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/details_sets'
3
-
4
- describe Yt::Associations::DetailsSets, :server_app do
5
- subject(:video) { Yt::Video.new id: video_id }
6
-
7
- describe '#details_set' do
8
- context 'given an existing video' do
9
- let(:video_id) { 'MESycYJytkU' }
10
- it { expect(video.details_set).to be_a Yt::DetailsSet }
11
- end
12
-
13
- context 'given an unknown video' do
14
- let(:video_id) { 'not-a-video-id' }
15
- it { expect{video.details_set}.to raise_error Yt::Errors::NoItems }
16
- end
17
- end
18
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/playlist'
3
- require 'yt/models/playlist_item'
4
-
5
- describe Yt::Associations::PlaylistItems, :server_app do
6
- describe '#playlist_items' do
7
- subject(:playlist_items) { playlist.playlist_items }
8
-
9
- context 'given an existing playlist with items' do
10
- let(:playlist) { Yt::Playlist.new id: 'PLSWYkYzOrPMRCK6j0UgryI8E0NHhoVdRc' }
11
- it { expect(playlist_items.first).to be_a Yt::PlaylistItem }
12
- end
13
- end
14
-
15
- # Creating and deleting playlist items cannot be tested with a server
16
- # app because only authenticated clients can perform those actions
17
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/channel'
3
- require 'yt/models/playlist'
4
-
5
- describe Yt::Associations::Playlists, :server_app do
6
- describe '#playlists' do
7
- subject(:playlists) { channel.playlists }
8
-
9
- context 'given an existing channel with playlists' do
10
- let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow' }
11
- it { expect(playlists.first).to be_a Yt::Playlist }
12
- end
13
- end
14
-
15
- # Creating and deleting playlist cannot be tested with a server app because
16
- # only authenticated clients can perform those actions
17
- end
@@ -1,2 +0,0 @@
1
- # Ratings cannot be tested with a server app because
2
- # only authenticated clients can like and unlike videos
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/snippets'
3
- require 'yt/models/channel'
4
- require 'yt/models/video'
5
-
6
- describe Yt::Associations::Snippets, :server_app do
7
- describe '#snippet' do
8
- context 'given an existing video resource' do
9
- let(:video) { Yt::Video.new id: 'MESycYJytkU' }
10
- it { expect(video.snippet).to be_a Yt::Snippet }
11
- end
12
-
13
- context 'given an unknown video resource' do
14
- let(:video) { Yt::Video.new id: 'not-a-video-id' }
15
- it { expect{video.snippet}.to raise_error Yt::Errors::NoItems }
16
- end
17
-
18
- context 'given an existing channel resource' do
19
- let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow' }
20
- it { expect(channel.snippet).to be_a Yt::Snippet }
21
- end
22
-
23
- context 'given an unknown channel resource' do
24
- let(:channel) { Yt::Channel.new id: 'not-a-channel-id' }
25
- it { expect{channel.snippet}.to raise_error Yt::Errors::NoItems }
26
- end
27
- end
28
- end
@@ -1,2 +0,0 @@
1
- # Subscriptions cannot be tested with a server app because
2
- # only authenticated clients can subscribe and unsubscribe
@@ -1,2 +0,0 @@
1
- # User infos cannot be tested with a server app because
2
- # only authenticated clients can like and unlike videos
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/associations/videos'
3
-
4
- describe Yt::Associations::Videos, :server_app do
5
- describe '#videos' do
6
- context 'given a channel with videos' do
7
- let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow' }
8
- it { expect(channel.videos.count).to be > 0 }
9
- it { expect(channel.videos.first).to be_a Yt::Video }
10
- end
11
-
12
- # NOTE: with an unknown channel id, YouTube behaves weirdly: if the
13
- # wrong channel ID starts with "UC" then it returns 0 results, otherwise
14
- # it ignores the channel filter and returns 100,000 results.
15
- context 'given an unknown channel starting with UC' do
16
- let(:channel) { Yt::Channel.new id: 'UC-not-a-channel' }
17
- it { expect(channel.videos.count).to be 0 }
18
- end
19
- end
20
- end