yt 0.32.5 → 0.33.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -4
  3. data/CHANGELOG.md +40 -0
  4. data/README.md +22 -33
  5. data/YOUTUBE_IT.md +4 -4
  6. data/lib/yt.rb +1 -1
  7. data/lib/yt/actions/list.rb +1 -1
  8. data/lib/yt/associations/has_reports.rb +9 -14
  9. data/lib/yt/collections/playlist_items.rb +10 -1
  10. data/lib/yt/collections/reports.rb +5 -7
  11. data/lib/yt/models/account.rb +20 -0
  12. data/lib/yt/models/channel.rb +2 -5
  13. data/lib/yt/models/content_owner.rb +20 -0
  14. data/lib/yt/models/playlist.rb +12 -2
  15. data/lib/yt/models/playlist_item.rb +8 -1
  16. data/lib/yt/models/resource.rb +74 -3
  17. data/lib/yt/models/statistics_set.rb +2 -1
  18. data/lib/yt/models/url.rb +2 -60
  19. data/lib/yt/models/video.rb +15 -2
  20. data/lib/yt/request.rb +6 -2
  21. data/lib/yt/version.rb +1 -1
  22. data/yt.gemspec +5 -2
  23. metadata +35 -174
  24. data/spec/collections/claims_spec.rb +0 -62
  25. data/spec/collections/comment_threads_spec.rb +0 -46
  26. data/spec/collections/playlist_items_spec.rb +0 -44
  27. data/spec/collections/playlists_spec.rb +0 -27
  28. data/spec/collections/policies_spec.rb +0 -30
  29. data/spec/collections/references_spec.rb +0 -30
  30. data/spec/collections/reports_spec.rb +0 -30
  31. data/spec/collections/subscriptions_spec.rb +0 -25
  32. data/spec/collections/videos_spec.rb +0 -43
  33. data/spec/constants/geography_spec.rb +0 -16
  34. data/spec/errors/forbidden_spec.rb +0 -10
  35. data/spec/errors/missing_auth_spec.rb +0 -24
  36. data/spec/errors/no_items_spec.rb +0 -10
  37. data/spec/errors/request_error_spec.rb +0 -44
  38. data/spec/errors/server_error_spec.rb +0 -10
  39. data/spec/errors/unauthorized_spec.rb +0 -10
  40. data/spec/models/account_spec.rb +0 -138
  41. data/spec/models/annotation_spec.rb +0 -180
  42. data/spec/models/asset_spec.rb +0 -32
  43. data/spec/models/channel_spec.rb +0 -127
  44. data/spec/models/claim_event_spec.rb +0 -62
  45. data/spec/models/claim_history_spec.rb +0 -27
  46. data/spec/models/claim_spec.rb +0 -223
  47. data/spec/models/comment_spec.rb +0 -40
  48. data/spec/models/comment_thread_spec.rb +0 -93
  49. data/spec/models/configuration_spec.rb +0 -44
  50. data/spec/models/content_detail_spec.rb +0 -52
  51. data/spec/models/content_owner_detail_spec.rb +0 -6
  52. data/spec/models/file_detail_spec.rb +0 -13
  53. data/spec/models/live_streaming_detail_spec.rb +0 -6
  54. data/spec/models/ownership_spec.rb +0 -59
  55. data/spec/models/player_spec.rb +0 -13
  56. data/spec/models/playlist_item_spec.rb +0 -120
  57. data/spec/models/playlist_spec.rb +0 -138
  58. data/spec/models/policy_rule_spec.rb +0 -63
  59. data/spec/models/policy_spec.rb +0 -41
  60. data/spec/models/rating_spec.rb +0 -12
  61. data/spec/models/reference_spec.rb +0 -249
  62. data/spec/models/request_spec.rb +0 -204
  63. data/spec/models/resource_spec.rb +0 -42
  64. data/spec/models/right_owner_spec.rb +0 -71
  65. data/spec/models/snippet_spec.rb +0 -13
  66. data/spec/models/statistics_set_spec.rb +0 -13
  67. data/spec/models/status_spec.rb +0 -13
  68. data/spec/models/subscription_spec.rb +0 -30
  69. data/spec/models/url_spec.rb +0 -78
  70. data/spec/models/video_category_spec.rb +0 -21
  71. data/spec/models/video_spec.rb +0 -669
  72. data/spec/requests/as_account/account_spec.rb +0 -143
  73. data/spec/requests/as_account/authentications_spec.rb +0 -127
  74. data/spec/requests/as_account/channel_spec.rb +0 -246
  75. data/spec/requests/as_account/channels_spec.rb +0 -18
  76. data/spec/requests/as_account/playlist_item_spec.rb +0 -55
  77. data/spec/requests/as_account/playlist_spec.rb +0 -218
  78. data/spec/requests/as_account/thumbnail.jpg +0 -0
  79. data/spec/requests/as_account/video.mp4 +0 -0
  80. data/spec/requests/as_account/video_spec.rb +0 -408
  81. data/spec/requests/as_content_owner/account_spec.rb +0 -29
  82. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +0 -15
  83. data/spec/requests/as_content_owner/asset_spec.rb +0 -31
  84. data/spec/requests/as_content_owner/bulk_report_job_spec.rb +0 -19
  85. data/spec/requests/as_content_owner/channel_spec.rb +0 -1836
  86. data/spec/requests/as_content_owner/claim_history_spec.rb +0 -20
  87. data/spec/requests/as_content_owner/claim_spec.rb +0 -17
  88. data/spec/requests/as_content_owner/content_owner_spec.rb +0 -370
  89. data/spec/requests/as_content_owner/match_policy_spec.rb +0 -17
  90. data/spec/requests/as_content_owner/ownership_spec.rb +0 -25
  91. data/spec/requests/as_content_owner/playlist_spec.rb +0 -767
  92. data/spec/requests/as_content_owner/video_group_spec.rb +0 -112
  93. data/spec/requests/as_content_owner/video_spec.rb +0 -1211
  94. data/spec/requests/as_server_app/channel_spec.rb +0 -54
  95. data/spec/requests/as_server_app/comment_spec.rb +0 -22
  96. data/spec/requests/as_server_app/comment_thread_spec.rb +0 -27
  97. data/spec/requests/as_server_app/comment_threads_spec.rb +0 -41
  98. data/spec/requests/as_server_app/playlist_item_spec.rb +0 -30
  99. data/spec/requests/as_server_app/playlist_spec.rb +0 -33
  100. data/spec/requests/as_server_app/url_spec.rb +0 -94
  101. data/spec/requests/as_server_app/video_spec.rb +0 -60
  102. data/spec/requests/as_server_app/videos_spec.rb +0 -40
  103. data/spec/requests/unauthenticated/video_spec.rb +0 -14
  104. data/spec/spec_helper.rb +0 -20
  105. data/spec/support/fail_matcher.rb +0 -15
  106. data/spec/support/global_hooks.rb +0 -48
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/claims'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::Claims do
6
- let(:content_owner) { Yt::ContentOwner.new owner_name: 'any-name' }
7
- let(:collection) { Yt::Collections::Claims.new parent: content_owner, auth: content_owner }
8
- let(:page) { {items: [], token: 'any-token'} }
9
- let(:query) { {q: 'search string'} }
10
-
11
- describe "#insert" do
12
- let(:attributes) {
13
- {
14
- asset_id: 'some_asset_id',
15
- video_id: 'some_video_id',
16
- content_type: 'audiovisual',
17
- policy: { id: 'some_policy_id' },
18
- match_info: { match_segments: [ { manual_segment: { start: "00:01:00.000", finish: "00:02:00.000" } } ] },
19
- is_manual_claim: true
20
- }
21
- }
22
-
23
- before do
24
- allow(collection).to receive(:do_insert)
25
- collection.insert(attributes.deep_dup)
26
- end
27
-
28
- it 'calls do_insert with appropriate body' do
29
- body = {
30
- asset_id: 'some_asset_id',
31
- video_id: 'some_video_id',
32
- content_type: 'audiovisual',
33
- policy: { id: 'some_policy_id' },
34
- match_info: { matchSegments: [ { manual_segment: { start: "00:01:00.000", finish: "00:02:00.000" } } ] }
35
- }
36
- expect(collection).to have_received(:do_insert).with(
37
- params: { is_manual_claim: true, on_behalf_of_content_owner: content_owner.owner_name },
38
- body: body
39
- )
40
- end
41
- end
42
-
43
- describe '#count' do
44
- context 'called once with .where(query) and once without' do
45
- after do
46
- collection.where(query).count
47
- collection.count
48
- end
49
-
50
- it 'only applies the query on the first call' do
51
- expect(collection).to receive(:fetch_page) do |options|
52
- expect(options[:params]).to include query
53
- page
54
- end
55
- expect(collection).to receive(:fetch_page) do |options|
56
- expect(options[:params]).not_to include query
57
- page
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/comment_threads'
3
- require 'yt/models/video'
4
- require 'yt/models/channel'
5
-
6
- describe Yt::Collections::CommentThreads do
7
- subject(:collection) { Yt::Collections::CommentThreads.new parent: parent}
8
-
9
- describe '#size', :ruby2 do
10
- describe 'sends only one request and return the total results' do
11
- let(:total_results) { 1234 }
12
- let(:parent) { Yt::Video.new id: 'any-id' }
13
-
14
- before do
15
- expect_any_instance_of(Yt::Request).to receive(:run).once do
16
- double(body: {'pageInfo'=>{'totalResults'=>total_results}})
17
- end
18
- end
19
- it { expect(collection.size).to be total_results }
20
- end
21
- end
22
-
23
- describe '#count' do
24
- let(:query) { {q: 'search string'} }
25
- let(:parent) { Yt::Video.new id: 'any-id' }
26
- let(:page) { {items: [], token: 'any-token'} }
27
-
28
- context 'called once with .where(query) and once without' do
29
- after do
30
- collection.where(query).count
31
- collection.count
32
- end
33
-
34
- it 'only applies the query on the first call' do
35
- expect(collection).to receive(:fetch_page) do |options|
36
- expect(options[:params]).to include query
37
- page
38
- end
39
- expect(collection).to receive(:fetch_page) do |options|
40
- expect(options[:params]).not_to include query
41
- page
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/models/playlist'
3
- require 'yt/models/playlist_item'
4
- require 'yt/collections/playlist_items'
5
-
6
- describe Yt::Collections::PlaylistItems do
7
- subject(:collection) { Yt::Collections::PlaylistItems.new parent: playlist }
8
- let(:playlist) { Yt::Playlist.new id: 'LLxO1tY8h1AhOz0T4ENwmpow' }
9
- let(:attrs) { {id: '9bZkp7q19f0', kind: :video} }
10
- let(:msg) { {response_body: {error: {errors: [{reason: reason}]}}}.to_json }
11
- before { expect(collection).to behave }
12
-
13
- describe '#insert' do
14
- let(:playlist_item) { Yt::PlaylistItem.new }
15
-
16
- context 'given an existing video' do
17
- let(:behave) { receive(:do_insert).and_return playlist_item }
18
-
19
- it { expect(collection.insert attrs).to eq playlist_item }
20
- end
21
-
22
- context 'given an unknown video' do
23
- let(:reason) { 'videoNotFound' }
24
- let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }
25
-
26
- it { expect{collection.insert attrs}.to fail.with 'videoNotFound' }
27
- it { expect{collection.insert attrs, ignore_errors: true}.not_to fail }
28
- end
29
-
30
- context 'given a forbidden video' do
31
- let(:reason) { 'forbidden' }
32
- let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }
33
-
34
- it { expect{collection.insert attrs}.to fail.with 'forbidden' }
35
- it { expect{collection.insert attrs, ignore_errors: true}.not_to fail }
36
- end
37
- end
38
-
39
- describe '#delete_all' do
40
- let(:behave) { receive(:do_delete_all).and_return [true] }
41
-
42
- it { expect(collection.delete_all).to eq [true] }
43
- end
44
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/playlists'
3
-
4
- describe Yt::Collections::Playlists do
5
- subject(:collection) { Yt::Collections::Playlists.new }
6
- before { expect(collection).to behave }
7
-
8
- describe '#insert' do
9
- let(:playlist) { Yt::Playlist.new }
10
- # TODO: separate stubs to show options translate into do_insert params
11
- let(:behave) { receive(:do_insert).and_return playlist }
12
-
13
- it { expect(collection.insert).to eq playlist }
14
- end
15
-
16
- describe '#delete_all' do
17
- let(:behave) { receive(:do_delete_all).and_return [true] }
18
-
19
- it { expect(collection.delete_all).to eq [true] }
20
- end
21
-
22
- describe '#delete_all' do
23
- let(:behave) { receive(:do_delete_all).and_return [true] }
24
-
25
- it { expect(collection.delete_all).to eq [true] }
26
- end
27
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/policies'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::Policies do
6
- subject(:collection) { Yt::Collections::Policies.new parent: content_owner }
7
- let(:content_owner) { Yt::ContentOwner.new owner_name: 'any-name' }
8
- let(:page) { {items: [], token: 'any-token'} }
9
- let(:query) { {id: 'any-id'} }
10
-
11
- describe '#count' do
12
- context 'called once with .where(query) and once without' do
13
- after do
14
- collection.where(query).count
15
- collection.count
16
- end
17
-
18
- it 'only applies the query on the first call' do
19
- expect(collection).to receive(:fetch_page) do |options|
20
- expect(options[:params]).to include query
21
- page
22
- end
23
- expect(collection).to receive(:fetch_page) do |options|
24
- expect(options[:params]).not_to include query
25
- page
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/references'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::References do
6
- subject(:collection) { Yt::Collections::References.new parent: content_owner }
7
- let(:content_owner) { Yt::ContentOwner.new id: 'any-id' }
8
- let(:page) { {items: [], token: 'any-token'} }
9
- let(:query) { {id: 'reference-id'} }
10
-
11
- describe '#count' do
12
- context 'called once with .where(query) and once without' do
13
- after do
14
- collection.where(query).count
15
- collection.count
16
- end
17
-
18
- it 'only applies the query on the first call' do
19
- expect(collection).to receive(:fetch_page) do |options|
20
- expect(options[:params]).to include query
21
- page
22
- end
23
- expect(collection).to receive(:fetch_page) do |options|
24
- expect(options[:params]).not_to include query
25
- page
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/reports'
3
- require 'yt/models/content_owner'
4
-
5
- describe Yt::Collections::Reports do
6
- subject(:reports) { Yt::Collections::Reports.new(parent: content_owner).tap{|reports| reports.metrics = {views: Integer}} }
7
- let(:content_owner) { Yt::ContentOwner.new owner_name: 'any-name' }
8
- let(:error){ {reason: reason, message: message} }
9
- let(:msg) { {response_body: {error: {errors: [error]}}}.to_json }
10
-
11
- describe '#within' do
12
- let(:result) { reports.within Range.new(5.days.ago, 4.days.ago), nil, nil, :day, nil, nil }
13
- context 'given the request raises error 400 with "Invalid Query" message' do
14
- let(:reason) { 'badRequest' }
15
- let(:message) { 'Invalid query. Query did not conform to the expectations' }
16
- before { expect(reports).to receive(:list).once.and_raise Yt::Error, msg }
17
- let(:try_again) { expect(reports).to receive(:list).at_least(:once) }
18
-
19
- context 'every time' do
20
- before { try_again.and_raise Yt::Error, msg }
21
- it { expect{result}.to fail }
22
- end
23
-
24
- context 'but returns a success code 2XX the second time' do
25
- before { try_again.and_return [views: {total: 20}] }
26
- it { expect{result}.not_to fail }
27
- end
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/subscriptions'
3
-
4
- describe Yt::Collections::Subscriptions do
5
- subject(:collection) { Yt::Collections::Subscriptions.new }
6
- let(:msg) { {response_body: {error: {errors: [{reason: reason}]}}}.to_json }
7
- before { expect(collection).to behave }
8
-
9
- describe '#insert' do
10
- context 'given a new subscription' do
11
- let(:subscription) { Yt::Subscription.new }
12
- let(:behave) { receive(:do_insert).and_return subscription }
13
-
14
- it { expect(collection.insert).to eq subscription }
15
- end
16
-
17
- context 'given a duplicate subscription' do
18
- let(:reason) { 'subscriptionDuplicate' }
19
- let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }
20
-
21
- it { expect{collection.insert}.to fail.with 'subscriptionDuplicate' }
22
- it { expect{collection.insert ignore_errors: true}.not_to fail }
23
- end
24
- end
25
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/collections/videos'
3
- require 'yt/models/channel'
4
-
5
- describe Yt::Collections::Videos do
6
- subject(:collection) { Yt::Collections::Videos.new parent: channel }
7
- let(:channel) { Yt::Channel.new id: 'any-id' }
8
- let(:page) { {items: [], token: 'any-token'} }
9
-
10
- describe '#size', :ruby2 do
11
- describe 'sends only one request and return the total results' do
12
- let(:total_results) { 123456 }
13
- before do
14
- expect_any_instance_of(Yt::Request).to receive(:run).once do
15
- double(body: {'pageInfo'=>{'totalResults'=>total_results}})
16
- end
17
- end
18
- it { expect(collection.size).to be total_results }
19
- end
20
- end
21
-
22
- describe '#count' do
23
- let(:query) { {q: 'search string'} }
24
-
25
- context 'called once with .where(query) and once without' do
26
- after do
27
- collection.where(query).count
28
- collection.count
29
- end
30
-
31
- it 'only applies the query on the first call' do
32
- expect(collection).to receive(:fetch_page) do |options|
33
- expect(options[:params]).to include query
34
- page
35
- end
36
- expect(collection).to receive(:fetch_page) do |options|
37
- expect(options[:params]).not_to include query
38
- page
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/constants/geography'
3
-
4
- describe 'Yt::COUNTRIES' do
5
- it 'returns all country codes and names' do
6
- expect(Yt::COUNTRIES[:US]).to eq 'United States'
7
- expect(Yt::COUNTRIES['IT']).to eq 'Italy'
8
- end
9
- end
10
-
11
- describe 'Yt::US_STATES' do
12
- it 'returns all U.S. state codes and names' do
13
- expect(Yt::US_STATES[:CA]).to eq 'California'
14
- expect(Yt::US_STATES['CO']).to eq 'Colorado'
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/forbidden'
3
-
4
- describe Yt::Errors::Forbidden do
5
- let(:msg) { %r{^A request to YouTube API was considered forbidden by the server} }
6
-
7
- describe '#exception' do
8
- it { expect{raise Yt::Errors::Forbidden}.to raise_error msg }
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/missing_auth'
3
-
4
- describe Yt::Errors::MissingAuth do
5
- subject(:error) { raise Yt::Errors::MissingAuth, params }
6
- let(:params) { {} }
7
- let(:msg) { %r{^A request to YouTube API was sent without a valid authentication} }
8
-
9
- describe '#exception' do
10
- it { expect{error}.to raise_error msg }
11
-
12
- context 'given the user can authenticate via web' do
13
- let(:params) { {scopes: 'youtube', authentication_url: 'http://google.example.com/auth', redirect_uri: 'http://localhost/'} }
14
- let(:msg) { %r{^You can ask YouTube accounts to authenticate your app} }
15
- it { expect{error}.to raise_error msg }
16
- end
17
-
18
- context 'given the user can authenticate via device code' do
19
- let(:params) { {scopes: 'youtube', user_code: 'abcdefgh', verification_url: 'http://google.com/device'} }
20
- let(:msg) { %r{^Please authenticate your app by visiting the page} }
21
- it { expect{error}.to raise_error msg }
22
- end
23
- end
24
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/no_items'
3
-
4
- describe Yt::Errors::NoItems do
5
- let(:msg) { %r{^A request to YouTube API returned no items} }
6
-
7
- describe '#exception' do
8
- it { expect{raise Yt::Errors::NoItems}.to raise_error msg }
9
- end
10
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
- require 'yt/errors/request_error'
3
-
4
- describe Yt::Errors::RequestError do
5
- subject(:error) { raise Yt::Errors::RequestError, params }
6
- let(:params) { {} }
7
- let(:msg) { %r{^A request to YouTube API failed} }
8
-
9
- describe '#exception' do
10
- it { expect{error}.to raise_error msg }
11
-
12
- context 'given the exception includes sensitive data' do
13
- let(:body) { 'some secret token' }
14
- let(:curl) { 'curl -H "Authorization: secret-token"' }
15
- let(:params) { {response_body: body, request_curl: curl}.to_json }
16
-
17
- describe 'given a log level of :debug or :devel' do
18
- before(:all) { Yt.configuration.log_level = :debug }
19
- specify 'exposes sensitive data' do
20
- expect{error}.to raise_error do |error|
21
- expect(error.message).to include 'secret'
22
- end
23
- end
24
- end
25
-
26
- describe 'given a different log level' do
27
- before(:all) { Yt.configuration.log_level = :info }
28
- specify 'hides sensitive data' do
29
- expect{error}.to raise_error do |error|
30
- expect(error.message).not_to include 'secret'
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- describe Yt::Error do
39
- let(:msg) { %r{^A request to YouTube API failed} }
40
-
41
- describe '#exception' do
42
- it { expect{raise Yt::Error}.to raise_error msg }
43
- end
44
- end