yt 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/yt/collections/references.rb +25 -1
- data/lib/yt/models/claim.rb +6 -0
- data/lib/yt/models/content_owner.rb +4 -0
- data/lib/yt/models/reference.rb +26 -0
- data/lib/yt/version.rb +1 -1
- data/spec/models/claim_spec.rb +7 -0
- data/spec/requests/as_account/video_spec.rb +1 -1
- data/spec/requests/as_content_owner/content_owner_spec.rb +27 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed082f94cdaa3fa496bd9ef6cffd95754fb292c1
|
4
|
+
data.tar.gz: 38a76b4cca68dcea1c70ab1bfe1423e6502a9922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c28709d46e78e6ed3b0b20d1c72d106b5330477e70088bd21193547963113b97594f44258c597a7b9203ba00e26defb838a748fb14bd958c59ea095fceb192f5
|
7
|
+
data.tar.gz: 535292f6eb80998cb0b46e6032eff963e7a0bae948b260d2be881c910f0e4eb5e664b72eff631155d6a1970e0e67c3210a3f5d9aa0053cb8d1d5094bda3c0680
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ 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.10.3 - 2014-08-12
|
10
|
+
|
11
|
+
* [FEATURE] Add methods to insert and delete ContentID references
|
12
|
+
* [FEATURE] Add `.match_reference_id` to Claim model
|
13
|
+
|
9
14
|
## 0.10.2 - 2014-08-11
|
10
15
|
|
11
16
|
* [FEATURE] Add `MatchPolicy` class with `.update` to change the policy used by an asset
|
data/Gemfile.lock
CHANGED
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.10.
|
44
|
+
gem 'yt', '~> 0.10.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*)
|
@@ -7,11 +7,25 @@ module Yt
|
|
7
7
|
#
|
8
8
|
# Resources with references are: {Yt::Models::ContentOwner content owners}.
|
9
9
|
class References < Base
|
10
|
+
def insert(attributes = {})
|
11
|
+
underscore_keys! attributes
|
12
|
+
body = {contentType: attributes[:content_type] }
|
13
|
+
params = {claimId: attributes[:claim_id], onBehalfOfContentOwner: @auth.owner_name}
|
14
|
+
do_insert(params: params, body: body)
|
15
|
+
end
|
10
16
|
|
11
17
|
private
|
12
18
|
|
13
19
|
def new_item(data)
|
14
|
-
Yt::Reference.new data: data
|
20
|
+
Yt::Reference.new data: data, auth: @auth
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Hash] the parameters to submit to YouTube to add a reference.
|
24
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/references/insert
|
25
|
+
def insert_params
|
26
|
+
super.tap do |params|
|
27
|
+
params[:path] = '/youtube/partner/v1/references'
|
28
|
+
end
|
15
29
|
end
|
16
30
|
|
17
31
|
# @return [Hash] the parameters to submit to YouTube to list references
|
@@ -27,6 +41,16 @@ module Yt
|
|
27
41
|
def references_params
|
28
42
|
apply_where_params! on_behalf_of_content_owner: @parent.owner_name
|
29
43
|
end
|
44
|
+
|
45
|
+
# If we dropped support for ActiveSupport 3, then we could simply
|
46
|
+
# invoke transform_keys!{|key| key.to_s.underscore.to_sym}
|
47
|
+
def underscore_keys!(hash)
|
48
|
+
hash.dup.each_key{|key| hash[underscore key] = hash.delete key}
|
49
|
+
end
|
50
|
+
|
51
|
+
def underscore(value)
|
52
|
+
value.to_s.underscore.to_sym
|
53
|
+
end
|
30
54
|
end
|
31
55
|
end
|
32
56
|
end
|
data/lib/yt/models/claim.rb
CHANGED
@@ -131,6 +131,12 @@ module Yt
|
|
131
131
|
def block_outside_ownership?
|
132
132
|
@block_outside_ownership ||= @data["blockOutsideOwnership"]
|
133
133
|
end
|
134
|
+
|
135
|
+
# @return [String] The unique ID that YouTube uses to identify the
|
136
|
+
# reference that generated the match.
|
137
|
+
def match_reference_id
|
138
|
+
@match_reference_id ||= @data.fetch('matchInfo', {})['referenceId']
|
139
|
+
end
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
data/lib/yt/models/reference.rb
CHANGED
@@ -7,6 +7,21 @@ module Yt
|
|
7
7
|
class Reference < Base
|
8
8
|
def initialize(options = {})
|
9
9
|
@data = options[:data]
|
10
|
+
@id = options[:id]
|
11
|
+
@auth = options[:auth]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Soft-deletes the reference.
|
15
|
+
#
|
16
|
+
# @note YouTube API does not provide a +delete+ method for the Reference
|
17
|
+
# resource, but only an +update+ method. Updating the +status+ of a
|
18
|
+
# Reference to "inactive" can be considered a soft-deletion, since it
|
19
|
+
# allows to successively create new references for the same claim.
|
20
|
+
# @return [Boolean] whether the reference is inactive.
|
21
|
+
def delete
|
22
|
+
body = {id: id, status: :inactive}
|
23
|
+
do_update(body: body) {|data| @data = data}
|
24
|
+
inactive?
|
10
25
|
end
|
11
26
|
|
12
27
|
# @return [String] the ID that YouTube assigns and uses to uniquely
|
@@ -173,6 +188,17 @@ module Yt
|
|
173
188
|
def audiovisual?
|
174
189
|
content_type == 'audiovisual'
|
175
190
|
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/references/update
|
195
|
+
def update_params
|
196
|
+
super.tap do |params|
|
197
|
+
params[:expected_response] = Net::HTTPOK
|
198
|
+
params[:path] = "/youtube/partner/v1/references/#{id}"
|
199
|
+
params[:params] = {onBehalfOfContentOwner: @auth.owner_name}
|
200
|
+
end
|
201
|
+
end
|
176
202
|
end
|
177
203
|
end
|
178
204
|
end
|
data/lib/yt/version.rb
CHANGED
data/spec/models/claim_spec.rb
CHANGED
@@ -190,6 +190,13 @@ describe Yt::Claim do
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
+
describe '#match_reference_id' do
|
194
|
+
context 'given fetching a claim returns matchInfo' do
|
195
|
+
let(:data) { {"matchInfo"=>{"referenceId"=>"0r3JDtcRLuQ"}} }
|
196
|
+
it { expect(claim.match_reference_id).to eq "0r3JDtcRLuQ" }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
193
200
|
describe '#third_party?' do
|
194
201
|
context 'given fetching a claim returns thirdPartyClaim true' do
|
195
202
|
let(:data) { {"thirdPartyClaim"=>true} }
|
@@ -334,7 +334,7 @@ describe Yt::Video, :device_app do
|
|
334
334
|
let!(:old_privacy_status) { 'private' }
|
335
335
|
after { video.delete}
|
336
336
|
|
337
|
-
let!(:new_scheduled_at) { Yt::Timestamp.parse("#{rand
|
337
|
+
let!(:new_scheduled_at) { Yt::Timestamp.parse("#{rand(30) + 1} Jan 2020", Time.now) }
|
338
338
|
|
339
339
|
context 'passing the parameter in underscore syntax' do
|
340
340
|
let(:attrs) { {publish_at: new_scheduled_at} }
|
@@ -95,6 +95,33 @@ describe Yt::ContentOwner, :partner do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
describe 'references' do
|
99
|
+
let(:claim_id) { ENV['YT_TEST_PARTNER_REFERENCE_CLAIM_ID'] }
|
100
|
+
let(:content_type) { ENV['YT_TEST_PARTNER_REFERENCE_CONTENT_TYPE'] }
|
101
|
+
let(:params) { {claim_id: claim_id, content_type: content_type} }
|
102
|
+
|
103
|
+
specify 'can be added' do
|
104
|
+
begin
|
105
|
+
expect($content_owner.create_reference params).to be_a Yt::Reference
|
106
|
+
rescue Yt::Errors::RequestError => e
|
107
|
+
# @note: Every time this test runs, a reference is inserted for the
|
108
|
+
# same claim, but YouTube does not allow this, and responds with an
|
109
|
+
# error message like "You attempted to create a reference using the
|
110
|
+
# content of a previously claimed video, but such a reference already
|
111
|
+
# exists. The ID of the duplicate reference is xhpACYclOdc."
|
112
|
+
# For the sake of testing, we delete the duplicate and try again.
|
113
|
+
# @note: Deleting a reference does not work if the reference status is
|
114
|
+
# "checking" or "pending" and it can take up to 4 minutes for a new
|
115
|
+
# reference to be checked. The +sleep+ statement takes care of this
|
116
|
+
# case in the only way allowed by YouTube: sadly waiting.
|
117
|
+
raise unless e.reasons.include? 'referenceAlreadyExists'
|
118
|
+
id = e.kind['message'].match(/reference is (.*?)\.$/) {|re| re[1]}
|
119
|
+
sleep 15 until Yt::Reference.new(id: id, auth: $content_owner).delete
|
120
|
+
expect($content_owner.create_reference params).to be_a Yt::Reference
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
98
125
|
describe '.references' do
|
99
126
|
describe '.where(id: reference_id)' do
|
100
127
|
let(:reference) { $content_owner.references.where(id: reference_id).first }
|