yt-andrewroth 0.25.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. data/.gitignore +27 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +5 -0
  5. data/CHANGELOG.md +732 -0
  6. data/Gemfile +4 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +489 -0
  9. data/Rakefile +11 -0
  10. data/YOUTUBE_IT.md +835 -0
  11. data/bin/yt +30 -0
  12. data/gemfiles/Gemfile.activesupport-3.x +4 -0
  13. data/gemfiles/Gemfile.activesupport-4.x +4 -0
  14. data/lib/yt.rb +21 -0
  15. data/lib/yt/actions/base.rb +32 -0
  16. data/lib/yt/actions/delete.rb +19 -0
  17. data/lib/yt/actions/delete_all.rb +32 -0
  18. data/lib/yt/actions/insert.rb +42 -0
  19. data/lib/yt/actions/list.rb +139 -0
  20. data/lib/yt/actions/modify.rb +37 -0
  21. data/lib/yt/actions/patch.rb +19 -0
  22. data/lib/yt/actions/update.rb +19 -0
  23. data/lib/yt/associations/has_attribute.rb +55 -0
  24. data/lib/yt/associations/has_authentication.rb +214 -0
  25. data/lib/yt/associations/has_many.rb +22 -0
  26. data/lib/yt/associations/has_one.rb +22 -0
  27. data/lib/yt/associations/has_reports.rb +320 -0
  28. data/lib/yt/collections/advertising_options_sets.rb +34 -0
  29. data/lib/yt/collections/annotations.rb +62 -0
  30. data/lib/yt/collections/assets.rb +58 -0
  31. data/lib/yt/collections/authentications.rb +47 -0
  32. data/lib/yt/collections/base.rb +62 -0
  33. data/lib/yt/collections/channels.rb +31 -0
  34. data/lib/yt/collections/claim_histories.rb +34 -0
  35. data/lib/yt/collections/claims.rb +56 -0
  36. data/lib/yt/collections/content_details.rb +30 -0
  37. data/lib/yt/collections/content_owner_details.rb +34 -0
  38. data/lib/yt/collections/content_owners.rb +32 -0
  39. data/lib/yt/collections/device_flows.rb +23 -0
  40. data/lib/yt/collections/file_details.rb +30 -0
  41. data/lib/yt/collections/ids.rb +27 -0
  42. data/lib/yt/collections/live_streaming_details.rb +30 -0
  43. data/lib/yt/collections/ownerships.rb +34 -0
  44. data/lib/yt/collections/partnered_channels.rb +28 -0
  45. data/lib/yt/collections/players.rb +30 -0
  46. data/lib/yt/collections/playlist_items.rb +53 -0
  47. data/lib/yt/collections/playlists.rb +28 -0
  48. data/lib/yt/collections/policies.rb +28 -0
  49. data/lib/yt/collections/ratings.rb +23 -0
  50. data/lib/yt/collections/references.rb +46 -0
  51. data/lib/yt/collections/related_playlists.rb +43 -0
  52. data/lib/yt/collections/reports.rb +161 -0
  53. data/lib/yt/collections/resources.rb +57 -0
  54. data/lib/yt/collections/resumable_sessions.rb +51 -0
  55. data/lib/yt/collections/snippets.rb +27 -0
  56. data/lib/yt/collections/statistics_sets.rb +30 -0
  57. data/lib/yt/collections/statuses.rb +27 -0
  58. data/lib/yt/collections/subscribed_channels.rb +46 -0
  59. data/lib/yt/collections/subscribers.rb +33 -0
  60. data/lib/yt/collections/subscriptions.rb +50 -0
  61. data/lib/yt/collections/user_infos.rb +36 -0
  62. data/lib/yt/collections/video_categories.rb +35 -0
  63. data/lib/yt/collections/videos.rb +137 -0
  64. data/lib/yt/config.rb +54 -0
  65. data/lib/yt/errors/forbidden.rb +13 -0
  66. data/lib/yt/errors/missing_auth.rb +81 -0
  67. data/lib/yt/errors/no_items.rb +13 -0
  68. data/lib/yt/errors/request_error.rb +74 -0
  69. data/lib/yt/errors/server_error.rb +13 -0
  70. data/lib/yt/errors/unauthorized.rb +50 -0
  71. data/lib/yt/models/account.rb +216 -0
  72. data/lib/yt/models/advertising_options_set.rb +38 -0
  73. data/lib/yt/models/annotation.rb +132 -0
  74. data/lib/yt/models/asset.rb +111 -0
  75. data/lib/yt/models/asset_metadata.rb +38 -0
  76. data/lib/yt/models/asset_snippet.rb +46 -0
  77. data/lib/yt/models/authentication.rb +83 -0
  78. data/lib/yt/models/base.rb +32 -0
  79. data/lib/yt/models/channel.rb +302 -0
  80. data/lib/yt/models/claim.rb +156 -0
  81. data/lib/yt/models/claim_event.rb +67 -0
  82. data/lib/yt/models/claim_history.rb +29 -0
  83. data/lib/yt/models/configuration.rb +70 -0
  84. data/lib/yt/models/content_detail.rb +65 -0
  85. data/lib/yt/models/content_owner.rb +48 -0
  86. data/lib/yt/models/content_owner_detail.rb +18 -0
  87. data/lib/yt/models/description.rb +58 -0
  88. data/lib/yt/models/device_flow.rb +16 -0
  89. data/lib/yt/models/file_detail.rb +21 -0
  90. data/lib/yt/models/id.rb +9 -0
  91. data/lib/yt/models/iterator.rb +16 -0
  92. data/lib/yt/models/live_streaming_detail.rb +23 -0
  93. data/lib/yt/models/match_policy.rb +34 -0
  94. data/lib/yt/models/ownership.rb +75 -0
  95. data/lib/yt/models/player.rb +18 -0
  96. data/lib/yt/models/playlist.rb +218 -0
  97. data/lib/yt/models/playlist_item.rb +112 -0
  98. data/lib/yt/models/policy.rb +36 -0
  99. data/lib/yt/models/policy_rule.rb +124 -0
  100. data/lib/yt/models/rating.rb +37 -0
  101. data/lib/yt/models/reference.rb +172 -0
  102. data/lib/yt/models/resource.rb +136 -0
  103. data/lib/yt/models/resumable_session.rb +52 -0
  104. data/lib/yt/models/right_owner.rb +58 -0
  105. data/lib/yt/models/snippet.rb +50 -0
  106. data/lib/yt/models/statistics_set.rb +26 -0
  107. data/lib/yt/models/status.rb +32 -0
  108. data/lib/yt/models/subscription.rb +38 -0
  109. data/lib/yt/models/timestamp.rb +13 -0
  110. data/lib/yt/models/url.rb +90 -0
  111. data/lib/yt/models/user_info.rb +26 -0
  112. data/lib/yt/models/video.rb +630 -0
  113. data/lib/yt/models/video_category.rb +12 -0
  114. data/lib/yt/request.rb +278 -0
  115. data/lib/yt/version.rb +3 -0
  116. data/spec/collections/claims_spec.rb +30 -0
  117. data/spec/collections/playlist_items_spec.rb +44 -0
  118. data/spec/collections/playlists_spec.rb +27 -0
  119. data/spec/collections/policies_spec.rb +30 -0
  120. data/spec/collections/references_spec.rb +30 -0
  121. data/spec/collections/reports_spec.rb +30 -0
  122. data/spec/collections/subscriptions_spec.rb +25 -0
  123. data/spec/collections/videos_spec.rb +43 -0
  124. data/spec/errors/forbidden_spec.rb +10 -0
  125. data/spec/errors/missing_auth_spec.rb +24 -0
  126. data/spec/errors/no_items_spec.rb +10 -0
  127. data/spec/errors/request_error_spec.rb +44 -0
  128. data/spec/errors/server_error_spec.rb +10 -0
  129. data/spec/errors/unauthorized_spec.rb +10 -0
  130. data/spec/models/account_spec.rb +138 -0
  131. data/spec/models/annotation_spec.rb +180 -0
  132. data/spec/models/asset_spec.rb +20 -0
  133. data/spec/models/channel_spec.rb +127 -0
  134. data/spec/models/claim_event_spec.rb +62 -0
  135. data/spec/models/claim_history_spec.rb +27 -0
  136. data/spec/models/claim_spec.rb +211 -0
  137. data/spec/models/configuration_spec.rb +44 -0
  138. data/spec/models/content_detail_spec.rb +45 -0
  139. data/spec/models/content_owner_detail_spec.rb +6 -0
  140. data/spec/models/description_spec.rb +94 -0
  141. data/spec/models/file_detail_spec.rb +13 -0
  142. data/spec/models/live_streaming_detail_spec.rb +6 -0
  143. data/spec/models/ownership_spec.rb +59 -0
  144. data/spec/models/player_spec.rb +13 -0
  145. data/spec/models/playlist_item_spec.rb +120 -0
  146. data/spec/models/playlist_spec.rb +138 -0
  147. data/spec/models/policy_rule_spec.rb +63 -0
  148. data/spec/models/policy_spec.rb +41 -0
  149. data/spec/models/rating_spec.rb +12 -0
  150. data/spec/models/reference_spec.rb +249 -0
  151. data/spec/models/request_spec.rb +163 -0
  152. data/spec/models/resource_spec.rb +57 -0
  153. data/spec/models/right_owner_spec.rb +71 -0
  154. data/spec/models/snippet_spec.rb +13 -0
  155. data/spec/models/statistics_set_spec.rb +13 -0
  156. data/spec/models/status_spec.rb +13 -0
  157. data/spec/models/subscription_spec.rb +30 -0
  158. data/spec/models/url_spec.rb +78 -0
  159. data/spec/models/video_category_spec.rb +21 -0
  160. data/spec/models/video_spec.rb +669 -0
  161. data/spec/requests/as_account/account_spec.rb +125 -0
  162. data/spec/requests/as_account/authentications_spec.rb +139 -0
  163. data/spec/requests/as_account/channel_spec.rb +259 -0
  164. data/spec/requests/as_account/channels_spec.rb +18 -0
  165. data/spec/requests/as_account/playlist_item_spec.rb +56 -0
  166. data/spec/requests/as_account/playlist_spec.rb +244 -0
  167. data/spec/requests/as_account/resource_spec.rb +18 -0
  168. data/spec/requests/as_account/thumbnail.jpg +0 -0
  169. data/spec/requests/as_account/video.mp4 +0 -0
  170. data/spec/requests/as_account/video_spec.rb +408 -0
  171. data/spec/requests/as_content_owner/account_spec.rb +25 -0
  172. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +15 -0
  173. data/spec/requests/as_content_owner/asset_spec.rb +20 -0
  174. data/spec/requests/as_content_owner/channel_spec.rb +1934 -0
  175. data/spec/requests/as_content_owner/claim_history_spec.rb +20 -0
  176. data/spec/requests/as_content_owner/content_owner_spec.rb +241 -0
  177. data/spec/requests/as_content_owner/match_policy_spec.rb +17 -0
  178. data/spec/requests/as_content_owner/ownership_spec.rb +25 -0
  179. data/spec/requests/as_content_owner/playlist_spec.rb +782 -0
  180. data/spec/requests/as_content_owner/video_spec.rb +1239 -0
  181. data/spec/requests/as_server_app/channel_spec.rb +74 -0
  182. data/spec/requests/as_server_app/playlist_item_spec.rb +30 -0
  183. data/spec/requests/as_server_app/playlist_spec.rb +53 -0
  184. data/spec/requests/as_server_app/video_spec.rb +58 -0
  185. data/spec/requests/as_server_app/videos_spec.rb +40 -0
  186. data/spec/requests/unauthenticated/video_spec.rb +22 -0
  187. data/spec/spec_helper.rb +20 -0
  188. data/spec/support/fail_matcher.rb +15 -0
  189. data/spec/support/global_hooks.rb +48 -0
  190. data/yt.gemspec +32 -0
  191. metadata +416 -0
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yt::Configuration do
4
+ subject(:config) { Yt::Configuration.new }
5
+
6
+ describe '#client_id' do
7
+ context 'without an environment variable YT_CLIENT_ID' do
8
+ before { ENV['YT_CLIENT_ID'] = nil }
9
+ it {expect(config.client_id).to be_nil }
10
+ end
11
+
12
+ context 'given an environment variable YT_CLIENT_ID' do
13
+ let(:client_id) { '1234567890.apps.googleusercontent.com' }
14
+ before { ENV['YT_CLIENT_ID'] = client_id}
15
+ it {expect(config.client_id).to eq client_id }
16
+ end
17
+ end
18
+
19
+ describe '#client_secret' do
20
+ context 'without an environment variable YT_CLIENT_SECRET' do
21
+ before { ENV['YT_CLIENT_SECRET'] = nil }
22
+ it {expect(config.client_secret).to be_nil }
23
+ end
24
+
25
+ context 'given an environment variable YT_CLIENT_SECRET' do
26
+ let(:client_secret) { '1234567890' }
27
+ before { ENV['YT_CLIENT_SECRET'] = client_secret}
28
+ it {expect(config.client_secret).to eq client_secret }
29
+ end
30
+ end
31
+
32
+ describe '#api_key' do
33
+ context 'without an environment variable YT_API_KEY' do
34
+ before { ENV['YT_API_KEY'] = nil }
35
+ it {expect(config.api_key).to be_nil }
36
+ end
37
+
38
+ context 'given an environment variable YT_API_KEY' do
39
+ let(:api_key) { '123456789012345678901234567890' }
40
+ before { ENV['YT_API_KEY'] = api_key}
41
+ it {expect(config.api_key).to eq api_key }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/content_detail'
3
+
4
+ describe Yt::ContentDetail do
5
+ subject(:content_detail) { Yt::ContentDetail.new data: data }
6
+
7
+ describe '#data' do
8
+ let(:data) { {"key"=>"value"} }
9
+ specify 'returns the data the content detail was initialized with' do
10
+ expect(content_detail.data).to eq data
11
+ end
12
+ end
13
+
14
+ describe '#duration' do
15
+ context 'given a content_detail with duration in weeks, days, hours, minutes' do
16
+ let(:data) { {"duration"=>"P1W2DT6H21M32S"}}
17
+ it { expect(content_detail.duration).to eq 800492 }
18
+ end
19
+
20
+ context 'given a content_detail with duration in days' do
21
+ let(:data) { {"duration"=>"P1D"}}
22
+ it { expect(content_detail.duration).to eq 86400 }
23
+ end
24
+
25
+ context 'given a content_detail with duration in hours, minutes, seconds' do
26
+ let(:data) { {"duration"=>"PT1H18M52S"} }
27
+ it { expect(content_detail.duration).to eq 4732 }
28
+ end
29
+
30
+ context 'given a content_detail with duration in minutes and seconds' do
31
+ let(:data) { {"duration"=>"PT2M51S"} }
32
+ it { expect(content_detail.duration).to eq 171 }
33
+ end
34
+
35
+ context 'given a content_detail with duration in minutes' do
36
+ let(:data) { {"duration"=>"PT2M"} }
37
+ it { expect(content_detail.duration).to eq 120 }
38
+ end
39
+
40
+ context 'given a content_detail with duration in seconds' do
41
+ let(:data) { {"duration"=>"PT51S"} }
42
+ it { expect(content_detail.duration).to eq 51 }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/content_owner_detail'
3
+
4
+ describe Yt::ContentOwnerDetail do
5
+ subject(:content_owner_detail) { Yt::ContentOwnerDetail.new data: data }
6
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/description'
3
+
4
+ describe Yt::Description do
5
+ subject(:description) { Yt::Description.new text }
6
+
7
+ describe '#text' do
8
+ let(:text) { 'this is a description' }
9
+ it { expect(description).to eq 'this is a description' }
10
+ end
11
+
12
+ describe '#length' do
13
+ let(:text) { 'twenty one characters' }
14
+ it { expect(description.length).to eq 21 }
15
+ end
16
+
17
+ describe '#has_link_to_video?' do
18
+ context 'without a video URL' do
19
+ let(:text) { 'Link to channel: youtube.com/fullscreen' }
20
+ it { expect(description).not_to have_link_to_video }
21
+ end
22
+
23
+ context 'with a video long URL' do
24
+ let(:text) { 'example.com and Link to video: youtube.com/watch?v=MESycYJytkU' }
25
+ it { expect(description).to have_link_to_video }
26
+ end
27
+
28
+ context 'with a video short URL' do
29
+ let(:text) { 'Link to video: youtu.be/MESycYJytkU' }
30
+ it { expect(description).to have_link_to_video }
31
+ end
32
+
33
+ context 'with a playlist-embedded video URL' do
34
+ let(:text) { 'Link to video in playlist: youtube.com/watch?v=MESycYJytkU&index=619&list=LLxO1tY8h1AhOz0T4ENwmpow' }
35
+ it { expect(description).to have_link_to_video }
36
+ end
37
+ end
38
+
39
+ describe '#has_link_to_channel?' do
40
+ context 'without a channel URL' do
41
+ let(:text) { 'youtu.be/MESycYJytkU is a video link' }
42
+ it { expect(description).not_to have_link_to_channel }
43
+ end
44
+
45
+ context 'with a channel long URL' do
46
+ let(:text) { 'Link to channel: youtube.com/channel/UCxO1tY8h1AhOz0T4ENwmpow' }
47
+ it { expect(description).to have_link_to_channel }
48
+ end
49
+
50
+ context 'with a channel short URL' do
51
+ let(:text) { 'Link to channel: youtube.com/fullscreen' }
52
+ it { expect(description).to have_link_to_channel }
53
+ end
54
+
55
+ context 'with a channel user URL' do
56
+ let(:text) { 'Link to channel: youtube.com/user/fullscreen' }
57
+ it { expect(description).to have_link_to_channel }
58
+ end
59
+ end
60
+
61
+ describe '#has_link_to_subscribe?' do
62
+ context 'without a subscribe URL' do
63
+ let(:text) { 'Link to video: youtu.be/MESycYJytkU' }
64
+ it { expect(description).not_to have_link_to_subscribe }
65
+ end
66
+
67
+ context 'with a subscribe center URL' do
68
+ let(:text) { 'Link to subscribe: youtube.com/subscription_center?add_user=fullscreen' }
69
+ it { expect(description).to have_link_to_subscribe }
70
+ end
71
+
72
+ context 'with a subscribe short URL' do
73
+ let(:text) { 'Link to subscribe: youtube.com/subscribe_widget?p=fullscreen' }
74
+ it { expect(description).to have_link_to_subscribe }
75
+ end
76
+
77
+ context 'with a subscribe confirm URL' do
78
+ let(:text) { 'Link to subscribe: youtube.com/channel/UCxO1tY8h1AhOz0T4ENwmpow?sub_confirmation=1' }
79
+ it { expect(description).to have_link_to_subscribe }
80
+ end
81
+ end
82
+
83
+ describe '#has_link_to_playlist?' do
84
+ context 'without a playlist URL' do
85
+ let(:text) { 'Link to video: youtu.be/MESycYJytkU' }
86
+ it { expect(description).not_to have_link_to_playlist }
87
+ end
88
+
89
+ context 'with a playlist long URL' do
90
+ let(:text) { 'Link to playlist: youtube.com/playlist?list=LLxO1tY8h1AhOz0T4ENwmpow' }
91
+ it { expect(description).to have_link_to_playlist }
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/file_detail'
3
+
4
+ describe Yt::FileDetail do
5
+ subject(:file_detail) { Yt::FileDetail.new data: data }
6
+
7
+ describe '#data' do
8
+ let(:data) { {"key"=>"value"} }
9
+ specify 'returns the data the file detail was initialized with' do
10
+ expect(file_detail.data).to eq data
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/live_streaming_detail'
3
+
4
+ describe Yt::LiveStreamingDetail do
5
+ subject(:live_streaming_detail) { Yt::LiveStreamingDetail.new data: data }
6
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/ownership'
3
+
4
+ describe Yt::Ownership do
5
+ subject(:ownership) { Yt::Ownership.new data: data }
6
+ let(:data) { {} }
7
+
8
+ describe '#general_owners' do
9
+ context 'given fetching an ownership returns a general owner' do
10
+ let(:general) { '{"ratio":100.0,"owner":"FullScreen","type":"exclude"}' }
11
+ let(:data) { {"general"=>[general]} }
12
+ it { expect(ownership.general_owners.size).to be 1 }
13
+ it { expect(ownership.general_owners.first).to be_a Yt::RightOwner }
14
+ end
15
+
16
+ context 'given fetching an ownership does not return general owners' do
17
+ it { expect(ownership.general_owners).to be_empty }
18
+ end
19
+ end
20
+
21
+ describe '#performance_owners' do
22
+ context 'given fetching an ownership returns a performance owner' do
23
+ let(:performance) { '{"ratio":100.0,"owner":"FullScreen","type":"exclude"}' }
24
+ let(:data) { {"performance"=>[performance]} }
25
+ it { expect(ownership.performance_owners.size).to be 1 }
26
+ it { expect(ownership.performance_owners.first).to be_a Yt::RightOwner }
27
+ end
28
+
29
+ context 'given fetching an ownership does not return performance owners' do
30
+ it { expect(ownership.performance_owners).to be_empty }
31
+ end
32
+ end
33
+
34
+ describe '#synchronization_owners' do
35
+ context 'given fetching an ownership returns a synchronization owner' do
36
+ let(:synchronization) { '{"ratio":100.0,"owner":"FullScreen","type":"exclude"}' }
37
+ let(:data) { {"synchronization"=>[synchronization]} }
38
+ it { expect(ownership.synchronization_owners.size).to be 1 }
39
+ it { expect(ownership.synchronization_owners.first).to be_a Yt::RightOwner }
40
+ end
41
+
42
+ context 'given fetching an ownership does not return synchronization owners' do
43
+ it { expect(ownership.synchronization_owners).to be_empty }
44
+ end
45
+ end
46
+
47
+ describe '#mechanical_owners' do
48
+ context 'given fetching an ownership returns a mechanical owner' do
49
+ let(:mechanical) { '{"ratio":100.0,"owner":"FullScreen","type":"exclude"}' }
50
+ let(:data) { {"mechanical"=>[mechanical]} }
51
+ it { expect(ownership.mechanical_owners.size).to be 1 }
52
+ it { expect(ownership.mechanical_owners.first).to be_a Yt::RightOwner }
53
+ end
54
+
55
+ context 'given fetching an ownership does not return mechanical owners' do
56
+ it { expect(ownership.mechanical_owners).to be_empty }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/player'
3
+
4
+ describe Yt::Player do
5
+ subject(:player) { Yt::Player.new data: data }
6
+
7
+ describe '#data' do
8
+ let(:data) { {"key"=>"value"} }
9
+ specify 'returns the data the player was initialized with' do
10
+ expect(player.data).to eq data
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/playlist_item'
3
+
4
+ describe Yt::PlaylistItem do
5
+ subject(:item) { Yt::PlaylistItem.new attrs }
6
+
7
+ describe '#title' do
8
+ context 'given a snippet with a title' do
9
+ let(:attrs) { {snippet: {"title"=>"Fullscreen"}} }
10
+ it { expect(item.title).to eq 'Fullscreen' }
11
+ end
12
+
13
+ context 'given a snippet without a title' do
14
+ let(:attrs) { {snippet: {}} }
15
+ it { expect(item.title).to eq '' }
16
+ end
17
+ end
18
+
19
+ describe '#published_at' do
20
+ context 'given a snippet with a timestamp' do
21
+ let(:attrs) { {snippet: {"publishedAt"=>"2014-04-22T19:14:49.000Z"}} }
22
+ it { expect(item.published_at.year).to be 2014 }
23
+ end
24
+ end
25
+
26
+ describe '#description' do
27
+ context 'given a snippet with a description' do
28
+ let(:attrs) { {snippet: {"description"=>"A video."}} }
29
+ it { expect(item.description).to eq 'A video.' }
30
+ end
31
+
32
+ context 'given a snippet without a description' do
33
+ let(:attrs) { {snippet: {}} }
34
+ it { expect(item.description).to eq '' }
35
+ end
36
+ end
37
+
38
+ describe '#thumbnail_url' do
39
+ context 'given a snippet with thumbnails' do
40
+ let(:attrs) { {snippet: {"thumbnails"=>{
41
+ "default"=>{"url"=> "http://example.com/120x90.jpg"},
42
+ "medium"=>{"url"=> "http://example.com/320x180.jpg"},
43
+ }}} }
44
+ it { expect(item.thumbnail_url).to eq 'http://example.com/120x90.jpg' }
45
+ it { expect(item.thumbnail_url 'default').to eq 'http://example.com/120x90.jpg' }
46
+ it { expect(item.thumbnail_url :default).to eq 'http://example.com/120x90.jpg' }
47
+ it { expect(item.thumbnail_url :medium).to eq 'http://example.com/320x180.jpg' }
48
+ it { expect(item.thumbnail_url :large).to be_nil }
49
+ end
50
+
51
+ context 'given a snippet without thumbnails' do
52
+ let(:attrs) { {snippet: {}} }
53
+ it { expect(item.thumbnail_url).to be_nil }
54
+ end
55
+ end
56
+
57
+ describe '#channel_id' do
58
+ context 'given a snippet with a channel ID' do
59
+ let(:attrs) { {snippet: {"channelId"=>"UCxO1tY8h1AhOz0T4ENwmpow"}} }
60
+ it { expect(item.channel_id).to eq 'UCxO1tY8h1AhOz0T4ENwmpow' }
61
+ end
62
+
63
+ context 'given a snippet without a channel ID' do
64
+ let(:attrs) { {snippet: {}} }
65
+ it { expect(item.channel_id).to be_nil }
66
+ end
67
+ end
68
+
69
+ describe '#channel_title' do
70
+ context 'given a snippet with a channel title' do
71
+ let(:attrs) { {snippet: {"channelTitle"=>"Fullscreen"}} }
72
+ it { expect(item.channel_title).to eq 'Fullscreen' }
73
+ end
74
+
75
+ context 'given a snippet without a channel title' do
76
+ let(:attrs) { {snippet: {}} }
77
+ it { expect(item.channel_title).to be_nil }
78
+ end
79
+ end
80
+
81
+ describe '#video_id and #video' do
82
+ context 'given a snippet with a video resource' do
83
+ let(:attrs) { {snippet: {"resourceId"=>{"kind"=>"youtube#video","videoId"=>"W4GhTprSsOY"}}} }
84
+ it { expect(item.video_id).to eq 'W4GhTprSsOY' }
85
+ it { expect(item.video).to be_a Yt::Models::Video }
86
+ it { expect(item.video.id).to eq 'W4GhTprSsOY' }
87
+ end
88
+
89
+ context 'given a snippet without a video resource' do
90
+ let(:attrs) { {snippet: {}} }
91
+ it { expect(item.video_id).to be_nil }
92
+ it { expect(item.video).to be_nil }
93
+ end
94
+ end
95
+
96
+ describe '#snippet' do
97
+ context 'given fetching a playlist item returns a snippet' do
98
+ let(:attrs) { {snippet: {"position"=>0}} }
99
+ it { expect(item.snippet).to be_a Yt::Snippet }
100
+ end
101
+ end
102
+
103
+ describe '#status' do
104
+ context 'given fetching a playlist item returns a status' do
105
+ let(:attrs) { {status: {"privacyStatus"=>"public"}} }
106
+ it { expect(item.status).to be_a Yt::Status }
107
+ end
108
+ end
109
+
110
+ describe '#delete' do
111
+ let(:attrs) { {id: 'playlist-item-id'} }
112
+
113
+ context 'given an existing playlist item' do
114
+ before { expect(item).to receive(:do_delete).and_yield }
115
+
116
+ it { expect(item.delete).to be true }
117
+ it { expect{item.delete}.to change{item.exists?} }
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/playlist'
3
+
4
+ describe Yt::Playlist do
5
+ subject(:playlist) { Yt::Playlist.new attrs }
6
+
7
+
8
+ describe '#title' do
9
+ context 'given a snippet with a title' do
10
+ let(:attrs) { {snippet: {"title"=>"Fullscreen"}} }
11
+ it { expect(playlist.title).to eq 'Fullscreen' }
12
+ end
13
+
14
+ context 'given a snippet without a title' do
15
+ let(:attrs) { {snippet: {}} }
16
+ it { expect(playlist.title).to eq '' }
17
+ end
18
+ end
19
+
20
+ describe '#published_at' do
21
+ context 'given a snippet with a timestamp' do # always returned by YouTube
22
+ let(:attrs) { {snippet: {"publishedAt"=>"2014-04-22T19:14:49.000Z"}} }
23
+ it { expect(playlist.published_at.year).to be 2014 }
24
+ end
25
+ end
26
+
27
+ describe '#description' do
28
+ context 'given a snippet with a description' do
29
+ let(:attrs) { {snippet: {"description"=>"The first media company for the connected generation."}} }
30
+ it { expect(playlist.description).to eq 'The first media company for the connected generation.' }
31
+ end
32
+
33
+ context 'given a snippet without a description' do
34
+ let(:attrs) { {snippet: {}} }
35
+ it { expect(playlist.description).to eq '' }
36
+ end
37
+ end
38
+
39
+ describe '#tags' do
40
+ context 'given a snippet with tags' do
41
+ let(:attrs) { {snippet: {"tags"=>["promotion", "new media"]}} }
42
+ it { expect(playlist.tags).to eq ["promotion", "new media"] }
43
+ end
44
+
45
+ context 'given a snippet without tags' do
46
+ let(:attrs) { {snippet: {}} }
47
+ it { expect(playlist.tags).to eq [] }
48
+ end
49
+ end
50
+
51
+ describe '#thumbnail_url' do
52
+ context 'given a snippet with thumbnails' do
53
+ let(:attrs) { {snippet: {"thumbnails"=>{
54
+ "default"=>{"url"=> "http://example.com/88x88.jpg"},
55
+ "medium"=>{"url"=> "http://example.com/240x240.jpg"},
56
+ }}} }
57
+ it { expect(playlist.thumbnail_url).to eq 'http://example.com/88x88.jpg' }
58
+ it { expect(playlist.thumbnail_url 'default').to eq 'http://example.com/88x88.jpg' }
59
+ it { expect(playlist.thumbnail_url :default).to eq 'http://example.com/88x88.jpg' }
60
+ it { expect(playlist.thumbnail_url :medium).to eq 'http://example.com/240x240.jpg' }
61
+ it { expect(playlist.thumbnail_url :large).to be_nil }
62
+ end
63
+
64
+ context 'given a snippet without thumbnails' do
65
+ let(:attrs) { {snippet: {}} }
66
+ it { expect(playlist.thumbnail_url).to be_nil }
67
+ end
68
+ end
69
+
70
+ describe '#channel_id' do
71
+ context 'given a snippet with a channel ID' do
72
+ let(:attrs) { {snippet: {"channelId"=>"UCxO1tY8h1AhOz0T4ENwmpow"}} }
73
+ it { expect(playlist.channel_id).to eq 'UCxO1tY8h1AhOz0T4ENwmpow' }
74
+ end
75
+
76
+ context 'given a snippet without a channel ID' do
77
+ let(:attrs) { {snippet: {}} }
78
+ it { expect(playlist.channel_id).to be_nil }
79
+ end
80
+ end
81
+
82
+ describe '#channel_title' do
83
+ context 'given a snippet with a channel title' do
84
+ let(:attrs) { {snippet: {"channelTitle"=>"Fullscreen"}} }
85
+ it { expect(playlist.channel_title).to eq 'Fullscreen' }
86
+ end
87
+
88
+ context 'given a snippet without a channel title' do
89
+ let(:attrs) { {snippet: {}} }
90
+ it { expect(playlist.channel_title).to be_nil }
91
+ end
92
+ end
93
+
94
+ describe '#exists?' do
95
+ context 'given a playlist with an id' do
96
+ let(:attrs) { {id: 'PLSWYkYzOr'} }
97
+ it { expect(playlist).to exist }
98
+ end
99
+
100
+ context 'given a playlist without an id' do
101
+ let(:attrs) { {} }
102
+ it { expect(playlist).not_to exist }
103
+ end
104
+ end
105
+
106
+ describe '#snippet' do
107
+ context 'given fetching a playlist returns a snippet' do
108
+ let(:attrs) { {snippet: {"title"=>"Fullscreen"}} }
109
+ it { expect(playlist.snippet).to be_a Yt::Snippet }
110
+ end
111
+ end
112
+
113
+ describe '#status' do
114
+ context 'given fetching a playlist returns a status' do
115
+ let(:attrs) { {status: {"privacyStatus"=>"public"}} }
116
+ it { expect(playlist.status).to be_a Yt::Status }
117
+ end
118
+ end
119
+
120
+ describe '#update' do
121
+ let(:attrs) { {id: 'PLSWYkYzOr', snippet: {'title'=>'old'}, status: {"privacyStatus"=>"public"}} }
122
+ before { expect(playlist).to receive(:do_update).and_yield 'snippet'=>{'title'=>'new'} }
123
+
124
+ it { expect(playlist.update title: 'new').to be true }
125
+ it { expect{playlist.update title: 'new'}.to change{playlist.title} }
126
+ end
127
+
128
+ describe '#delete' do
129
+ let(:attrs) { {id: 'PLSWYkYzOr'} }
130
+
131
+ context 'given an existing playlist' do
132
+ before { expect(playlist).to receive(:do_delete).and_yield }
133
+
134
+ it { expect(playlist.delete).to be true }
135
+ it { expect{playlist.delete}.to change{playlist.exists?} }
136
+ end
137
+ end
138
+ end