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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9fd88acf793e77574d16b31819944cd77df882d
4
- data.tar.gz: 7e535a7e4c88f91477f2ccc19ce7ad5d4c1968cc
3
+ metadata.gz: a06e107e7f31f7de48b0d8ff204c767c823c25eb
4
+ data.tar.gz: edfd691ddfbb02206d8edde88ade590ea16054be
5
5
  SHA512:
6
- metadata.gz: 8eed1c36c8d41ae347a6bf9f951842446415efdf8bd9df139973122366fda9f772ffcf5aa7da08c87aa576c382c4364ddadfec8ebefa0717e9355874f5bea548
7
- data.tar.gz: 0cd8c87df0590b986dd1e72d6f7332dc633505386cfe6514595591efa237828df096ae610cb72ba946edc5024543cb84c45220d0b9bfc26b09a982ac7e437824
6
+ metadata.gz: 71703d93dc25594789d244709ef378fab971c23dd6920ea8e10e7daa2546d3087a6246d80135e3c5c01ad94b4cf05f4ade40199bff5acb91fcd3cd1065527010
7
+ data.tar.gz: 874b280fabf0bc5417203724049dfe5915d9d2d6d19c79f8e3b5395f221ad324ead150cae7468bda633e78575aad364560001b2802268addd6376cbe9bae89b1
@@ -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.1'
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
@@ -202,6 +202,7 @@ module Yt
202
202
  [
203
203
  OpenSSL::SSL::SSLError,
204
204
  Errno::ETIMEDOUT,
205
+ Errno::EHOSTUNREACH,
205
206
  Errno::ENETUNREACH,
206
207
  Errno::ECONNRESET,
207
208
  Net::HTTPServerError
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.25.1'
2
+ VERSION = '0.25.2'
3
3
  end
@@ -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
- it { expect(playlist.playlist_items.first).to be_a Yt::PlaylistItem }
24
- it { expect(playlist.playlist_items.first.snippet).to be_complete }
25
- it { expect(playlist.playlist_items.first.position).not_to be_nil }
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.1
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-06 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport