yt-andrewroth 0.25.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +27 -0
- data/.rspec +3 -0
- data/.travis.yml +9 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +732 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +489 -0
- data/Rakefile +11 -0
- data/YOUTUBE_IT.md +835 -0
- data/bin/yt +30 -0
- data/gemfiles/Gemfile.activesupport-3.x +4 -0
- data/gemfiles/Gemfile.activesupport-4.x +4 -0
- data/lib/yt.rb +21 -0
- data/lib/yt/actions/base.rb +32 -0
- data/lib/yt/actions/delete.rb +19 -0
- data/lib/yt/actions/delete_all.rb +32 -0
- data/lib/yt/actions/insert.rb +42 -0
- data/lib/yt/actions/list.rb +139 -0
- data/lib/yt/actions/modify.rb +37 -0
- data/lib/yt/actions/patch.rb +19 -0
- data/lib/yt/actions/update.rb +19 -0
- data/lib/yt/associations/has_attribute.rb +55 -0
- data/lib/yt/associations/has_authentication.rb +214 -0
- data/lib/yt/associations/has_many.rb +22 -0
- data/lib/yt/associations/has_one.rb +22 -0
- data/lib/yt/associations/has_reports.rb +320 -0
- data/lib/yt/collections/advertising_options_sets.rb +34 -0
- data/lib/yt/collections/annotations.rb +62 -0
- data/lib/yt/collections/assets.rb +58 -0
- data/lib/yt/collections/authentications.rb +47 -0
- data/lib/yt/collections/base.rb +62 -0
- data/lib/yt/collections/channels.rb +31 -0
- data/lib/yt/collections/claim_histories.rb +34 -0
- data/lib/yt/collections/claims.rb +56 -0
- data/lib/yt/collections/content_details.rb +30 -0
- data/lib/yt/collections/content_owner_details.rb +34 -0
- data/lib/yt/collections/content_owners.rb +32 -0
- data/lib/yt/collections/device_flows.rb +23 -0
- data/lib/yt/collections/file_details.rb +30 -0
- data/lib/yt/collections/ids.rb +27 -0
- data/lib/yt/collections/live_streaming_details.rb +30 -0
- data/lib/yt/collections/ownerships.rb +34 -0
- data/lib/yt/collections/partnered_channels.rb +28 -0
- data/lib/yt/collections/players.rb +30 -0
- data/lib/yt/collections/playlist_items.rb +53 -0
- data/lib/yt/collections/playlists.rb +28 -0
- data/lib/yt/collections/policies.rb +28 -0
- data/lib/yt/collections/ratings.rb +23 -0
- data/lib/yt/collections/references.rb +46 -0
- data/lib/yt/collections/related_playlists.rb +43 -0
- data/lib/yt/collections/reports.rb +161 -0
- data/lib/yt/collections/resources.rb +57 -0
- data/lib/yt/collections/resumable_sessions.rb +51 -0
- data/lib/yt/collections/snippets.rb +27 -0
- data/lib/yt/collections/statistics_sets.rb +30 -0
- data/lib/yt/collections/statuses.rb +27 -0
- data/lib/yt/collections/subscribed_channels.rb +46 -0
- data/lib/yt/collections/subscribers.rb +33 -0
- data/lib/yt/collections/subscriptions.rb +50 -0
- data/lib/yt/collections/user_infos.rb +36 -0
- data/lib/yt/collections/video_categories.rb +35 -0
- data/lib/yt/collections/videos.rb +137 -0
- data/lib/yt/config.rb +54 -0
- data/lib/yt/errors/forbidden.rb +13 -0
- data/lib/yt/errors/missing_auth.rb +81 -0
- data/lib/yt/errors/no_items.rb +13 -0
- data/lib/yt/errors/request_error.rb +74 -0
- data/lib/yt/errors/server_error.rb +13 -0
- data/lib/yt/errors/unauthorized.rb +50 -0
- data/lib/yt/models/account.rb +216 -0
- data/lib/yt/models/advertising_options_set.rb +38 -0
- data/lib/yt/models/annotation.rb +132 -0
- data/lib/yt/models/asset.rb +111 -0
- data/lib/yt/models/asset_metadata.rb +38 -0
- data/lib/yt/models/asset_snippet.rb +46 -0
- data/lib/yt/models/authentication.rb +83 -0
- data/lib/yt/models/base.rb +32 -0
- data/lib/yt/models/channel.rb +302 -0
- data/lib/yt/models/claim.rb +156 -0
- data/lib/yt/models/claim_event.rb +67 -0
- data/lib/yt/models/claim_history.rb +29 -0
- data/lib/yt/models/configuration.rb +70 -0
- data/lib/yt/models/content_detail.rb +65 -0
- data/lib/yt/models/content_owner.rb +48 -0
- data/lib/yt/models/content_owner_detail.rb +18 -0
- data/lib/yt/models/description.rb +58 -0
- data/lib/yt/models/device_flow.rb +16 -0
- data/lib/yt/models/file_detail.rb +21 -0
- data/lib/yt/models/id.rb +9 -0
- data/lib/yt/models/iterator.rb +16 -0
- data/lib/yt/models/live_streaming_detail.rb +23 -0
- data/lib/yt/models/match_policy.rb +34 -0
- data/lib/yt/models/ownership.rb +75 -0
- data/lib/yt/models/player.rb +18 -0
- data/lib/yt/models/playlist.rb +218 -0
- data/lib/yt/models/playlist_item.rb +112 -0
- data/lib/yt/models/policy.rb +36 -0
- data/lib/yt/models/policy_rule.rb +124 -0
- data/lib/yt/models/rating.rb +37 -0
- data/lib/yt/models/reference.rb +172 -0
- data/lib/yt/models/resource.rb +136 -0
- data/lib/yt/models/resumable_session.rb +52 -0
- data/lib/yt/models/right_owner.rb +58 -0
- data/lib/yt/models/snippet.rb +50 -0
- data/lib/yt/models/statistics_set.rb +26 -0
- data/lib/yt/models/status.rb +32 -0
- data/lib/yt/models/subscription.rb +38 -0
- data/lib/yt/models/timestamp.rb +13 -0
- data/lib/yt/models/url.rb +90 -0
- data/lib/yt/models/user_info.rb +26 -0
- data/lib/yt/models/video.rb +630 -0
- data/lib/yt/models/video_category.rb +12 -0
- data/lib/yt/request.rb +278 -0
- data/lib/yt/version.rb +3 -0
- data/spec/collections/claims_spec.rb +30 -0
- data/spec/collections/playlist_items_spec.rb +44 -0
- data/spec/collections/playlists_spec.rb +27 -0
- data/spec/collections/policies_spec.rb +30 -0
- data/spec/collections/references_spec.rb +30 -0
- data/spec/collections/reports_spec.rb +30 -0
- data/spec/collections/subscriptions_spec.rb +25 -0
- data/spec/collections/videos_spec.rb +43 -0
- data/spec/errors/forbidden_spec.rb +10 -0
- data/spec/errors/missing_auth_spec.rb +24 -0
- data/spec/errors/no_items_spec.rb +10 -0
- data/spec/errors/request_error_spec.rb +44 -0
- data/spec/errors/server_error_spec.rb +10 -0
- data/spec/errors/unauthorized_spec.rb +10 -0
- data/spec/models/account_spec.rb +138 -0
- data/spec/models/annotation_spec.rb +180 -0
- data/spec/models/asset_spec.rb +20 -0
- data/spec/models/channel_spec.rb +127 -0
- data/spec/models/claim_event_spec.rb +62 -0
- data/spec/models/claim_history_spec.rb +27 -0
- data/spec/models/claim_spec.rb +211 -0
- data/spec/models/configuration_spec.rb +44 -0
- data/spec/models/content_detail_spec.rb +45 -0
- data/spec/models/content_owner_detail_spec.rb +6 -0
- data/spec/models/description_spec.rb +94 -0
- data/spec/models/file_detail_spec.rb +13 -0
- data/spec/models/live_streaming_detail_spec.rb +6 -0
- data/spec/models/ownership_spec.rb +59 -0
- data/spec/models/player_spec.rb +13 -0
- data/spec/models/playlist_item_spec.rb +120 -0
- data/spec/models/playlist_spec.rb +138 -0
- data/spec/models/policy_rule_spec.rb +63 -0
- data/spec/models/policy_spec.rb +41 -0
- data/spec/models/rating_spec.rb +12 -0
- data/spec/models/reference_spec.rb +249 -0
- data/spec/models/request_spec.rb +163 -0
- data/spec/models/resource_spec.rb +57 -0
- data/spec/models/right_owner_spec.rb +71 -0
- data/spec/models/snippet_spec.rb +13 -0
- data/spec/models/statistics_set_spec.rb +13 -0
- data/spec/models/status_spec.rb +13 -0
- data/spec/models/subscription_spec.rb +30 -0
- data/spec/models/url_spec.rb +78 -0
- data/spec/models/video_category_spec.rb +21 -0
- data/spec/models/video_spec.rb +669 -0
- data/spec/requests/as_account/account_spec.rb +125 -0
- data/spec/requests/as_account/authentications_spec.rb +139 -0
- data/spec/requests/as_account/channel_spec.rb +259 -0
- data/spec/requests/as_account/channels_spec.rb +18 -0
- data/spec/requests/as_account/playlist_item_spec.rb +56 -0
- data/spec/requests/as_account/playlist_spec.rb +244 -0
- data/spec/requests/as_account/resource_spec.rb +18 -0
- data/spec/requests/as_account/thumbnail.jpg +0 -0
- data/spec/requests/as_account/video.mp4 +0 -0
- data/spec/requests/as_account/video_spec.rb +408 -0
- data/spec/requests/as_content_owner/account_spec.rb +25 -0
- data/spec/requests/as_content_owner/advertising_options_set_spec.rb +15 -0
- data/spec/requests/as_content_owner/asset_spec.rb +20 -0
- data/spec/requests/as_content_owner/channel_spec.rb +1934 -0
- data/spec/requests/as_content_owner/claim_history_spec.rb +20 -0
- data/spec/requests/as_content_owner/content_owner_spec.rb +241 -0
- data/spec/requests/as_content_owner/match_policy_spec.rb +17 -0
- data/spec/requests/as_content_owner/ownership_spec.rb +25 -0
- data/spec/requests/as_content_owner/playlist_spec.rb +782 -0
- data/spec/requests/as_content_owner/video_spec.rb +1239 -0
- data/spec/requests/as_server_app/channel_spec.rb +74 -0
- data/spec/requests/as_server_app/playlist_item_spec.rb +30 -0
- data/spec/requests/as_server_app/playlist_spec.rb +53 -0
- data/spec/requests/as_server_app/video_spec.rb +58 -0
- data/spec/requests/as_server_app/videos_spec.rb +40 -0
- data/spec/requests/unauthenticated/video_spec.rb +22 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/fail_matcher.rb +15 -0
- data/spec/support/global_hooks.rb +48 -0
- data/yt.gemspec +32 -0
- metadata +416 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yt/collections/resources'
|
2
|
+
require 'yt/models/advertising_options_set'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Collections
|
6
|
+
# Provides methods to interact with a the advertising options of a YouTube video.
|
7
|
+
#
|
8
|
+
# Resources with advertising options are: {Yt::Models::Video videos}.
|
9
|
+
class AdvertisingOptionsSets < Resources
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def attributes_for_new_item(data)
|
14
|
+
{data: data, video_id: @parent.id, auth: @auth}
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Hash] the parameters to submit to YouTube to get video advertising options.
|
18
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/videoAdvertisingOptions/get
|
19
|
+
def list_params
|
20
|
+
super.tap do |params|
|
21
|
+
params[:path] = "/youtube/partner/v1/videoAdvertisingOptions/#{@parent.id}"
|
22
|
+
params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @private
|
27
|
+
# @note AdvertisingOptionsSets 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
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'yt/collections/base'
|
2
|
+
require 'yt/models/annotation'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Collections
|
6
|
+
# Provides methods to interact with a collection of YouTube annotations.
|
7
|
+
#
|
8
|
+
# Resources with annotations are: {Yt::Models::Video videos}.
|
9
|
+
# @note Since there is no (authenticable) API endpoint to retrieve
|
10
|
+
# annotations, only annotations of public videos can be retrieved.
|
11
|
+
class Annotations < Base
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# @return [Hash] the parameters to submit to YouTube to list annotations.
|
16
|
+
# @note YouTube does not provide an API endpoint to get annotations for
|
17
|
+
# a video, so we use an "old-style" URL that YouTube still maintains.
|
18
|
+
def list_params
|
19
|
+
super.tap do |params|
|
20
|
+
params[:response_format] = :xml
|
21
|
+
params[:host] = 'www.youtube.com'
|
22
|
+
params[:path] = '/annotations_invideo'
|
23
|
+
params[:params] = {video_id: @parent.id}
|
24
|
+
params[:camelize_params] = false
|
25
|
+
params[:expected_response] = Net::HTTPOK
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @private
|
30
|
+
# @note Annotations overwrites +next_page+ since the list of annotations
|
31
|
+
# is not paginated API-style, but in its own custom way.
|
32
|
+
def next_page
|
33
|
+
request = Yt::Request.new(list_params).tap do |request|
|
34
|
+
print "#{request.as_curl}\n" if Yt.configuration.developing?
|
35
|
+
end
|
36
|
+
response = request.run
|
37
|
+
@page_token = nil
|
38
|
+
|
39
|
+
document = response.body.fetch('document', {})['annotations'] || {}
|
40
|
+
Array.wrap document.fetch 'annotation', []
|
41
|
+
rescue Yt::Error => error
|
42
|
+
expected?(error) ? [] : raise(error)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @private
|
46
|
+
# @note Annotations overwrites +total_results+ since `items_key` is
|
47
|
+
# not `items` for annotations.
|
48
|
+
# @todo Remove this function by extracting the keys used by annotations
|
49
|
+
# in a method and reusing them both in `next_page` and `total_results`.
|
50
|
+
def total_results
|
51
|
+
count
|
52
|
+
end
|
53
|
+
|
54
|
+
# Since there is no API endpoint, retrieving annotations of unknown
|
55
|
+
# videos or of private videos (to which YouTube responds with 403)
|
56
|
+
# should not raise an error, but simply not return any annotation.
|
57
|
+
def expected?(error)
|
58
|
+
error.is_a? Yt::Errors::Forbidden
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'yt/collections/base'
|
2
|
+
require 'yt/models/asset'
|
3
|
+
require 'yt/models/asset_snippet'
|
4
|
+
|
5
|
+
module Yt
|
6
|
+
module Collections
|
7
|
+
# Provides methods to interact with a collection of Content ID assets.
|
8
|
+
#
|
9
|
+
# Resources with assets are: {Yt::Models::ContentOwner content owners}.
|
10
|
+
class Assets < Base
|
11
|
+
def insert(attributes = {})
|
12
|
+
params = {on_behalf_of_content_owner: @auth.owner_name}
|
13
|
+
do_insert(params: params, body: attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def new_item(data)
|
19
|
+
klass = (data["kind"] == "youtubePartner#assetSnippet") ? Yt::AssetSnippet : Yt::Asset
|
20
|
+
klass.new attributes_for_new_item(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Hash] the parameters to submit to YouTube to list assets
|
24
|
+
# owned by the content owner.
|
25
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/assets/list
|
26
|
+
def list_params
|
27
|
+
super.tap do |params|
|
28
|
+
params[:path] = assets_path
|
29
|
+
params[:params] = assets_params
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def assets_params
|
34
|
+
apply_where_params! on_behalf_of_content_owner: @auth.owner_name
|
35
|
+
end
|
36
|
+
|
37
|
+
# @private
|
38
|
+
# @todo: This is one of three places outside of base.rb where @where_params
|
39
|
+
# is accessed; it should be replaced with a filter on params instead.
|
40
|
+
def assets_path
|
41
|
+
@where_params ||= {}
|
42
|
+
if @where_params.empty? || @where_params.key?(:id)
|
43
|
+
'/youtube/partner/v1/assets'
|
44
|
+
else
|
45
|
+
'/youtube/partner/v1/assetSearch'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Hash] the parameters to submit to YouTube to add a asset.
|
50
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/assets/insert
|
51
|
+
def insert_params
|
52
|
+
super.tap do |params|
|
53
|
+
params[:path] = '/youtube/partner/v1/assets'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'yt/collections/base'
|
2
|
+
require 'yt/models/authentication'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Collections
|
6
|
+
# @private
|
7
|
+
class Authentications < Base
|
8
|
+
attr_accessor :auth_params
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def attributes_for_new_item(data)
|
13
|
+
data['refresh_token'] ||= auth_params[:refresh_token]
|
14
|
+
data
|
15
|
+
end
|
16
|
+
|
17
|
+
def list_params
|
18
|
+
super.tap do |params|
|
19
|
+
params[:host] = 'accounts.google.com'
|
20
|
+
params[:path] = '/o/oauth2/token'
|
21
|
+
params[:request_format] = :form
|
22
|
+
params[:method] = :post
|
23
|
+
params[:auth] = nil
|
24
|
+
params[:body] = auth_params
|
25
|
+
params[:camelize_body] = false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def more_pages?
|
30
|
+
auth_params.values.all?
|
31
|
+
end
|
32
|
+
|
33
|
+
def next_page
|
34
|
+
request = Yt::Request.new(list_params).tap do |request|
|
35
|
+
print "#{request.as_curl}\n" if Yt.configuration.developing?
|
36
|
+
end
|
37
|
+
Array.wrap request.run.body
|
38
|
+
rescue Yt::Error => error
|
39
|
+
expected?(error) ? [] : raise(error)
|
40
|
+
end
|
41
|
+
|
42
|
+
def expected?(error)
|
43
|
+
error.kind == 'invalid_grant'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'yt/actions/delete_all'
|
2
|
+
require 'yt/actions/insert'
|
3
|
+
require 'yt/actions/list'
|
4
|
+
require 'yt/errors/request_error'
|
5
|
+
|
6
|
+
module Yt
|
7
|
+
module Collections
|
8
|
+
class Base
|
9
|
+
include Actions::DeleteAll
|
10
|
+
include Actions::Insert
|
11
|
+
include Actions::List
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@parent = options[:parent]
|
15
|
+
@auth = options[:auth]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.of(parent)
|
19
|
+
new parent: parent, auth: parent.auth
|
20
|
+
end
|
21
|
+
|
22
|
+
# Adds requirements to the collection in order to limit the result of
|
23
|
+
# List methods to only items that match the requirements.
|
24
|
+
#
|
25
|
+
# Under the hood, all the requirements are passed to the YouTube API
|
26
|
+
# as query parameters, after transforming the keys to camel-case.
|
27
|
+
#
|
28
|
+
# To know which requirements are available for each collection, check
|
29
|
+
# the documentation of the corresponding YouTube API endpoint.
|
30
|
+
# For instance the list of valid requirements to filter a list of videos
|
31
|
+
# are at https://developers.google.com/youtube/v3/docs/search/list
|
32
|
+
#
|
33
|
+
# @example Return the first video of a channel (no requirements):
|
34
|
+
# video.channels.first
|
35
|
+
# @example Return the first long video of a channel by video count:
|
36
|
+
# video.channels.where(order: 'viewCount', video_duration: 'long').first
|
37
|
+
def where(requirements = {})
|
38
|
+
self.tap do
|
39
|
+
@items = []
|
40
|
+
@where_params = requirements
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def includes(*relationships)
|
45
|
+
self.tap do
|
46
|
+
@items = []
|
47
|
+
@included_relationships = relationships
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def apply_where_params!(params = {})
|
54
|
+
params.merge!(@where_params ||= {})
|
55
|
+
end
|
56
|
+
|
57
|
+
def included_relationships
|
58
|
+
@included_relationships || []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yt/collections/resources'
|
2
|
+
|
3
|
+
module Yt
|
4
|
+
module Collections
|
5
|
+
# Provides methods to interact with a collection of YouTube channels.
|
6
|
+
#
|
7
|
+
# Resources with channels are: {Yt::Models::Account accounts}.
|
8
|
+
class Channels < Resources
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def attributes_for_new_item(data)
|
13
|
+
super(data).tap do |attributes|
|
14
|
+
attributes[:statistics] = data['statistics']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Hash] the parameters to submit to YouTube to list channels.
|
19
|
+
# @see https://developers.google.com/youtube/v3/docs/channels/list
|
20
|
+
def list_params
|
21
|
+
super.tap{|params| params[:params] = channels_params}
|
22
|
+
end
|
23
|
+
|
24
|
+
def channels_params
|
25
|
+
params = resources_params
|
26
|
+
params.merge! mine: true if @parent
|
27
|
+
apply_where_params! params
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -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
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'yt/collections/base'
|
2
|
+
require 'yt/models/claim'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Collections
|
6
|
+
# Provides methods to interact with a collection of Content ID claims.
|
7
|
+
#
|
8
|
+
# Resources with claims are: {Yt::Models::ContentOwner content owners}.
|
9
|
+
class Claims < Base
|
10
|
+
def insert(attributes = {})
|
11
|
+
underscore_keys! attributes
|
12
|
+
body = attributes.slice :asset_id, :video_id, :content_type, :policy
|
13
|
+
body[:policy] = {id: attributes[:policy_id]} if attributes[:policy_id]
|
14
|
+
params = attributes.slice(:is_manual_claim).merge({on_behalf_of_content_owner: @auth.owner_name})
|
15
|
+
do_insert(params: params, body: body)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# @return [Hash] the parameters to submit to YouTube to list claims
|
21
|
+
# administered by the content owner.
|
22
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/claims/list
|
23
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/claimSearch/list
|
24
|
+
def list_params
|
25
|
+
super.tap do |params|
|
26
|
+
params[:path] = claims_path
|
27
|
+
params[:params] = claims_params
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash] the parameters to submit to YouTube to add a claim.
|
32
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/claims/insert
|
33
|
+
def insert_params
|
34
|
+
super.tap do |params|
|
35
|
+
params[:path] = '/youtube/partner/v1/claims'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def claims_params
|
40
|
+
apply_where_params! on_behalf_of_content_owner: @parent.owner_name
|
41
|
+
end
|
42
|
+
|
43
|
+
# @private
|
44
|
+
# @todo: This is one of three places outside of base.rb where @where_params
|
45
|
+
# is accessed; it should be replaced with a filter on params instead.
|
46
|
+
def claims_path
|
47
|
+
@where_params ||= {}
|
48
|
+
if @where_params.empty? || @where_params.key?(:id)
|
49
|
+
'/youtube/partner/v1/claims'
|
50
|
+
else
|
51
|
+
'/youtube/partner/v1/claimSearch'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'yt/collections/base'
|
2
|
+
require 'yt/models/content_detail'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Collections
|
6
|
+
# @private
|
7
|
+
class ContentDetails < Base
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def attributes_for_new_item(data)
|
12
|
+
{data: data['contentDetails']}
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Hash] the parameters to submit to YouTube to get the
|
16
|
+
# content detail of a resource, for instance a video.
|
17
|
+
# @see https://developers.google.com/youtube/v3/docs/videos#resource
|
18
|
+
def list_params
|
19
|
+
super.tap do |params|
|
20
|
+
params[:params] = content_details_params
|
21
|
+
params[:path] = '/youtube/v3/videos'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def content_details_params
|
26
|
+
{max_results: 50, part: 'contentDetails', id: @parent.id}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yt/collections/base'
|
2
|
+
require 'yt/models/content_owner_detail'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Collections
|
6
|
+
# @private
|
7
|
+
class ContentOwnerDetails < Base
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def attributes_for_new_item(data)
|
12
|
+
{data: data['contentOwnerDetails']}
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Hash] the parameters to submit to YouTube to get the
|
16
|
+
# content owner detail of a channel.
|
17
|
+
# @see https://developers.google.com/youtube/v3/docs/channels#contentOwnerDetails
|
18
|
+
def list_params
|
19
|
+
super.tap do |params|
|
20
|
+
params[:params] = content_owner_details_params
|
21
|
+
params[:path] = '/youtube/v3/channels'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def content_owner_details_params
|
26
|
+
@parent.content_owner_details_params.tap do |params|
|
27
|
+
params[:max_results] = 50
|
28
|
+
params[:part] = 'contentOwnerDetails'
|
29
|
+
params[:id] = @parent.id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|