yt 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile.lock +1 -1
- data/HISTORY.md +3 -0
- data/README.md +5 -1
- data/TODO.md +0 -2
- data/bin/yt +2 -0
- data/lib/yt/actions/delete_all.rb +2 -2
- data/lib/yt/associations/authentications.rb +17 -2
- data/lib/yt/collections/base.rb +6 -0
- data/lib/yt/collections/statuses.rb +22 -0
- data/lib/yt/collections/subscriptions.rb +1 -1
- data/lib/yt/collections/videos.rb +6 -1
- data/lib/yt/models/account.rb +6 -12
- data/lib/yt/models/base.rb +28 -2
- data/lib/yt/models/channel.rb +37 -2
- data/lib/yt/models/playlist.rb +24 -0
- data/lib/yt/models/video.rb +19 -0
- data/lib/yt/version.rb +1 -1
- data/spec/associations/device_auth/account_spec.rb +31 -0
- data/spec/associations/device_auth/channel_spec.rb +114 -0
- data/spec/associations/device_auth/content_owner_spec.rb +8 -0
- data/spec/associations/device_auth/earnings_spec.rb +2 -0
- data/spec/associations/device_auth/playlist_spec.rb +136 -0
- data/spec/associations/device_auth/{ids_spec.rb → resource_spec.rb} +2 -2
- data/spec/associations/device_auth/video_spec.rb +42 -0
- data/spec/associations/no_auth/video_spec.rb +13 -0
- data/spec/associations/server_auth/channel_spec.rb +50 -0
- data/spec/associations/server_auth/playlist_spec.rb +36 -0
- data/spec/associations/server_auth/{ids_spec.rb → resource_spec.rb} +2 -2
- data/spec/associations/server_auth/video_spec.rb +22 -0
- data/spec/models/channel_spec.rb +7 -0
- metadata +25 -60
- data/lib/yt/associations.rb +0 -38
- data/lib/yt/associations/annotations.rb +0 -15
- data/lib/yt/associations/channels.rb +0 -20
- data/lib/yt/associations/details_sets.rb +0 -20
- data/lib/yt/associations/ids.rb +0 -20
- data/lib/yt/associations/partnered_channels.rb +0 -14
- data/lib/yt/associations/playlist_items.rb +0 -34
- data/lib/yt/associations/playlists.rb +0 -22
- data/lib/yt/associations/ratings.rb +0 -39
- data/lib/yt/associations/snippets.rb +0 -20
- data/lib/yt/associations/statuses.rb +0 -14
- data/lib/yt/associations/subscriptions.rb +0 -34
- data/lib/yt/associations/user_infos.rb +0 -21
- data/lib/yt/associations/videos.rb +0 -14
- data/spec/associations/device_auth/channels_spec.rb +0 -8
- data/spec/associations/device_auth/details_sets_spec.rb +0 -18
- data/spec/associations/device_auth/partnered_channels_spec.rb +0 -15
- data/spec/associations/device_auth/playlist_items_spec.rb +0 -79
- data/spec/associations/device_auth/playlists_spec.rb +0 -61
- data/spec/associations/device_auth/ratings_spec.rb +0 -28
- data/spec/associations/device_auth/snippets_spec.rb +0 -28
- data/spec/associations/device_auth/subscriptions_spec.rb +0 -35
- data/spec/associations/device_auth/user_infos_spec.rb +0 -12
- data/spec/associations/device_auth/videos_spec.rb +0 -20
- data/spec/associations/no_auth/annotations_spec.rb +0 -15
- data/spec/associations/server_auth/channels_spec.rb +0 -2
- data/spec/associations/server_auth/details_sets_spec.rb +0 -18
- data/spec/associations/server_auth/playlist_items_spec.rb +0 -17
- data/spec/associations/server_auth/playlists_spec.rb +0 -17
- data/spec/associations/server_auth/ratings_spec.rb +0 -2
- data/spec/associations/server_auth/snippets_spec.rb +0 -28
- data/spec/associations/server_auth/subscriptions_spec.rb +0 -2
- data/spec/associations/server_auth/user_infos_spec.rb +0 -2
- data/spec/associations/server_auth/videos_spec.rb +0 -20
data/lib/yt/associations.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/delegation'
|
2
|
-
require 'active_support/dependencies/autoload'
|
3
|
-
require 'active_support/core_ext/string/inflections' # for camelize
|
4
|
-
|
5
|
-
module Yt
|
6
|
-
module Associations
|
7
|
-
# @note: Using Autoload to avoid circular dependencies.
|
8
|
-
# For instance: Yt::Channel requires Yt::Base, which requires
|
9
|
-
# Yt::Associations, which requires Yt::Associations::Subscription,
|
10
|
-
# which requires Yt::Subscription, which requires Yt::Base
|
11
|
-
extend ActiveSupport::Autoload
|
12
|
-
|
13
|
-
autoload :Annotations
|
14
|
-
autoload :Authentications
|
15
|
-
autoload :Channels
|
16
|
-
autoload :DetailsSets
|
17
|
-
autoload :Earnings
|
18
|
-
autoload :Ids
|
19
|
-
autoload :PartneredChannels
|
20
|
-
autoload :PlaylistItems
|
21
|
-
autoload :Playlists
|
22
|
-
autoload :Ratings
|
23
|
-
autoload :Snippets
|
24
|
-
autoload :Statuses
|
25
|
-
autoload :Subscriptions
|
26
|
-
autoload :UserInfos
|
27
|
-
autoload :Videos
|
28
|
-
autoload :Views
|
29
|
-
|
30
|
-
def has_many(attributes, options = {})
|
31
|
-
mod = attributes.to_s.sub(/.*\./, '').camelize
|
32
|
-
include "Yt::Associations::#{mod.pluralize}".constantize
|
33
|
-
delegate *options[:delegate], to: attributes if options[:delegate]
|
34
|
-
end
|
35
|
-
|
36
|
-
alias has_one has_many
|
37
|
-
end
|
38
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'yt/collections/annotations'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_many :annotations` method to YouTube resources,
|
6
|
-
# which allows to access to content annotation set-specific methods.
|
7
|
-
# YouTube resources with annotations are: videos.
|
8
|
-
module Annotations
|
9
|
-
def annotations
|
10
|
-
@annotations ||= Collections::Annotations.of self
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'yt/collections/channels'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :channel` method to YouTube resources, which
|
6
|
-
# allows to access to channel-specific methods like.
|
7
|
-
# YouTube resources with a channel are: account.
|
8
|
-
module Channels
|
9
|
-
def channel
|
10
|
-
@channel ||= channels.first
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def channels
|
16
|
-
@channels ||= Collections::Channels.of self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'yt/collections/details_sets'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :details_set` method to YouTube resources, which
|
6
|
-
# allows to access to content detail set-specific methods like `duration`.
|
7
|
-
# YouTube resources with content details are: videos.
|
8
|
-
module DetailsSets
|
9
|
-
def details_set
|
10
|
-
@detail_set ||= details_sets.first!
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def details_sets
|
16
|
-
@details_sets ||= Collections::DetailsSets.of self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/yt/associations/ids.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'yt/collections/ids'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :id` method to YouTube resources, which
|
6
|
-
# allows to retrieve the id of a resource knowing only its username.
|
7
|
-
# YouTube resources with ids are: resources.
|
8
|
-
module Ids
|
9
|
-
def id
|
10
|
-
@id ||= ids.first!
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def ids
|
16
|
-
@ids ||= Collections::Ids.of self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'yt/collections/partnered_channels'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_many :partnered_channels` method to YouTube resources,
|
6
|
-
# which allows to access to partnered channel-specific methods.
|
7
|
-
# YouTube resources with a channel are: content owners.
|
8
|
-
module PartneredChannels
|
9
|
-
def partnered_channels
|
10
|
-
@partnered_channels ||= Collections::PartneredChannels.of self
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'yt/collections/playlist_items'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_many :playlist_items` method to YouTube resources, which
|
6
|
-
# allows to invoke playlist_item-related methods, such as .add_video.
|
7
|
-
# YouTube resources with playlist items are: playlists.
|
8
|
-
module PlaylistItems
|
9
|
-
def playlist_items
|
10
|
-
@playlist_items ||= Collections::PlaylistItems.of self
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_video(video_id)
|
14
|
-
playlist_items.insert({id: video_id, kind: :video}, ignore_errors: true)
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_video!(video_id)
|
18
|
-
playlist_items.insert id: video_id, kind: :video
|
19
|
-
end
|
20
|
-
|
21
|
-
def add_videos(video_ids = [])
|
22
|
-
video_ids.map{|video_id| add_video video_id}
|
23
|
-
end
|
24
|
-
|
25
|
-
def add_videos!(video_ids = [])
|
26
|
-
video_ids.map{|video_id| add_video! video_id}
|
27
|
-
end
|
28
|
-
|
29
|
-
def delete_playlist_items(attrs = {})
|
30
|
-
playlist_items.delete_all attrs
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'yt/collections/playlists'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_many :playlists` method to YouTube resources, which
|
6
|
-
# allows to invoke playlist-related methods, such as .create_playlist.
|
7
|
-
# YouTube resources with playlist are: channels.
|
8
|
-
module Playlists
|
9
|
-
def playlists
|
10
|
-
@playlists ||= Collections::Playlists.of self
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_playlist(params = {})
|
14
|
-
playlists.insert params
|
15
|
-
end
|
16
|
-
|
17
|
-
def delete_playlists(attrs = {})
|
18
|
-
playlists.delete_all attrs
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'yt/collections/ratings'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :rating` method to YouTube resources, which
|
6
|
-
# allows to invoke rating-related methods, such as .like.
|
7
|
-
# YouTube resources with rating are: videos.
|
8
|
-
module Ratings
|
9
|
-
def rating
|
10
|
-
@rating ||= ratings.first
|
11
|
-
end
|
12
|
-
|
13
|
-
def liked?
|
14
|
-
rating.rating == :like
|
15
|
-
end
|
16
|
-
|
17
|
-
def like
|
18
|
-
rating.update :like
|
19
|
-
liked?
|
20
|
-
end
|
21
|
-
|
22
|
-
def dislike
|
23
|
-
rating.update :dislike
|
24
|
-
!liked?
|
25
|
-
end
|
26
|
-
|
27
|
-
def unlike
|
28
|
-
rating.update :none
|
29
|
-
!liked?
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def ratings
|
35
|
-
@ratings ||= Collections::Ratings.of self
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'yt/collections/snippets'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :snippet` method to YouTube resources, which
|
6
|
-
# allows to access to content detail set-specific methods like `title`.
|
7
|
-
# YouTube resources with content details are: videos and channels.
|
8
|
-
module Snippets
|
9
|
-
def snippet
|
10
|
-
@snippet ||= snippets.first!
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def snippets
|
16
|
-
@snippets ||= Collections::Snippets.of self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'yt/models/status'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :status` method to YouTube resources, which
|
6
|
-
# allows to access to status-specific methods like `public?`.
|
7
|
-
# YouTube resources with status are: playlists.
|
8
|
-
module Statuses
|
9
|
-
def status
|
10
|
-
@status
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'yt/collections/subscriptions'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :subscription` method to YouTube resources, which
|
6
|
-
# allows to invoke subscription-related methods, such as .subscribe.
|
7
|
-
# YouTube resources with subscription are: channels.
|
8
|
-
module Subscriptions
|
9
|
-
def subscriptions
|
10
|
-
@subscriptions ||= Collections::Subscriptions.of self
|
11
|
-
end
|
12
|
-
|
13
|
-
def subscribed?
|
14
|
-
subscriptions.any?{|s| s.exists?}
|
15
|
-
end
|
16
|
-
|
17
|
-
def subscribe
|
18
|
-
subscriptions.insert ignore_errors: true
|
19
|
-
end
|
20
|
-
|
21
|
-
def subscribe!
|
22
|
-
subscriptions.insert
|
23
|
-
end
|
24
|
-
|
25
|
-
def unsubscribe
|
26
|
-
subscriptions.delete_all({}, ignore_errors: true)
|
27
|
-
end
|
28
|
-
|
29
|
-
def unsubscribe!
|
30
|
-
subscriptions.delete_all
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'yt/collections/user_infos'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_one :user_info` method to YouTube resources, which
|
6
|
-
# allows to access to user_info-specific methods like `email`.
|
7
|
-
# YouTube resources with user infos are: accounts.
|
8
|
-
module UserInfos
|
9
|
-
def user_info
|
10
|
-
@user_info ||= user_infos.first!
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def user_infos
|
16
|
-
@user_infos ||= Collections::UserInfos.of self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'yt/collections/videos'
|
2
|
-
|
3
|
-
module Yt
|
4
|
-
module Associations
|
5
|
-
# Provides the `has_many :videos` method to YouTube resources, which
|
6
|
-
# allows to access only the videos that belong to a specific resource.
|
7
|
-
# YouTube resources with videos are: channels.
|
8
|
-
module Videos
|
9
|
-
def videos
|
10
|
-
@videos ||= Collections::Videos.of self
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'yt/associations/details_sets'
|
3
|
-
|
4
|
-
describe Yt::Associations::DetailsSets, :device_app do
|
5
|
-
let(:video) { Yt::Video.new id: 'fsdfsfsdMESycYJytkU', auth: $account }
|
6
|
-
|
7
|
-
describe '#details_set' do
|
8
|
-
context 'given an existing video' do
|
9
|
-
let(:video) { Yt::Video.new id: 'MESycYJytkU', auth: $account }
|
10
|
-
it { expect(video.details_set).to be_a Yt::DetailsSet }
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'given an unknown video' do
|
14
|
-
let(:video) { Yt::Video.new id: 'not-a-video-id', auth: $account }
|
15
|
-
it { expect{video.details_set}.to raise_error Yt::Errors::NoItems }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yt::Associations::PartneredChannels, :partner do
|
4
|
-
describe '#partnered_channels' do
|
5
|
-
let(:partnered_channels) { content_owner.partnered_channels }
|
6
|
-
|
7
|
-
context 'given a content owner with partnered channels' do
|
8
|
-
let(:content_owner) { $content_owner }
|
9
|
-
|
10
|
-
# NOTE: Uncomment once size does not runs through *all* the pages
|
11
|
-
# it { expect(partnered_channels.size).to be > 0 }
|
12
|
-
it { expect(partnered_channels.first).to be_a Yt::Channel }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'yt/associations/playlist_items'
|
3
|
-
|
4
|
-
# TODO: Delete playlist item after tests that create them
|
5
|
-
|
6
|
-
describe Yt::Associations::PlaylistItems, :device_app do
|
7
|
-
before:all do
|
8
|
-
@playlist = $account.create_playlist title: "Yt Test Playlist Items"
|
9
|
-
end
|
10
|
-
after(:all) { @playlist.delete }
|
11
|
-
|
12
|
-
describe '#playlist_items' do
|
13
|
-
let(:video_id) { 'MESycYJytkU' }
|
14
|
-
before { @playlist.add_video video_id }
|
15
|
-
|
16
|
-
it { expect(@playlist.playlist_items.count).to be > 0 }
|
17
|
-
it { expect(@playlist.playlist_items.first).to be_a Yt::PlaylistItem }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#add_video' do
|
21
|
-
context 'given an existing video' do
|
22
|
-
let(:video_id) { 'MESycYJytkU' }
|
23
|
-
it { expect(@playlist.add_video video_id).to be_a Yt::PlaylistItem }
|
24
|
-
it { expect{@playlist.add_video video_id}.to change{@playlist.playlist_items.count}.by(1) }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'given an unknown video' do
|
28
|
-
let(:video_id) { 'not-a-video' }
|
29
|
-
it { expect(@playlist.add_video video_id).to be_nil }
|
30
|
-
it { expect{@playlist.add_video video_id}.not_to change{@playlist.playlist_items.count} }
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'given a video of a terminated account' do
|
34
|
-
let(:video_id) { 'kDCpdKeTe5g' }
|
35
|
-
it { expect(@playlist.add_video video_id).to be_nil }
|
36
|
-
it { expect{@playlist.add_video video_id}.not_to change{@playlist.playlist_items.count} }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#add_video!' do
|
41
|
-
context 'given an existing video' do
|
42
|
-
let(:video_id) { 'MESycYJytkU' }
|
43
|
-
it { expect(@playlist.add_video video_id).to be_a Yt::PlaylistItem }
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'given an unknown video' do
|
47
|
-
let(:video_id) { 'not-a-video' }
|
48
|
-
it { expect{@playlist.add_video! video_id}.to fail.with 'videoNotFound' }
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'given a video of a terminated account' do
|
52
|
-
let(:video_id) { 'kDCpdKeTe5g' }
|
53
|
-
it { expect{@playlist.add_video! video_id}.to fail.with 'forbidden' }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#add_videos' do
|
58
|
-
context 'given one existing and one unknown video' do
|
59
|
-
let(:video_ids) { ['MESycYJytkU', 'not-a-video'] }
|
60
|
-
it { expect(@playlist.add_videos(video_ids).length).to eq 2 }
|
61
|
-
it { expect{@playlist.add_videos video_ids}.to change{@playlist.playlist_items.count}.by(1) }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#add_videos!' do
|
66
|
-
context 'given one existing and one unknown video' do
|
67
|
-
let(:video_ids) { ['MESycYJytkU', 'not-a-video'] }
|
68
|
-
it { expect{@playlist.add_videos! video_ids}.to fail.with 'videoNotFound'}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#delete_playlist_items' do
|
73
|
-
let(:video_id) { 'MESycYJytkU' }
|
74
|
-
before { @playlist.add_video video_id }
|
75
|
-
|
76
|
-
it { expect(@playlist.delete_playlist_items.uniq).to eq [true] }
|
77
|
-
it { expect{@playlist.delete_playlist_items}.to change{@playlist.playlist_items.count} }
|
78
|
-
end
|
79
|
-
end
|