class Yt::Collections::Claims
Provides methods to interact with a collection of Content ID claims.
Resources
with claims are: {Yt::Models::ContentOwner content owners}.
Public Instance Methods
insert(attributes = {})
click to toggle source
# File lib/yt/collections/claims.rb, line 10 def insert(attributes = {}) underscore_keys! attributes body = attributes.slice :asset_id, :video_id, :content_type, :policy body[:policy] = {id: attributes[:policy_id]} if attributes[:policy_id] body[:match_info] = match_attributes(attributes[:match_info]) if attributes[:match_info] params = attributes.slice(:is_manual_claim).merge({on_behalf_of_content_owner: @auth.owner_name}) do_insert(params: params, body: body) end
Private Instance Methods
attributes_for_new_item(data)
click to toggle source
# File lib/yt/collections/claims.rb, line 21 def attributes_for_new_item(data) {}.tap do |attributes| attributes[:id] = data['id'] attributes[:auth] = @auth attributes[:data] = data attributes[:asset] = data['asset'] end end
claims_params()
click to toggle source
# File lib/yt/collections/claims.rb, line 68 def claims_params apply_where_params! on_behalf_of_content_owner: @parent.owner_name end
claims_path()
click to toggle source
@private @todo: This is one of three places outside of base.rb where @where_params
is accessed; it should be replaced with a filter on params instead.
# File lib/yt/collections/claims.rb, line 75 def claims_path @where_params ||= {} if @where_params.empty? || @where_params.key?(:id) '/youtube/partner/v1/claims' else '/youtube/partner/v1/claimSearch' end end
eager_load_items_from(items)
click to toggle source
Calls superclass method
Yt::Actions::List#eager_load_items_from
# File lib/yt/collections/claims.rb, line 30 def eager_load_items_from(items) if included_relationships.include? :asset asset_ids = items.map{|a| a.values_at 'videoId', 'assetId'}.to_h.values conditions = { id: asset_ids.join(','), fetch_metadata: 'effective' } assets = @parent.assets.where conditions items.each do |item| item['asset'] = assets.find { |a| a.id == item['assetId'] } end end super end
insert_params()
click to toggle source
@return [Hash] the parameters to submit to YouTube to add a claim. @see developers.google.com/youtube/partner/docs/v1/claims/insert
Calls superclass method
Yt::Actions::Insert#insert_params
# File lib/yt/collections/claims.rb, line 62 def insert_params super.tap do |params| params[:path] = '/youtube/partner/v1/claims' end end
list_params()
click to toggle source
@return [Hash] the parameters to submit to YouTube to list claims
administered by the content owner.
@see developers.google.com/youtube/partner/docs/v1/claims/list @see developers.google.com/youtube/partner/docs/v1/claimSearch/list
Calls superclass method
Yt::Actions::List#list_params
# File lib/yt/collections/claims.rb, line 53 def list_params super.tap do |params| params[:path] = claims_path params[:params] = claims_params end end
match_attributes(attributes = {})
click to toggle source
# File lib/yt/collections/claims.rb, line 42 def match_attributes(attributes = {}) segments = attributes[:match_segments].map do |segment| { manual_segment: (segment[:manual_segment] || segment).slice(:start, :finish) } end { matchSegments: segments } end