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,63 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/policy_rule'
3
+
4
+ describe Yt::PolicyRule do
5
+ subject(:policy_rule) { Yt::PolicyRule.new data: data }
6
+
7
+ describe '#action' do
8
+ context 'given fetching a policy rule returns an action' do
9
+ let(:data) { {"action"=>"takedown"} }
10
+ it { expect(policy_rule.action).to eq 'takedown' }
11
+ end
12
+ end
13
+
14
+ describe '#subaction' do
15
+ context 'given fetching a policy rule returns a subaction' do
16
+ let(:data) { {"subaction"=>"review"} }
17
+ it { expect(policy_rule.subaction).to eq 'review' }
18
+ end
19
+ end
20
+
21
+ describe '#included_territories' do
22
+ context 'given fetching a policy rule returns included territories' do
23
+ let(:data) { {"conditions"=>{"requiredTerritories"=>{"type"=>"include", "territories"=>["US", "CA"]}}} }
24
+ let(:data) { {"conditions"=>{"requiredTerritories"=>{"type"=>"include", "territories"=>["US", "CA"]}}} }
25
+ it { expect(policy_rule.included_territories).to eq %w(US CA) }
26
+ end
27
+ end
28
+
29
+ describe '#excluded_territories' do
30
+ context 'given fetching a policy rule returns excluded territories' do
31
+ let(:data) { {"conditions"=>{"requiredTerritories"=>{"type"=>"exclude", "territories"=>["US", "CA"]}}} }
32
+ it { expect(policy_rule.excluded_territories).to eq %w(US CA) }
33
+ end
34
+ end
35
+
36
+ describe '#match_duration' do
37
+ context 'given fetching a policy rule returns a match duration list' do
38
+ let(:data) { {"conditions"=>{"matchDuration"=>[{"high"=>60.0}]}} }
39
+ it { expect(policy_rule.match_duration).to match_array [{low: nil, high: 60.0}] }
40
+ end
41
+ end
42
+
43
+ describe '#match_percent' do
44
+ context 'given fetching a policy rule returns a match percent list' do
45
+ let(:data) { {"conditions"=>{"matchPercent"=>[{"high"=>60.0}]}} }
46
+ it { expect(policy_rule.match_percent).to match_array [{low: nil, high: 60.0}] }
47
+ end
48
+ end
49
+
50
+ describe '#reference_duration' do
51
+ context 'given fetching a policy rule returns a reference duration list' do
52
+ let(:data) { {"conditions"=>{"referenceDuration"=>[{"low"=>60.0, "high"=>600.0}, {"low"=>20.0, "high"=>30.0}]}} }
53
+ it { expect(policy_rule.reference_duration).to match_array [{low: 60.0, high: 600.0}, {low: 20.0, high: 30.0}] }
54
+ end
55
+ end
56
+
57
+ describe '#reference_percent' do
58
+ context 'given fetching a policy rule returns a reference percent list' do
59
+ let(:data) { {"conditions"=>{"referencePercent"=>[{"low"=>60.0, "high"=>600.0}, {"low"=>20.0, "high"=>30.0}]}} }
60
+ it { expect(policy_rule.reference_percent).to match_array [{low: 60.0, high: 600.0}, {low: 20.0, high: 30.0}] }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/policy'
3
+
4
+ describe Yt::Policy do
5
+ subject(:policy) { Yt::Policy.new data: data }
6
+
7
+ describe '#id' do
8
+ context 'given fetching a policy returns an id' do
9
+ let(:data) { {"id"=>"S123456789"} }
10
+ it { expect(policy.id).to eq 'S123456789' }
11
+ end
12
+ end
13
+
14
+ describe '#name' do
15
+ context 'given fetching a policy returns a name' do
16
+ let(:data) { {"name"=>"Block in all countries"} }
17
+ it { expect(policy.name).to eq 'Block in all countries' }
18
+ end
19
+ end
20
+
21
+ describe '#description' do
22
+ context 'given fetching a policy returns a description' do
23
+ let(:data) { {"description"=>"Block videos in every country"} }
24
+ it { expect(policy.description).to eq 'Block videos in every country' }
25
+ end
26
+ end
27
+
28
+ describe '#updated_at' do
29
+ context 'given fetching a policy returns a timeUpdated' do
30
+ let(:data) { {"timeUpdated"=>"1970-01-16T20:33:03.675Z"} }
31
+ it { expect(policy.updated_at.year).to be 1970 }
32
+ end
33
+ end
34
+
35
+ describe '#rules' do
36
+ context 'given fetching a policy returns rules' do
37
+ let(:data) { {"rules"=>[{"action"=>"track"},{"action"=>"track"}]} }
38
+ it { expect(policy.rules.size).to be 2 }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/rating'
3
+
4
+ describe Yt::Rating do
5
+ subject(:rating) { Yt::Rating.new }
6
+
7
+ describe '#update' do
8
+ before { expect(rating).to receive(:do_update).and_yield }
9
+
10
+ it { expect{rating.set :like}.to change{rating.rating} }
11
+ end
12
+ end
@@ -0,0 +1,249 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/reference'
3
+
4
+ describe Yt::Reference do
5
+ subject(:reference) { Yt::Reference.new data: data }
6
+
7
+ describe '#id' do
8
+ context 'given fetching a reference returns an id' do
9
+ let(:data) { {"id"=>"aBcD1EfGHIk"} }
10
+ it { expect(reference.id).to eq 'aBcD1EfGHIk' }
11
+ end
12
+ end
13
+
14
+ describe '#asset_id' do
15
+ context 'given fetching a reference returns an assetId' do
16
+ let(:data) { {"assetId"=>"A123456789012601"} }
17
+ it { expect(reference.asset_id).to eq 'A123456789012601' }
18
+ end
19
+ end
20
+
21
+ describe '#status' do
22
+ context 'given fetching a reference returns a status' do
23
+ let(:data) { {"status"=>"active"} }
24
+ it { expect(reference.status).to eq 'active' }
25
+ end
26
+ end
27
+
28
+ describe '#activating?' do
29
+ context 'given fetching a reference returns an activating status' do
30
+ let(:data) { {"status"=>"activating"} }
31
+ it { expect(reference).to be_activating }
32
+ end
33
+
34
+ context 'given fetching a reference does not return an activating status' do
35
+ let(:data) { {"status"=>"unknown"} }
36
+ it { expect(reference).not_to be_activating }
37
+ end
38
+ end
39
+
40
+ describe '#active?' do
41
+ context 'given fetching a reference returns an active status' do
42
+ let(:data) { {"status"=>"active"} }
43
+ it { expect(reference).to be_active }
44
+ end
45
+
46
+ context 'given fetching a reference does not return an active status' do
47
+ let(:data) { {"status"=>"unknown"} }
48
+ it { expect(reference).not_to be_active }
49
+ end
50
+ end
51
+
52
+ describe '#checking?' do
53
+ context 'given fetching a reference returns an checking status' do
54
+ let(:data) { {"status"=>"checking"} }
55
+ it { expect(reference).to be_checking }
56
+ end
57
+
58
+ context 'given fetching a reference does not return an checking status' do
59
+ let(:data) { {"status"=>"unknown"} }
60
+ it { expect(reference).not_to be_checking }
61
+ end
62
+ end
63
+
64
+ describe '#computing_fingerprint?' do
65
+ context 'given fetching a reference returns an computing_fingerprint status' do
66
+ let(:data) { {"status"=>"computing_fingerprint"} }
67
+ it { expect(reference).to be_computing_fingerprint }
68
+ end
69
+
70
+ context 'given fetching a reference does not return an computing_fingerprint status' do
71
+ let(:data) { {"status"=>"unknown"} }
72
+ it { expect(reference).not_to be_computing_fingerprint }
73
+ end
74
+ end
75
+
76
+ describe '#deleted?' do
77
+ context 'given fetching a reference returns an deleted status' do
78
+ let(:data) { {"status"=>"deleted"} }
79
+ it { expect(reference).to be_deleted }
80
+ end
81
+
82
+ context 'given fetching a reference does not return an deleted status' do
83
+ let(:data) { {"status"=>"unknown"} }
84
+ it { expect(reference).not_to be_deleted }
85
+ end
86
+ end
87
+
88
+ describe '#duplicate_on_hold?' do
89
+ context 'given fetching a reference returns an duplicate_on_hold status' do
90
+ let(:data) { {"status"=>"duplicate_on_hold"} }
91
+ it { expect(reference).to be_duplicate_on_hold }
92
+ end
93
+
94
+ context 'given fetching a reference does not return an duplicate_on_hold status' do
95
+ let(:data) { {"status"=>"unknown"} }
96
+ it { expect(reference).not_to be_duplicate_on_hold }
97
+ end
98
+ end
99
+
100
+ describe '#inactive?' do
101
+ context 'given fetching a reference returns an inactive status' do
102
+ let(:data) { {"status"=>"inactive"} }
103
+ it { expect(reference).to be_inactive }
104
+ end
105
+
106
+ context 'given fetching a reference does not return an inactive status' do
107
+ let(:data) { {"status"=>"unknown"} }
108
+ it { expect(reference).not_to be_inactive }
109
+ end
110
+ end
111
+
112
+ describe '#live_streaming_processing?' do
113
+ context 'given fetching a reference returns an live_streaming_processing status' do
114
+ let(:data) { {"status"=>"live_streaming_processing"} }
115
+ it { expect(reference).to be_live_streaming_processing }
116
+ end
117
+
118
+ context 'given fetching a reference does not return an live_streaming_processing status' do
119
+ let(:data) { {"status"=>"unknown"} }
120
+ it { expect(reference).not_to be_live_streaming_processing }
121
+ end
122
+ end
123
+
124
+ describe '#urgent_reference_processing?' do
125
+ context 'given fetching a reference returns an urgent_reference_processing status' do
126
+ let(:data) { {"status"=>"urgent_reference_processing"} }
127
+ it { expect(reference).to be_urgent_reference_processing }
128
+ end
129
+
130
+ context 'given fetching a reference does not return an urgent_reference_processing status' do
131
+ let(:data) { {"status"=>"unknown"} }
132
+ it { expect(reference).not_to be_urgent_reference_processing }
133
+ end
134
+ end
135
+
136
+ describe '#status_reason' do
137
+ context 'given fetching a reference returns a statusReason' do
138
+ let(:data) { {"statusReason"=>"explanation"} }
139
+ it { expect(reference.status_reason).to eq 'explanation' }
140
+ end
141
+ end
142
+
143
+ describe '#duplicate_leader' do
144
+ context 'given fetching a reference returns a duplicateLeader' do
145
+ let(:data) { {"duplicateLeader"=>"123456"} }
146
+ it { expect(reference.duplicate_leader).to eq '123456' }
147
+ end
148
+ end
149
+
150
+ describe '#length' do
151
+ context 'given fetching a reference returns a length' do
152
+ let(:data) { {"length"=>354.66} }
153
+ it { expect(reference.length).to eq 354.66 }
154
+ end
155
+ end
156
+
157
+ describe '#video_id' do
158
+ context 'given fetching a reference returns an videoId' do
159
+ let(:data) { {"videoId"=>"MESycYJytkU"} }
160
+ it { expect(reference.video_id).to eq 'MESycYJytkU' }
161
+ end
162
+ end
163
+
164
+ describe '#claim_id' do
165
+ context 'given fetching a reference returns an claimId' do
166
+ let(:data) { {"claimId"=>"aBcD1EfGHIk"} }
167
+ it { expect(reference.claim_id).to eq 'aBcD1EfGHIk' }
168
+ end
169
+ end
170
+
171
+ describe '#urgent?' do
172
+ context 'given fetching a reference returns an urgent status true' do
173
+ let(:data) { {"urgent"=>true} }
174
+ it { expect(reference).to be_urgent }
175
+ end
176
+
177
+ context 'given fetching a reference returns an urgent status false' do
178
+ let(:data) { {"urgent"=>false} }
179
+ it { expect(reference).not_to be_urgent }
180
+ end
181
+ end
182
+
183
+ describe '#content_type' do
184
+ context 'given fetching a reference returns a content type' do
185
+ let(:data) { {"contentType"=>"audio"} }
186
+ it { expect(reference.content_type).to eq 'audio' }
187
+ end
188
+ end
189
+
190
+ describe '#audio?' do
191
+ context 'given fetching a reference returns an audio content type' do
192
+ let(:data) { {"contentType"=>"audio"} }
193
+ it { expect(reference).to be_audio }
194
+ end
195
+
196
+ context 'given fetching a reference does not return an audio content type' do
197
+ let(:data) { {"contentType"=>"audiovisual"} }
198
+ it { expect(reference).not_to be_audio }
199
+ end
200
+ end
201
+
202
+ describe '#video?' do
203
+ context 'given fetching a reference returns an video content type' do
204
+ let(:data) { {"contentType"=>"video"} }
205
+ it { expect(reference).to be_video }
206
+ end
207
+
208
+ context 'given fetching a reference does not return an video content type' do
209
+ let(:data) { {"contentType"=>"audiovisual"} }
210
+ it { expect(reference).not_to be_video }
211
+ end
212
+ end
213
+
214
+ describe '#audiovisual?' do
215
+ context 'given fetching a reference returns an audiovisual content type' do
216
+ let(:data) { {"contentType"=>"audiovisual"} }
217
+ it { expect(reference).to be_audiovisual }
218
+ end
219
+
220
+ context 'given fetching a reference does not return an audiovisual content type' do
221
+ let(:data) { {"contentType"=>"audio"} }
222
+ it { expect(reference).not_to be_audiovisual }
223
+ end
224
+ end
225
+
226
+ describe '#audioswap_enabled?' do
227
+ context 'given fetching a reference returns audioswapEnabled true' do
228
+ let(:data) { {"audioswapEnabled"=>true} }
229
+ it { expect(reference).to be_audioswap_enabled }
230
+ end
231
+
232
+ context 'given fetching a reference returns audioswapEnabled false' do
233
+ let(:data) { {"audioswap_enabled"=>false} }
234
+ it { expect(reference).not_to be_audioswap_enabled }
235
+ end
236
+ end
237
+
238
+ describe '#ignore_fp_match?' do
239
+ context 'given fetching a reference returns ignoreFpMatch true' do
240
+ let(:data) { {"ignoreFpMatch"=>true} }
241
+ it { expect(reference.ignore_fp_match?).to be true }
242
+ end
243
+
244
+ context 'given fetching a reference returns ignoreFpMatch false' do
245
+ let(:data) { {"ignoreFpMatch"=>false} }
246
+ it { expect(reference.ignore_fp_match?).to be false }
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+ require 'yt/request'
3
+
4
+
5
+ describe Yt::Request do
6
+ subject(:request) { Yt::Request.new host: 'example.com' }
7
+ let(:response) { response_class.new nil, nil, nil }
8
+ let(:response_body) { }
9
+
10
+ describe '#run' do
11
+ context 'given a request that returns' do
12
+ before { allow(response).to receive(:body).and_return response_body }
13
+ before { expect(Net::HTTP).to receive(:start).once.and_return response }
14
+
15
+ context 'a success code 2XX' do
16
+ let(:response_class) { Net::HTTPOK }
17
+
18
+ it { expect{request.run}.not_to fail }
19
+ end
20
+
21
+ context 'an error code 5XX' do
22
+ let(:response_class) { Net::HTTPServerError }
23
+ let(:retry_response) { retry_response_class.new nil, nil, nil }
24
+ before { allow(retry_response).to receive(:body) }
25
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
26
+
27
+ context 'every time' do
28
+ let(:retry_response_class) { Net::HTTPServerError }
29
+
30
+ it { expect{request.run}.to fail }
31
+ end
32
+
33
+ context 'but returns a success code 2XX the second time' do
34
+ let(:retry_response_class) { Net::HTTPOK }
35
+
36
+ it { expect{request.run}.not_to fail }
37
+ end
38
+ end
39
+
40
+ context 'an error code 401' do
41
+ let(:response_class) { Net::HTTPUnauthorized }
42
+
43
+ it { expect{request.run}.to fail }
44
+ end
45
+
46
+ context 'any other non-2XX error code' do
47
+ let(:response_class) { Net::HTTPNotFound }
48
+
49
+ it { expect{request.run}.to fail }
50
+ end
51
+ end
52
+
53
+ # TODO: clean up the following tests, removing repetitions
54
+ context 'given a request that raises' do
55
+ before { expect(Net::HTTP).to receive(:start).once.and_raise http_error }
56
+
57
+ # NOTE: This test is just a reflection of YouTube irrational behavior of
58
+ # being unavailable once in a while, and therefore causing Net::HTTP to
59
+ # fail, although retrying after some seconds works.
60
+ context 'an OpenSSL::SSL::SSLError' do
61
+ let(:http_error) { OpenSSL::SSL::SSLError.new }
62
+
63
+ context 'every time' do
64
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
65
+
66
+ it { expect{request.run}.to fail }
67
+ end
68
+
69
+ context 'but works the second time' do
70
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
71
+ before { allow(retry_response).to receive(:body) }
72
+ let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
73
+
74
+ it { expect{request.run}.not_to fail }
75
+ end
76
+ end
77
+
78
+ # NOTE: This test is just a reflection of YouTube irrational behavior of
79
+ # being unavailable once in a while, and therefore causing Net::HTTP to
80
+ # fail, although retrying after some seconds works.
81
+ context 'an Errno::ETIMEDOUT' do
82
+ let(:http_error) { Errno::ETIMEDOUT.new }
83
+
84
+ context 'every time' do
85
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
86
+
87
+ it { expect{request.run}.to fail }
88
+ end
89
+
90
+ context 'but works the second time' do
91
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
92
+ before { allow(retry_response).to receive(:body) }
93
+ let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
94
+
95
+ it { expect{request.run}.not_to fail }
96
+ end
97
+ end
98
+
99
+ # NOTE: This test is just a reflection of YouTube irrational behavior of
100
+ # being unavailable once in a while, and therefore causing Net::HTTP to
101
+ # fail, although retrying after some seconds works.
102
+ context 'an Errno::ENETUNREACH' do
103
+ let(:http_error) { Errno::ENETUNREACH.new }
104
+
105
+ context 'every time' do
106
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
107
+
108
+ it { expect{request.run}.to fail }
109
+ end
110
+
111
+ context 'but works the second time' do
112
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
113
+ before { allow(retry_response).to receive(:body) }
114
+ let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
115
+
116
+ it { expect{request.run}.not_to fail }
117
+ end
118
+ end
119
+
120
+ # NOTE: This test is just a reflection of YouTube irrational behavior of
121
+ # being unavailable once in a while, and therefore causing Net::HTTP to
122
+ # fail, although retrying after some seconds works.
123
+ context 'an Errno::EHOSTUNREACH' do
124
+ let(:http_error) { Errno::EHOSTUNREACH.new }
125
+
126
+ context 'every time' do
127
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
128
+
129
+ it { expect{request.run}.to fail }
130
+ end
131
+
132
+ context 'but works the second time' do
133
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
134
+ before { allow(retry_response).to receive(:body) }
135
+ let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
136
+
137
+ it { expect{request.run}.not_to fail }
138
+ end
139
+ end
140
+
141
+ # NOTE: This test is just a reflection of YouTube irrational behavior of
142
+ # being unavailable once in a while, and therefore causing Net::HTTP to
143
+ # fail, although retrying after some seconds works.
144
+ context 'an OpenSSL::SSL::SSLErrorWaitReadable', ruby21: true do
145
+ let(:http_error) { OpenSSL::SSL::SSLErrorWaitReadable.new }
146
+
147
+ context 'every time' do
148
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_raise http_error }
149
+
150
+ it { expect{request.run}.to fail }
151
+ end
152
+
153
+ context 'but works the second time' do
154
+ before { expect(Net::HTTP).to receive(:start).at_least(:once).and_return retry_response }
155
+ before { allow(retry_response).to receive(:body) }
156
+ let(:retry_response) { Net::HTTPOK.new nil, nil, nil }
157
+
158
+ it { expect{request.run}.not_to fail }
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end