Skip to content

Commit

Permalink
Add Claims#list and ClaimSearch#list
Browse files Browse the repository at this point in the history
  • Loading branch information
stavro committed Jul 22, 2014
1 parent 7859af9 commit d8045ad
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ Use [Yt::ContentOwner](http://rubydoc.info/github/Fullscreen/yt/master/Yt/Models

* authenticate as a YouTube content owner
* list the channels partnered with a YouTube content owner
* list the claims administered by the content owner
* search the claims administered by the content owner

```ruby
# Content owners can be initialized with access token, refresh token or an authorization code
content_owner = Yt::ContentOwner.new owner_name: 'CMSname', access_token: 'ya29.1.ABCDEFGHIJ'

content_owner.partnered_channels.count #=> 12
content_owner.partnered_channels.first #=> #<Yt::Models::Channel @id=...>
content_owner.claims.first #=> => #<Yt::Models::Claim ...>
content_owner.claim_searches.where(videoId: 'dQw4w9WgXcQ,btPJPFnesV4').first #=> => #<Yt::Models::Claim ...>
```

*All the above methods require authentication (see below).*
Expand Down
1 change: 1 addition & 0 deletions lib/yt.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'yt/config'
require 'yt/models/account'
require 'yt/models/channel'
require 'yt/models/claim'
require 'yt/models/content_owner'
require 'yt/models/playlist'
require 'yt/models/playlist_item'
Expand Down
22 changes: 22 additions & 0 deletions lib/yt/collections/claim_searches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Yt
module Collections
class ClaimSearches < Base

private

def new_item(data)
Yt::Models::Claim.new data: data
end

# @return [Hash] the parameters to submit to YouTube to list claims that match the search criteria.
# @see https://developers.google.com/youtube/partner/docs/v1/claimSearch/list
def list_params
super.tap do |params|
params[:path] = "/youtube/partner/v1/claimSearch"
params[:params] = {onBehalfOfContentOwner: @parent.owner_name}.merge(@extra_params || {})
end
end

end
end
end
22 changes: 22 additions & 0 deletions lib/yt/collections/claims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Yt
module Collections
class Claims < Base

private

def new_item(data)
Yt::Claim.new data: data
end

# @return [Hash] the parameters to submit to YouTube to list claims administered by the content owner.
# @see https://developers.google.com/youtube/partner/docs/v1/claims/list
def list_params
super.tap do |params|
params[:path] = "/youtube/partner/v1/claims"
params[:params] = {onBehalfOfContentOwner: @parent.owner_name}.merge(@extra_params || {})
end
end

end
end
end
56 changes: 56 additions & 0 deletions lib/yt/models/claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'yt/models/base'

module Yt
module Models
class Claim < Base
def initialize(options = {})
@data = options[:data]
end

def id
@data["id"]
end

def asset_id
@data["assetId"]
end

def video_id
@data["videoId"]
end

def status
@data["status"]
end

def policy
@data["policy"]
end

def content_type
@data["contentType"]
end

def time_created
@data["timeCreated"]
end

def block_outside_ownership
@data["blockOutsideOwnership"]
end

def origin
@data["origin"]
end

def video_views
@data["videoViews"]
end

def video_title
@data["videoTitle"]
end

end
end
end
8 changes: 8 additions & 0 deletions lib/yt/models/content_owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class ContentOwner < Account
# @return [Yt::Collection::PartneredChannels] the channels managed by the CMS account.
has_many :partnered_channels

# @!attribute [r] claims
# @return [Yt::Collection::Claim] the claims administered by the content owner.
has_many :claims

# @!attribute [r] claim_searches
# @return [Yt::Collection::ClaimSearches] the claims that match search criteria.
has_many :claim_searches

def initialize(options = {})
super options
@owner_name = options[:owner_name]
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/as_content_owner/content_owner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
# NOTE: Uncomment once size does not runs through *all* the pages
# it { expect($content_owner.partnered_channels.size).to be > 0 }
it { expect($content_owner.partnered_channels.first).to be_a Yt::Channel }
it { expect($content_owner.claims.first).to be_a Yt::Claim }
it { expect($content_owner.claim_searches.where(status: 'active').first).to be_a Yt::Claim }
end

0 comments on commit d8045ad

Please sign in to comment.