yt 0.14.2 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ab7c0d75dc3c575f9c55dd9e222505f70db290f
4
- data.tar.gz: 1594d3e696c068d0a439396591e6a41efb292dd0
3
+ metadata.gz: 9d1eeefafcd75a3c1c5f93117c6f5d08ab882569
4
+ data.tar.gz: 48aafacb7c44c358ca7e4d32dd3cac022e50835a
5
5
  SHA512:
6
- metadata.gz: 5205274ae1d25ce04a75f6d5cd92742e1cfa77930695795a13879f463dcbaf0c5d5d25e56ef799bf90506c0494a29e732133faab705da4c9c32d2cf54bbb7d38
7
- data.tar.gz: 42810660757c546f295d1f8b038ce2b7cefb74b30c20327cc7d1548e19562c07c06cfc3e53b867d604ef0156edc4be96bfcdc656acaeda030c87d1ef89441f2a
6
+ metadata.gz: ff3234ddd12713b1ef8ab0d291cb154be0db0d673272c2aa50f602c358a8c9f0617ca1505b6a11f027f42b06fed5244346e0d85b9c429192d803da8ae49d0da6
7
+ data.tar.gz: 2cf90341fe38289cbcbabcb1e2543b347bd9ca00e6eed81d49fae81845b457df15e7dc429d89c98ed743de0c5a7b99819f2b4e16ccff1952fb36dab15283e28b
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.14.3 - 2015-04-09
10
+
11
+ * [BUGFIX] Don't let request errors crash Yt in Ruby 1.9.3.
12
+
9
13
  ## 0.14.2 - 2015-04-08
10
14
 
11
15
  * [FEATURE] Make `Annotation#text` a public method.
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.14.2'
44
+ gem 'yt', '~> 0.14.3'
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*)
@@ -568,6 +568,30 @@ asset.ownership.release! #=> true
568
568
  asset.update metadata_mine: {notes: 'Some notes'} #=> true
