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,112 @@
|
|
1
|
+
require 'yt/models/resource'
|
2
|
+
|
3
|
+
module Yt
|
4
|
+
module Models
|
5
|
+
# Provides methods to interact with YouTube playlist items.
|
6
|
+
# @see https://developers.google.com/youtube/v3/docs/playlistItems
|
7
|
+
class PlaylistItem < Resource
|
8
|
+
|
9
|
+
### SNIPPET ###
|
10
|
+
|
11
|
+
# @!attribute [r] title
|
12
|
+
# @return [String] the item’s title.
|
13
|
+
delegate :title, to: :snippet
|
14
|
+
|
15
|
+
# @!attribute [r] description
|
16
|
+
# @return [String] the item’s description.
|
17
|
+
delegate :description, to: :snippet
|
18
|
+
|
19
|
+
# @!method thumbnail_url(size = :default)
|
20
|
+
# Returns the URL of the item’s thumbnail.
|
21
|
+
# @param [Symbol, String] size The size of the item’s thumbnail.
|
22
|
+
# @return [String] if +size+ is +default+, the URL of a 120x90px image.
|
23
|
+
# @return [String] if +size+ is +medium+, the URL of a 320x180px image.
|
24
|
+
# @return [String] if +size+ is +high+, the URL of a 480x360px image.
|
25
|
+
# @return [nil] if the +size+ is not +default+, +medium+ or +high+.
|
26
|
+
delegate :thumbnail_url, to: :snippet
|
27
|
+
|
28
|
+
# @!attribute [r] published_at
|
29
|
+
# @return [Time] the time that the item was added to the playlist.
|
30
|
+
delegate :published_at, to: :snippet
|
31
|
+
|
32
|
+
# @!attribute [r] channel_id
|
33
|
+
# @return [String] the ID of the channel that the item belongs to.
|
34
|
+
delegate :channel_id, to: :snippet
|
35
|
+
|
36
|
+
# @!attribute [r] channel_title
|
37
|
+
# @return [String] the title of the channel that the item belongs to.
|
38
|
+
delegate :channel_title, to: :snippet
|
39
|
+
|
40
|
+
# @!attribute [r] playlist_id
|
41
|
+
# @return [String] the ID of the playlist that the item is in.
|
42
|
+
delegate :playlist_id, to: :snippet
|
43
|
+
|
44
|
+
# @return [String] the ID of the video referred by the item.
|
45
|
+
def video_id
|
46
|
+
snippet.resource_id['videoId']
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Integer] the order in which the item appears in a playlist.
|
50
|
+
# The value is zero-based, so the first item has a position of 0.
|
51
|
+
def position
|
52
|
+
ensure_complete_snippet :position
|
53
|
+
end
|
54
|
+
|
55
|
+
### ACTIONS (UPLOAD, UPDATE, DELETE) ###
|
56
|
+
|
57
|
+
# Deletes the playlist item.
|
58
|
+
# @return [Boolean] whether the playlist item does not exist anymore.
|
59
|
+
# @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an
|
60
|
+
# authenticated Yt::Account with permissions to delete the item.
|
61
|
+
def delete(options = {})
|
62
|
+
do_delete {@id = nil}
|
63
|
+
!exists?
|
64
|
+
end
|
65
|
+
|
66
|
+
# Updates the attributes of a playlist item.
|
67
|
+
# @return [Boolean] whether the item was successfully updated.
|
68
|
+
# @raise [Yt::Errors::Unauthorized] if {Resource#auth auth} is not an
|
69
|
+
# authenticated Yt::Account with permissions to update the item.
|
70
|
+
# @param [Hash] attributes the attributes to update.
|
71
|
+
# @option attributes [Integer] the order in which the item should appear
|
72
|
+
# in a playlist. The value is zero-based, so the first position of 0.
|
73
|
+
def update(attributes = {})
|
74
|
+
super
|
75
|
+
end
|
76
|
+
|
77
|
+
### ASSOCIATIONS ###
|
78
|
+
|
79
|
+
# @return [Yt::Models::Video] the video referred by the item.
|
80
|
+
def video
|
81
|
+
@video ||= Video.new id: video_id, auth: @auth if video_id
|
82
|
+
end
|
83
|
+
|
84
|
+
### PRIVATE API ###
|
85
|
+
|
86
|
+
# @private
|
87
|
+
def exists?
|
88
|
+
!@id.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
# @private
|
92
|
+
# Override Resource's new to set video if the response includes it
|
93
|
+
def initialize(options = {})
|
94
|
+
super options
|
95
|
+
@video = options[:video] if options[:video]
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def resource_id
|
101
|
+
{kind: 'youtube#video', videoId: video_id}
|
102
|
+
end
|
103
|
+
|
104
|
+
# @see https://developers.google.com/youtube/v3/docs/playlistItems/update
|
105
|
+
def update_parts
|
106
|
+
keys = [:position, :playlist_id, :resource_id]
|
107
|
+
snippet = {keys: keys, required: true}
|
108
|
+
{snippet: snippet}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'yt/models/base'
|
2
|
+
require 'yt/models/policy_rule'
|
3
|
+
|
4
|
+
module Yt
|
5
|
+
module Models
|
6
|
+
# Provides methods to interact with YouTube ContentID policies.
|
7
|
+
# A policy resource specifies rules that define a particular usage or
|
8
|
+
# match policy that a partner can associate with an asset or claim.
|
9
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/policies
|
10
|
+
class Policy < Base
|
11
|
+
def initialize(options = {})
|
12
|
+
@data = options[:data]
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String] the ID that YouTube assigns and uses to uniquely
|
16
|
+
# identify the policy.
|
17
|
+
has_attribute :id
|
18
|
+
|
19
|
+
# @return [String] the policy’s name.
|
20
|
+
has_attribute :name
|
21
|
+
|
22
|
+
# @return [String] the policy’s description.
|
23
|
+
has_attribute :description
|
24
|
+
|
25
|
+
# @return [String] the time the policy was updated.
|
26
|
+
has_attribute :updated_at, type: Time, from: :time_updated
|
27
|
+
|
28
|
+
# @return [Array<PolicyRule>] a list of rules that specify the action
|
29
|
+
# that YouTube should take and may optionally specify the conditions
|
30
|
+
# under which that action is enforced.
|
31
|
+
has_attribute :rules do |rules|
|
32
|
+
rules.map{|rule| PolicyRule.new data: rule}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'yt/models/base'
|
2
|
+
|
3
|
+
module Yt
|
4
|
+
module Models
|
5
|
+
# Provides methods to interact with YouTube ContentID policy rules.
|
6
|
+
# Rules that specify the action that YouTube should take and may optionally
|
7
|
+
# specify the conditions under which that action is enforced.
|
8
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/policies
|
9
|
+
class PolicyRule < Base
|
10
|
+
def initialize(options = {})
|
11
|
+
@data = options[:data]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return the policy that YouTube should enforce if the rule’s conditions
|
15
|
+
# are all valid for an asset or for an attempt to view that asset on
|
16
|
+
# YouTube. Possible values are: +'block'+, +'monetize'+, +'takedown'+,
|
17
|
+
# +'track'+.
|
18
|
+
# @return [String] the policy that YouTube should enforce.
|
19
|
+
has_attribute :action
|
20
|
+
|
21
|
+
# @return [Array] A list of additional actions that YouTube should take if
|
22
|
+
# the conditions in the rule are met. Possible values are: +'review'+.
|
23
|
+
has_attribute :subaction
|
24
|
+
|
25
|
+
# Return the list of territories where the policy applies.
|
26
|
+
# Each territory is an ISO 3166 two-letter country code.
|
27
|
+
# YouTube determines whether the condition is satisfied based on the
|
28
|
+
# user’s location.
|
29
|
+
# @return [Array<String>] the territories where the policy applies.
|
30
|
+
# @example (with 'block' action) only block a video for U.S. users:
|
31
|
+
# included_territories #=> ['us']
|
32
|
+
def included_territories
|
33
|
+
territories_type == 'include' ? territories : []
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return the list of territories where the policy does not apply.
|
37
|
+
# Each territory is an ISO 3166 two-letter country code.
|
38
|
+
# YouTube determines whether the condition is satisfied based on the
|
39
|
+
# user’s location.
|
40
|
+
# @return [Array<String>] the territories where the policy does not apply.
|
41
|
+
# @example (with 'block' action) only allow U.S. users to view a video:
|
42
|
+
# excluded_territories #=> ['us']
|
43
|
+
def excluded_territories
|
44
|
+
territories_type == 'exclude' ? territories : []
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Array<Hash<Symbol, Float>>] the intervals of time the user-
|
48
|
+
# or partner-uploaded content needs to match a reference file for the
|
49
|
+
# rule to apply. :low is the minimum (inclusive) allowed value and
|
50
|
+
# :high is the maximum (inclusive) allowed value for the rule to apply.
|
51
|
+
# @example videos that match the reference for 20 to 30 seconds:
|
52
|
+
# match_duration #= [{low: 20.0, high: 30.0}]
|
53
|
+
def match_duration
|
54
|
+
match_duration_list.map{|r| low_and_high r}
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Array<Hash<Symbol, Float>>] the intervals of percentages the
|
58
|
+
# user- or partner-uploaded content needs to match a reference file for
|
59
|
+
# the rule to apply. :low is the minimum (inclusive) allowed value and
|
60
|
+
# :high is the maximum (inclusive) allowed value for the rule to apply.
|
61
|
+
# @example videos that match the reference for 40%~50% of their duration:
|
62
|
+
# match_percent #= [{low: 40.0, high: 50.0}]
|
63
|
+
def match_percent
|
64
|
+
match_percent_list.map{|r| low_and_high r}
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array<Hash<Symbol, Float>>] the intervals of duration that the
|
68
|
+
# reference must have for the rule to apply. :low is the minimum
|
69
|
+
# (inclusive) allowed value, :high is the maximum (inclusive) allowed
|
70
|
+
# value for the rule to apply.
|
71
|
+
# @example references that are between 20 and 30 seconds:
|
72
|
+
# reference_duration #= [{low: 20.0, high: 30.0}]
|
73
|
+
def reference_duration
|
74
|
+
reference_duration_list.map{|r| low_and_high r}
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Array<Hash<Symbol, Float>>] the intervals of percentages the
|
78
|
+
# reference file needs to match the user- or partner-uploaded content
|
79
|
+
# for the rule to apply. :low is the minimum (inclusive) allowed value,
|
80
|
+
# :high is the maximum (inclusive) allowed value for the rule to apply.
|
81
|
+
# @example videos that match either 0%~10% or 40%~50% of a reference:
|
82
|
+
# reference_percent #= [{low: 0.0, high: 10.0}, {low: 40.0, high: 50.0}]
|
83
|
+
def reference_percent
|
84
|
+
reference_percent_list.map{|r| low_and_high r}
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
has_attribute :conditions, default: {}
|
90
|
+
|
91
|
+
def territories_object
|
92
|
+
conditions.fetch 'requiredTerritories', {}
|
93
|
+
end
|
94
|
+
|
95
|
+
def territories_type
|
96
|
+
territories_object['type']
|
97
|
+
end
|
98
|
+
|
99
|
+
def territories
|
100
|
+
territories_object['territories']
|
101
|
+
end
|
102
|
+
|
103
|
+
def match_duration_list
|
104
|
+
conditions.fetch 'matchDuration', []
|
105
|
+
end
|
106
|
+
|
107
|
+
def match_percent_list
|
108
|
+
conditions.fetch 'matchPercent', []
|
109
|
+
end
|
110
|
+
|
111
|
+
def reference_duration_list
|
112
|
+
conditions.fetch 'referenceDuration', []
|
113
|
+
end
|
114
|
+
|
115
|
+
def reference_percent_list
|
116
|
+
conditions.fetch 'referencePercent', []
|
117
|
+
end
|
118
|
+
|
119
|
+
def low_and_high(range)
|
120
|
+
{low: range['low'], high: range['high']}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'yt/models/base'
|
2
|
+
|
3
|
+
module Yt
|
4
|
+
module Models
|
5
|
+
# @private
|
6
|
+
# Provides methods to modify the rating of a video on YouTube.
|
7
|
+
# @see https://developers.google.com/youtube/v3/docs/videos/rate
|
8
|
+
# @see https://developers.google.com/youtube/v3/docs/videos/getRating
|
9
|
+
class Rating < Base
|
10
|
+
# @return [Symbol, nil] the rating of a video (if present).
|
11
|
+
# Possible values are: +:dislike+, +:like+, +:none+, +:unspecified+.
|
12
|
+
attr_reader :rating
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@rating = options[:rating].to_sym if options[:rating]
|
16
|
+
@video_id = options[:video_id]
|
17
|
+
@auth = options[:auth]
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(new_rating)
|
21
|
+
do_update(params: {rating: new_rating}) {@rating = new_rating}
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# @return [Hash] the parameters to submit to YouTube to update a rating.
|
27
|
+
# @see https://developers.google.com/youtube/v3/docs/videos/rate
|
28
|
+
def update_params
|
29
|
+
super.tap do |params|
|
30
|
+
params[:method] = :post
|
31
|
+
params[:path] = '/youtube/v3/videos/rate'
|
32
|
+
params[:params] = {id: @video_id}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'yt/models/base'
|
2
|
+
|
3
|
+
module Yt
|
4
|
+
module Models
|
5
|
+
# Provides methods to interact with YouTube ContentID references.
|
6
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/references
|
7
|
+
class Reference < Base
|
8
|
+
def initialize(options = {})
|
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?
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String] the ID that YouTube assigns and uses to uniquely
|
28
|
+
# identify the reference.
|
29
|
+
has_attribute :id
|
30
|
+
|
31
|
+
# @return [String] the ID that uniquely identifies the asset that the
|
32
|
+
# reference is associated with.
|
33
|
+
has_attribute :asset_id
|
34
|
+
|
35
|
+
# @return [Float] The length of the reference in seconds
|
36
|
+
has_attribute :length
|
37
|
+
|
38
|
+
# @return [String] the ID of the source video. This field is only present
|
39
|
+
# if the reference was created by associating an asset with an existing
|
40
|
+
# YouTube video that was uploaded to a YouTube channel linked to your
|
41
|
+
# CMS account.
|
42
|
+
has_attribute :video_id
|
43
|
+
|
44
|
+
# @return [String] the claim ID that represents the resulting association
|
45
|
+
# between the asset and the video. This field is only present if the
|
46
|
+
# reference was created by associating an asset with an existing
|
47
|
+
# YouTube video that was uploaded to a YouTube channel linked to your
|
48
|
+
# CMS account.
|
49
|
+
has_attribute :claim_id
|
50
|
+
|
51
|
+
# @return [boolean] whether or not the reference content is included in
|
52
|
+
# YouTube's AudioSwap program. Set this field's value to true to
|
53
|
+
# indicate that the reference content should be included in YouTube's
|
54
|
+
# AudioSwap program.
|
55
|
+
has_attribute :audioswap_enabled?, from: :audioswap_enabled
|
56
|
+
|
57
|
+
# @return [boolean] should the reference be used to generate claims. Set
|
58
|
+
# this value to true to indicate that the reference should not be used
|
59
|
+
# to generate claims. This field is only used on AudioSwap references.
|
60
|
+
has_attribute :ignore_fp_match?, from: :ignore_fp_match
|
61
|
+
|
62
|
+
# @return [Boolean] the urgent status of the reference file.
|
63
|
+
# Set this value to true to indicate that YouTube should prioritize
|
64
|
+
# Content ID processing for a video file. YouTube processes urgent
|
65
|
+
# video files before other files that are not marked as urgent.
|
66
|
+
# This setting is primarily used for videos of live events or other
|
67
|
+
# videos that require time-sensitive processing.
|
68
|
+
# The sooner YouTube completes Content ID processing for a video, the
|
69
|
+
# sooner YouTube can match user-uploaded videos to that video.
|
70
|
+
has_attribute :urgent?, from: :urgent
|
71
|
+
|
72
|
+
# @return [String] An explanation of how a reference entered its current
|
73
|
+
# state. This value is only present if the reference’s status is either
|
74
|
+
# inactive or deleted.
|
75
|
+
has_attribute :status_reason
|
76
|
+
|
77
|
+
# @return [String] The ID that uniquely identifies the reference that
|
78
|
+
# this reference duplicates. This field is only present if the
|
79
|
+
# reference’s status is duplicate_on_hold.
|
80
|
+
has_attribute :duplicate_leader
|
81
|
+
|
82
|
+
# Status
|
83
|
+
|
84
|
+
# @return [String] the reference’s status. Possible values are:
|
85
|
+
# +'activating'+, +'active'+, +'checking'+, +'computing_fingerprint'+,
|
86
|
+
# +'deleted'+, +'duplicate_on_hold'+, +'inactive'+,
|
87
|
+
# +'live_streaming_processing'+, +'urgent_reference_processing'+.
|
88
|
+
has_attribute :status
|
89
|
+
|
90
|
+
# @return [Boolean] whether the reference is pending.
|
91
|
+
def activating?
|
92
|
+
status == 'activating'
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [Boolean] whether the reference is active.
|
96
|
+
def active?
|
97
|
+
status == 'active'
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [Boolean] whether the reference is being compared to existing
|
101
|
+
# references to identify any reference conflicts that might exist.
|
102
|
+
def checking?
|
103
|
+
status == 'checking'
|
104
|
+
end
|
105
|
+
|
106
|
+
# @return [Boolean] whether the reference’s fingerprint is being
|
107
|
+
# computed.
|
108
|
+
def computing_fingerprint?
|
109
|
+
status == 'computing_fingerprint'
|
110
|
+
end
|
111
|
+
|
112
|
+
# @return [Boolean] whether the reference is deleted.
|
113
|
+
def deleted?
|
114
|
+
status == 'deleted'
|
115
|
+
end
|
116
|
+
|
117
|
+
# @return [Boolean] whether the reference iis a duplicate and is on hold.
|
118
|
+
def duplicate_on_hold?
|
119
|
+
status == 'duplicate_on_hold'
|
120
|
+
end
|
121
|
+
|
122
|
+
# @return [Boolean] whether the reference is inactive.
|
123
|
+
def inactive?
|
124
|
+
status == 'inactive'
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [Boolean] whether the reference is being processed from a live
|
128
|
+
# video stream.
|
129
|
+
def live_streaming_processing?
|
130
|
+
status == 'live_streaming_processing'
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [Boolean] whether the reference is urgent_reference_processing.
|
134
|
+
def urgent_reference_processing?
|
135
|
+
status == 'urgent_reference_processing'
|
136
|
+
end
|
137
|
+
|
138
|
+
# Content Type
|
139
|
+
|
140
|
+
# Returns the audiovisual portion of the referenced content.
|
141
|
+
# @return [String] the audiovisual portion of the referenced content.
|
142
|
+
# Possible values are: +'audio'+, +'audiovisual'+, +'video'+.
|
143
|
+
has_attribute :content_type
|
144
|
+
|
145
|
+
# @return [Boolean] whether the reference covers only the audio.
|
146
|
+
def audio?
|
147
|
+
content_type == 'audio'
|
148
|
+
end
|
149
|
+
|
150
|
+
# @return [Boolean] whether the reference covers only the video.
|
151
|
+
def video?
|
152
|
+
content_type == 'video'
|
153
|
+
end
|
154
|
+
|
155
|
+
# @return [Boolean] whether the reference covers both audio and video.
|
156
|
+
def audiovisual?
|
157
|
+
content_type == 'audiovisual'
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/references/update
|
163
|
+
def update_params
|
164
|
+
super.tap do |params|
|
165
|
+
params[:expected_response] = Net::HTTPOK
|
166
|
+
params[:path] = "/youtube/partner/v1/references/#{id}"
|
167
|
+
params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|