yt 0.25.1 → 0.25.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -1
- data/lib/yt/collections/playlist_items.rb +17 -1
- data/lib/yt/models/playlist_item.rb +7 -0
- data/lib/yt/request.rb +1 -0
- data/lib/yt/version.rb +1 -1
- data/spec/models/request_spec.rb +21 -0
- data/spec/requests/as_account/playlist_spec.rb +25 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06e107e7f31f7de48b0d8ff204c767c823c25eb
|
4
|
+
data.tar.gz: edfd691ddfbb02206d8edde88ade590ea16054be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71703d93dc25594789d244709ef378fab971c23dd6920ea8e10e7daa2546d3087a6246d80135e3c5c01ad94b4cf05f4ade40199bff5acb91fcd3cd1065527010
|
7
|
+
data.tar.gz: 874b280fabf0bc5417203724049dfe5915d9d2d6d19c79f8e3b5395f221ad324ead150cae7468bda633e78575aad364560001b2802268addd6376cbe9bae89b1
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 0.25.2 - 2015-07-22
|
10
|
+
|
11
|
+
* [FEATURE] Add .includes(:video) to .playlist_items to eager-load video data of a list of playlist items.
|
12
|
+
|
9
13
|
## 0.25.1 - 2015-07-06
|
10
14
|
|
11
15
|
* [ENHANCEMENT] `Yt::Video.new` accepts embedded video url.
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ To install on your system, run
|
|
41
41
|
|
42
42
|
To use inside a bundled Ruby project, add this line to the Gemfile:
|
43
43
|
|
44
|
-
gem 'yt', '~> 0.25.
|
44
|
+
gem 'yt', '~> 0.25.2'
|
45
45
|
|
46
46
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
47
47
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
@@ -174,6 +174,24 @@ asset.ownership.release! #=> true
|
|
174
174
|
asset.update metadata_mine: {notes: 'Some notes'} #=> true
|
175
175
|
```
|
176
176
|
|
177
|
+
* to retrieve metadata for an asset (e.g. title, notes, description, custom_id)
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
content_owner = Yt::ContentOwner.new(...)
|
181
|
+
asset = content_owner.assets.where(id: 'A969176766549462', fetch_metadata: 'mine').first
|
182
|
+
asset.metadata_mine.title #=> "Master Final Neu La Anh Fix"
|
183
|
+
|
184
|
+
asset = content_owner.assets.where(id: 'A969176766549462', fetch_metadata: 'effective').first
|
185
|
+
asset.metadata_effective.title #=> "Neu la anh" (different due to ownership conflicts)
|
186
|
+
```
|
187
|
+
|
188
|
+
* to search for an asset
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
content_owner.assets.where(labels: "campaign:cpiuwdz-8oc").size #=> 417
|
192
|
+
content_owner.assets.where(labels: "campaign:cpiuwdz-8oc").first.title #=> "Whoomp! (Supadupafly) (Xxl Hip House Mix)"
|
193
|
+
```
|
194
|
+
|
177
195
|
Yt::Claim
|
178
196
|
---------
|
179
197
|
|
@@ -16,7 +16,23 @@ module Yt
|
|
16
16
|
def attributes_for_new_item(data)
|
17
17
|
snippet = data.fetch 'snippet', {}
|
18
18
|
data['snippet'].reverse_merge! complete: snippet.key?('position')
|
19
|
-
super(data)
|
19
|
+
super(data).tap do |attributes|
|
20
|
+
attributes[:video] = data['video']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def eager_load_items_from(items)
|
25
|
+
if included_relationships.include?(:video)
|
26
|
+
video_ids = items.map{|item| item['snippet']['resourceId']['videoId']}.uniq
|
27
|
+
conditions = {id: video_ids.join(',')}
|
28
|
+
conditions[:part] = 'snippet,status,statistics'
|
29
|
+
videos = Collections::Videos.new(auth: @auth).where conditions
|
30
|
+
items.each do |item|
|
31
|
+
video = videos.find{|v| v.id == item['snippet']['resourceId']['videoId']}
|
32
|
+
item['video'] = video
|
33
|
+
end
|
34
|
+
end
|
35
|
+
super
|
20
36
|
end
|
21
37
|
|
22
38
|
# @return [Hash] the parameters to submit to YouTube to list playlist items.
|
@@ -88,6 +88,13 @@ module Yt
|
|
88
88
|
!@id.nil?
|
89
89
|
end
|
90
90
|
|
91
|
+
# @private
|
92
|
+
# Override Resource's new to set video if the response includes it
|
93
|
+
def initialize(options = {})
|
94
|
+
super options
|
95
|
+
@video = options[:video] if options[:video]
|
96
|
+
end
|
97
|
+
|
91
98
|
private
|
92
99
|
|
93
100
|
def resource_id
|
data/lib/yt/request.rb
CHANGED
data/lib/yt/version.rb
CHANGED
data/spec/models/request_spec.rb
CHANGED
@@ -117,6 +117,27 @@ describe Yt::Request do
|
|
117
117
|
end
|
118
118
|
end
|
119
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
|
+
|
120
141
|
# NOTE: This test is just a reflection of YouTube irrational behavior of
|
121
142
|
# being unavailable once in a while, and therefore causing Net::HTTP to
|
122
143
|
# fail, although retrying after some seconds works.
|
@@ -20,9 +20,31 @@ describe Yt::Playlist, :device_app do
|
|
20
20
|
expect(playlist.privacy_status).to be_a String
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
describe '.playlist_items' do
|
24
|
+
let(:item) { playlist.playlist_items.first }
|
25
|
+
|
26
|
+
specify 'returns the playlist item with the complete snippet' do
|
27
|
+
expect(item).to be_a Yt::PlaylistItem
|
28
|
+
expect(item.snippet).to be_complete
|
29
|
+
expect(item.position).not_to be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
specify 'does not eager-load the attributes of the item’s video' do
|
33
|
+
expect(item.video.instance_variable_defined? :@snippet).to be false
|
34
|
+
expect(item.video.instance_variable_defined? :@status).to be false
|
35
|
+
expect(item.video.instance_variable_defined? :@statistics_set).to be false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.playlist_items.includes(:video)' do
|
40
|
+
let(:item) { playlist.playlist_items.includes(:video).first }
|
41
|
+
|
42
|
+
specify 'eager-loads the snippet, status and statistics of each video' do
|
43
|
+
expect(item.video.instance_variable_defined? :@snippet).to be true
|
44
|
+
expect(item.video.instance_variable_defined? :@status).to be true
|
45
|
+
expect(item.video.instance_variable_defined? :@statistics_set).to be true
|
46
|
+
end
|
47
|
+
end
|
26
48
|
end
|
27
49
|
|
28
50
|
context 'given an unknown playlist' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.25.
|
4
|
+
version: 0.25.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Baccigalupo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|