569
569
  ```
570
570
 
571
+ Yt::Claim
572
+ ---------
573
+
574
+ Use [Yt::Claim](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models/Claim) to:
575
+
576
+ * read the attributes of a claim
577
+ * view the history of a claim
578
+ * update the attributes of an claim
579
+
580
+ ```ruby
581
+
582
+ content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'
583
+ claim = Yt::Claim.new id: 'ABCD12345678', auth: content_owner
584
+ claim.video_id #=> 'va141cJga2'
585
+ claim.asset_id #=> 'A1234'
586
+ claim.content_type #=> 'audiovisual'
587
+ claim.active? #=> true
588
+
589
+ claim.claim_history #=> #<Yt::Models::ClaimHistory ...>
590
+ claim.claim_history.events[0].type #=> "claim_create"
591
+
592
+ claim.delete #=> true
593
+ ```
594
+
571
595
  *The methods above require to be authenticated as the video’s content owner (see below).*
572
596
 
573
597
  Yt::Ownership
data/lib/yt.rb CHANGED
@@ -2,6 +2,7 @@ require 'yt/config'
2
2
  require 'yt/models/account'
3
3
  require 'yt/models/channel'
4
4
  require 'yt/models/claim'
5
+ require 'yt/models/claim_history'
5
6
  require 'yt/models/content_owner'
6
7
  require 'yt/models/match_policy'
7
8
  require 'yt/models/playlist'
@@ -0,0 +1,34 @@
1
+ require 'yt/collections/resources'
2
+ require 'yt/models/claim'
3
+
4
+ module Yt
5
+ module Collections
6
+ # Provides methods to interact with a the claim history options of a YouTube claim.
7
+ #
8
+ # Resources with claim history are: {Yt::Models::Claim claims}.
9
+ class ClaimHistories < Resources
10
+
11
+ private
12
+
13
+ def attributes_for_new_item(data)
14
+ {data: data, id: @parent.id, auth: @auth}
15
+ end
16
+
17
+ # @return [Hash] the parameters to submit to YouTube to get claim history.
18
+ # @see https://developers.google.com/youtube/partner/docs/v1/claimHistory/get
19
+ def list_params
20
+ super.tap do |params|
21
+ params[:path] = "/youtube/partner/v1/claimHistory/#{@parent.id}"
22
+ params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
23
+ end
24
+ end
25
+
26
+ # @private
27
+ # @note ClaimHistories overwrites +fetch_page+ since it’s a get.
28
+ def fetch_page(params = {})
29
+ response = list_request(params).run
30
+ {items: [response.body], token: nil}
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,12 +5,18 @@ module Yt
5
5
  # Provides methods to interact with YouTube ContentID claims.
6
6
  # @see https://developers.google.com/youtube/partner/docs/v1/claims
7
7
  class Claim < Base
8
+ attr_reader :auth
9
+
8
10
  def initialize(options = {})
9
11
  @data = options[:data]
10
12
  @id = options[:id]
11
13
  @auth = options[:auth]
12
14
  end
13
15
 
16
+ # @!attribute [r] claim_history
17
+ # @return [Yt::Collections::ClaimHistories] the claim's history.
18
+ has_one :claim_history
19
+
14
20
  # Soft-deletes the claim.
15
21
  # @note YouTube API does not provide a +delete+ method for the Asset
16
22
  # resource, but only an +update+ method. Updating the +status+ of a
@@ -137,6 +143,7 @@ module Yt
137
143
  (match_info || {})['referenceId']
138
144
  end
139
145
 
146
+
140
147
  private
141
148
 
142
149
  # @see https://developers.google.com/youtube/partner/docs/v1/claims/update
@@ -0,0 +1,67 @@
1
+ require 'yt/models/base'
2
+
3
+ module Yt
4
+ module Models
5
+ class ClaimEvent < Base
6
+ def initialize(options = {})
7
+ @data = options[:data]
8
+ end
9
+
10
+ REASONS = %w(asset_transfer_request audio_muted audio_replaced audioswap_removed
11
+ channel_transferred channel_whitelisted closed_audio_claim_on_visual_reference
12
+ closed_audio_revshare closed_by_admin closed_cover_revshare
13
+ closed_invalid_reference_segment closed_manually closed_partner_exclusion
14
+ closed_private_video closed_reference_conflict copyrighted_content_matched
15
+ counter_received dispute_resolution duplicate invalid_claim muting_audio
16
+ ownership_removed partner_deactivated pending_activation pending_adsense
17
+ pending_fingerprint pending_for_review reference_removed released replaced
18
+ review_expired revshare_disabled risk_of_error song_erased
19
+ suspended_monetization_on_channel video_classifier_rejecion video_content_modified
20
+ video_removed video_taken_down)
21
+
22
+ # @return [Time] the date and time when the event occurred.
23
+ has_attribute :time, type: Time
24
+
25
+ # @return [String] the reason an event occurred.
26
+ has_attribute :reason
27
+
28
+ # @return [String] the event's type.
29
+ has_attribute :type
30
+
31
+ # @return [String] the source type which triggered the event.
32
+ has_attribute :source_type, from: :source do |source|
33
+ (source || {})['type']
34
+ end
35
+
36
+ # @return [String] the ID of the content owner that initiated
37
+ # the event.
38
+ has_attribute :source_content_owner_id, from: :source do |source|
39
+ (source || {})['contentOwnerId']
40
+ end
41
+
42
+ # @return [String] the email address of the user who initiated
43
+ # the event.
44
+ has_attribute :source_user_email, from: :source do |source|
45
+ (source || {})['userEmail']
46
+ end
47
+
48
+ # @return [String] the reason that explains why a
49
+ # dispute_create event occurred.
50
+ has_attribute :dispute_reason, from: :type_details do |type_details|
51
+ (type_details || {})['disputeReason']
52
+ end
53
+
54
+ # @return [String] a free-text explanation of the reason that a claim
55
+ # was disputed. This property is returned for dispute_create events.
56
+ has_attribute :dispute_notes, from: :type_details do |type_details|
57
+ (type_details || {})['disputeNotes']
58
+ end
59
+
60
+ # @return [String] the event status that resulted from a claim_update
61
+ # event.
62
+ has_attribute :update_status, from: :type_details do |type_details|
63
+ (type_details || {})['updateStatus']
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ require 'yt/models/base'
2
+ require 'yt/models/claim_event'
3
+
4
+ module Yt
5
+ module Models
6
+ # Provides methods to interact with YouTube ContentID claims.
7
+ # @see https://developers.google.com/youtube/partner/docs/v1/claims
8
+ class ClaimHistory < Base
9
+ def initialize(options = {})
10
+ @data = options[:data]
11
+ @id = options[:id]
12
+ @auth = options[:auth]
13
+ end
14
+
15
+ # @return [String] the ID that YouTube assigns and uses to uniquely
16
+ # identify the claim.
17
+ has_attribute :id
18
+
19
+ # @return [String] the unique YouTube channel ID of the channel to
20
+ # which the claimed video was uploaded.
21
+ has_attribute :uploader_channel_id
22
+
23
+ # @return [Array<String>] the list of events associated with the claim.
24
+ has_attribute :events, from: :event do |event_info|
25
+ event_info.map{|event| ClaimEvent.new data: event}
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/yt/request.rb CHANGED
@@ -202,12 +202,11 @@ module Yt
202
202
  def server_errors
203
203
  [
204
204
  OpenSSL::SSL::SSLError,
205
- OpenSSL::SSL::SSLErrorWaitReadable,
206
205
  Errno::ETIMEDOUT,
207
206
  Errno::ENETUNREACH,
208
207
  Errno::ECONNRESET,
209
208
  Net::HTTPServerError
210
- ]
209
+ ] + (RUBY_VERSION < '2' ? [] : [OpenSSL::SSL::SSLErrorWaitReadable])
211
210
  end
212
211
 
213
212
  # Sleeps for a while and returns true for the first +max_retries+ times,
@@ -265,4 +264,4 @@ module Yt
265
264
  {request_curl: as_curl, response_body: response_body}
266
265
  end
267
266
  end
268
- end
267
+ end
data/lib/yt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.14.2'
2
+ VERSION = '0.14.3'
3
3
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/claim_event'
3
+
4
+ describe Yt::ClaimEvent do
5
+ subject(:claim_event) { Yt::ClaimEvent.new data: data }
6
+
7
+ describe '#time' do
8
+ context 'given fetching a claim_event returns a time' do
9
+ let(:data) { {"time"=>"2015-04-08T21:52:13.000Z"} }
10
+ it { expect(claim_event.time).to be_a Time }
11
+ end
12
+ end
13
+
14
+ describe '#type' do
15
+ context 'given fetching a claim_event returns a type' do
16
+ let(:data) { {"type"=>"claim_create"} }
17
+ it { expect(claim_event.type).to eq 'claim_create' }
18
+ end
19
+ end
20
+
21
+ describe '#source_type' do
22
+ context 'given fetching a claim_event returns a source_type' do
23
+ let(:data) { {'source'=>{'type' => 'cms_user'}} }
24
+ it { expect(claim_event.source_type).to eq 'cms_user' }
25
+ end
26
+ end
27
+
28
+ describe '#source_content_owner_id' do
29
+ context 'given fetching a claim_event returns a source_content_owner_id' do
30
+ let(:data) { {'source'=>{'contentOwnerId' => 'C1234'}} }
31
+ it { expect(claim_event.source_content_owner_id).to eq 'C1234' }
32
+ end
33
+ end
34
+
35
+ describe '#source_user_email' do
36
+ context 'given fetching a claim_event returns a source_user_email' do
37
+ let(:data) { {'source'=>{'userEmail' => 'email@fullscreen.net'}} }
38
+ it { expect(claim_event.source_user_email).to eq 'email@fullscreen.net' }
39
+ end
40
+ end
41
+
42
+ describe '#dispute_reason' do
43
+ context 'given fetching a claim_event returns a dispute_reason' do
44
+ let(:data) { {'typeDetails'=>{'disputeReason' => 'fair_use'}} }
45
+ it { expect(claim_event.dispute_reason).to eq 'fair_use' }
46
+ end
47
+ end
48
+
49
+ describe '#dispute_notes' do
50
+ context 'given fetching a claim_event returns dispute_notes' do
51
+ let(:data) { {'typeDetails'=>{'disputeNotes' => 'User entered notes here.'}} }
52
+ it { expect(claim_event.dispute_notes).to eq 'User entered notes here.' }
53
+ end
54
+ end
55
+
56
+ describe '#update_status' do
57
+ context 'given fetching a claim_event returns an update_status' do
58
+ let(:data) { {'typeDetails'=>{'updateStatus' => 'active'}} }
59
+ it { expect(claim_event.update_status).to eq 'active' }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/claim_history'
3
+
4
+ describe Yt::ClaimHistory do
5
+ subject(:claim_history) { Yt::ClaimHistory.new data: data }
6
+
7
+ describe '#id' do
8
+ context 'given fetching claim_history with an id' do
9
+ let(:data) { {"id"=>"acbd1234"}}
10
+ it { expect(claim_history.id).to eq "acbd1234" }
11
+ end
12
+ end
13
+
14
+ describe '#uploader_channel_id' do
15
+ context 'given fetching claim_history with an uploader_channel_id' do
16
+ let(:data) { {"uploaderChannelId"=>"C1234"}}
17
+ it { expect(claim_history.uploader_channel_id).to eq "C1234" }
18
+ end
19
+ end
20
+
21
+ describe '#events' do
22
+ context 'given fetching claim_history with associated events' do
23
+ let(:data) { {"event"=>[{"time"=>"2015-03-21T21:35:42.000Z"},{"time"=>"2015-03-21T21:35:42.000Z"}]} }
24
+ it { expect(claim_history.events.size).to eq 2 }
25
+ end
26
+ end
27
+ end
@@ -120,7 +120,7 @@ describe Yt::Request do
120
120
  # NOTE: This test is just a reflection of YouTube irrational behavior of
121
121
  # being unavailable once in a while, and therefore causing Net::HTTP to
122
122
  # fail, although retrying after some seconds works.
123
- context 'an OpenSSL::SSL::SSLErrorWaitReadable' do
123
+ context 'an OpenSSL::SSL::SSLErrorWaitReadable', ruby2: true do
124
124
  let(:http_error) { OpenSSL::SSL::SSLErrorWaitReadable.new }
125
125
 
126
126
  context 'every time' do
@@ -139,4 +139,4 @@ describe Yt::Request do
139
139
  end
140
140
  end
141
141
  end
142
- end
142
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'yt/models/claim'
3
+ require 'yt/models/claim_history'
4
+
5
+ describe Yt::ClaimHistory, :partner do
6
+ subject(:claim) { Yt::Claim.new id: asset_id, auth: $content_owner }
7
+
8
+ context 'given a claim previously administered by the authenticated Content Owner' do
9
+ let(:asset_id) { ENV['YT_TEST_CLAIM_ID'] }
10
+
11
+ describe 'the claim history can be obtained' do
12
+ it { expect(claim.claim_history.events.size > 0).to eq true }
13
+ end
14
+
15
+ describe 'the claim_create event' do
16
+ let(:claim_create_event) { claim.claim_history.events.find {|e| e.type == 'claim_create'} }
17
+ it { expect(claim_create_event.time).to be_a Time }
18
+ end
19
+ end
20
+ end
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.14.2
4
+ version: 0.14.3
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-04-08 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -136,6 +136,7 @@ files:
136
136
  - lib/yt/collections/authentications.rb
137
137
  - lib/yt/collections/base.rb
138
138
  - lib/yt/collections/channels.rb
139
+ - lib/yt/collections/claim_histories.rb
139
140
  - lib/yt/collections/claims.rb
140
141
  - lib/yt/collections/content_details.rb
141
142
  - lib/yt/collections/content_owner_details.rb
@@ -179,6 +180,8 @@ files:
179
180
  - lib/yt/models/base.rb
180
181
  - lib/yt/models/channel.rb
181
182
  - lib/yt/models/claim.rb
183
+ - lib/yt/models/claim_event.rb
184
+ - lib/yt/models/claim_history.rb
182
185
  - lib/yt/models/configuration.rb
183
186
  - lib/yt/models/content_detail.rb
184
187
  - lib/yt/models/content_owner.rb
@@ -227,6 +230,8 @@ files:
227
230
  - spec/models/annotation_spec.rb
228
231
  - spec/models/asset_spec.rb
229
232
  - spec/models/channel_spec.rb
233
+ - spec/models/claim_event_spec.rb
234
+ - spec/models/claim_history_spec.rb
230
235
  - spec/models/claim_spec.rb
231
236
  - spec/models/configuration_spec.rb
232
237
  - spec/models/content_detail_spec.rb
@@ -264,6 +269,7 @@ files:
264
269
  - spec/requests/as_content_owner/advertising_options_set_spec.rb
265
270
  - spec/requests/as_content_owner/asset_spec.rb
266
271
  - spec/requests/as_content_owner/channel_spec.rb
272
+ - spec/requests/as_content_owner/claim_history_spec.rb
267
273
  - spec/requests/as_content_owner/content_owner_spec.rb
268
274
  - spec/requests/as_content_owner/match_policy_spec.rb
269
275
  - spec/requests/as_content_owner/ownership_spec.rb
@@ -325,6 +331,8 @@ test_files:
325
331
  - spec/models/annotation_spec.rb
326
332
  - spec/models/asset_spec.rb
327
333
  - spec/models/channel_spec.rb
334
+ - spec/models/claim_event_spec.rb
335
+ - spec/models/claim_history_spec.rb
328
336
  - spec/models/claim_spec.rb
329
337
  - spec/models/configuration_spec.rb
330
338
  - spec/models/content_detail_spec.rb
@@ -362,6 +370,7 @@ test_files:
362
370
  - spec/requests/as_content_owner/advertising_options_set_spec.rb
363
371
  - spec/requests/as_content_owner/asset_spec.rb
364
372
  - spec/requests/as_content_owner/channel_spec.rb
373
+ - spec/requests/as_content_owner/claim_history_spec.rb
365
374
  - spec/requests/as_content_owner/content_owner_spec.rb
366
375
  - spec/requests/as_content_owner/match_policy_spec.rb
367
376
  - spec/requests/as_content_owner/ownership_spec.rb