yt 0.32.3 → 0.33.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -2
- data/.travis.yml +2 -4
- data/CHANGELOG.md +48 -2
- data/README.md +54 -41
- data/YOUTUBE_IT.md +4 -4
- data/bin/yt +2 -9
- data/lib/yt.rb +0 -1
- data/lib/yt/actions/get.rb +33 -0
- data/lib/yt/associations/has_reports.rb +9 -14
- data/lib/yt/collections/claims.rb +8 -0
- data/lib/yt/collections/content_owners.rb +6 -2
- data/lib/yt/collections/playlist_items.rb +10 -1
- data/lib/yt/collections/reports.rb +5 -7
- data/lib/yt/collections/snippets.rb +1 -1
- data/lib/yt/config.rb +54 -0
- data/lib/yt/models/account.rb +21 -1
- data/lib/yt/models/asset.rb +27 -4
- data/lib/yt/models/asset_metadata.rb +1 -1
- data/lib/yt/models/base.rb +2 -0
- data/lib/yt/models/channel.rb +2 -5
- data/lib/yt/models/claim.rb +11 -0
- data/lib/yt/models/configuration.rb +70 -0
- data/lib/yt/models/content_owner.rb +49 -0
- data/lib/yt/models/match_policy.rb +4 -6
- data/lib/yt/models/playlist.rb +12 -2
- data/lib/yt/models/playlist_item.rb +8 -1
- data/lib/yt/models/resource.rb +70 -4
- data/lib/yt/models/statistics_set.rb +2 -1
- data/lib/yt/models/url.rb +2 -60
- data/lib/yt/models/video.rb +16 -3
- data/lib/yt/request.rb +6 -2
- data/lib/yt/version.rb +1 -1
- data/yt.gemspec +6 -3
- metadata +44 -176
- data/spec/collections/claims_spec.rb +0 -30
- data/spec/collections/comment_threads_spec.rb +0 -46
- data/spec/collections/playlist_items_spec.rb +0 -44
- data/spec/collections/playlists_spec.rb +0 -27
- data/spec/collections/policies_spec.rb +0 -30
- data/spec/collections/references_spec.rb +0 -30
- data/spec/collections/reports_spec.rb +0 -30
- data/spec/collections/subscriptions_spec.rb +0 -25
- data/spec/collections/videos_spec.rb +0 -43
- data/spec/constants/geography_spec.rb +0 -16
- data/spec/errors/forbidden_spec.rb +0 -10
- data/spec/errors/missing_auth_spec.rb +0 -24
- data/spec/errors/no_items_spec.rb +0 -10
- data/spec/errors/request_error_spec.rb +0 -44
- data/spec/errors/server_error_spec.rb +0 -10
- data/spec/errors/unauthorized_spec.rb +0 -10
- data/spec/models/account_spec.rb +0 -138
- data/spec/models/annotation_spec.rb +0 -180
- data/spec/models/asset_spec.rb +0 -20
- data/spec/models/channel_spec.rb +0 -127
- data/spec/models/claim_event_spec.rb +0 -62
- data/spec/models/claim_history_spec.rb +0 -27
- data/spec/models/claim_spec.rb +0 -223
- data/spec/models/comment_spec.rb +0 -40
- data/spec/models/comment_thread_spec.rb +0 -93
- data/spec/models/content_detail_spec.rb +0 -52
- data/spec/models/content_owner_detail_spec.rb +0 -6
- data/spec/models/file_detail_spec.rb +0 -13
- data/spec/models/live_streaming_detail_spec.rb +0 -6
- data/spec/models/ownership_spec.rb +0 -59
- data/spec/models/player_spec.rb +0 -13
- data/spec/models/playlist_item_spec.rb +0 -120
- data/spec/models/playlist_spec.rb +0 -138
- data/spec/models/policy_rule_spec.rb +0 -63
- data/spec/models/policy_spec.rb +0 -41
- data/spec/models/rating_spec.rb +0 -12
- data/spec/models/reference_spec.rb +0 -249
- data/spec/models/request_spec.rb +0 -204
- data/spec/models/resource_spec.rb +0 -42
- data/spec/models/right_owner_spec.rb +0 -71
- data/spec/models/snippet_spec.rb +0 -13
- data/spec/models/statistics_set_spec.rb +0 -13
- data/spec/models/status_spec.rb +0 -13
- data/spec/models/subscription_spec.rb +0 -30
- data/spec/models/url_spec.rb +0 -78
- data/spec/models/video_category_spec.rb +0 -21
- data/spec/models/video_spec.rb +0 -669
- data/spec/requests/as_account/account_spec.rb +0 -148
- data/spec/requests/as_account/authentications_spec.rb +0 -127
- data/spec/requests/as_account/channel_spec.rb +0 -246
- data/spec/requests/as_account/channels_spec.rb +0 -18
- data/spec/requests/as_account/playlist_item_spec.rb +0 -55
- data/spec/requests/as_account/playlist_spec.rb +0 -218
- 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 +0 -408
- data/spec/requests/as_content_owner/account_spec.rb +0 -29
- data/spec/requests/as_content_owner/advertising_options_set_spec.rb +0 -15
- data/spec/requests/as_content_owner/asset_spec.rb +0 -20
- data/spec/requests/as_content_owner/bulk_report_job_spec.rb +0 -19
- data/spec/requests/as_content_owner/channel_spec.rb +0 -1836
- data/spec/requests/as_content_owner/claim_history_spec.rb +0 -20
- data/spec/requests/as_content_owner/content_owner_spec.rb +0 -329
- data/spec/requests/as_content_owner/match_policy_spec.rb +0 -17
- data/spec/requests/as_content_owner/ownership_spec.rb +0 -25
- data/spec/requests/as_content_owner/playlist_spec.rb +0 -767
- data/spec/requests/as_content_owner/video_group_spec.rb +0 -112
- data/spec/requests/as_content_owner/video_spec.rb +0 -1211
- data/spec/requests/as_server_app/channel_spec.rb +0 -54
- data/spec/requests/as_server_app/comment_spec.rb +0 -22
- data/spec/requests/as_server_app/comment_thread_spec.rb +0 -27
- data/spec/requests/as_server_app/comment_threads_spec.rb +0 -41
- data/spec/requests/as_server_app/playlist_item_spec.rb +0 -30
- data/spec/requests/as_server_app/playlist_spec.rb +0 -33
- data/spec/requests/as_server_app/url_spec.rb +0 -94
- data/spec/requests/as_server_app/video_spec.rb +0 -60
- data/spec/requests/as_server_app/videos_spec.rb +0 -40
- data/spec/requests/unauthenticated/video_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -20
- data/spec/support/fail_matcher.rb +0 -15
- data/spec/support/global_hooks.rb +0 -48
@@ -48,6 +48,15 @@ module Yt
|
|
48
48
|
def insert_parts
|
49
49
|
{snippet: {keys: [:playlist_id, :resource_id, :position]}}
|
50
50
|
end
|
51
|
+
|
52
|
+
# For inserting a playlist item with content owner auth.
|
53
|
+
# @see https://developers.google.com/youtube/v3/docs/playlistItems/insert
|
54
|
+
def insert_params
|
55
|
+
params = super
|
56
|
+
params[:params] ||= {}
|
57
|
+
params[:params].merge! @auth.insert_playlist_item_params
|
58
|
+
params
|
59
|
+
end
|
51
60
|
end
|
52
61
|
end
|
53
|
-
end
|
62
|
+
end
|
@@ -6,7 +6,6 @@ module Yt
|
|
6
6
|
class Reports < Base
|
7
7
|
DIMENSIONS = Hash.new({name: 'day', parse: ->(day, *values) { @metrics.keys.zip(values.map{|v| {Date.iso8601(day) => v}}).to_h} }).tap do |hash|
|
8
8
|
hash[:month] = {name: 'month', parse: ->(month, *values) { @metrics.keys.zip(values.map{|v| {Range.new(Date.strptime(month, '%Y-%m').beginning_of_month, Date.strptime(month, '%Y-%m').end_of_month) => v} }).to_h} }
|
9
|
-
hash[:week] = {name: '7DayTotals', parse: ->(last_day_of_week, *values) { @metrics.keys.zip(values.map{|v| {Range.new(Date.strptime(last_day_of_week) - 6, Date.strptime(last_day_of_week)) => v} }).to_h} }
|
10
9
|
hash[:range] = {parse: ->(*values) { @metrics.keys.zip(values.map{|v| {total: v}}).to_h } }
|
11
10
|
hash[:traffic_source] = {name: 'insightTrafficSourceType', parse: ->(source, *values) { @metrics.keys.zip(values.map{|v| {TRAFFIC_SOURCES.key(source) => v}}).to_h} }
|
12
11
|
hash[:playback_location] = {name: 'insightPlaybackLocationType', parse: ->(location, *values) { @metrics.keys.zip(values.map{|v| {PLAYBACK_LOCATIONS.key(location) => v}}).to_h} }
|
@@ -140,11 +139,6 @@ module Yt
|
|
140
139
|
end
|
141
140
|
if dimension == :month
|
142
141
|
hash = hash.transform_values{|h| h.sort_by{|range, v| range.first}.to_h}
|
143
|
-
elsif dimension == :week
|
144
|
-
hash = hash.transform_values do |h|
|
145
|
-
h.select{|range, v| range.last.wday == days_range.last.wday}.
|
146
|
-
sort_by{|range, v| range.first}.to_h
|
147
|
-
end
|
148
142
|
elsif dimension == :day
|
149
143
|
hash = hash.transform_values{|h| h.sort_by{|day, v| day}.to_h}
|
150
144
|
elsif dimension.in? [:traffic_source, :country, :state, :playback_location, :device_type, :operating_system, :subscribed_status]
|
@@ -159,11 +153,15 @@ module Yt
|
|
159
153
|
# same query is a workaround that works and can hardly cause any damage.
|
160
154
|
# Similarly, once in while YouTube responds with a random 503 error.
|
161
155
|
rescue Yt::Error => e
|
162
|
-
(max_retries > 0) && rescue?(e) ? sleep(
|
156
|
+
(max_retries > 0) && rescue?(e) ? sleep(retry_time) && within(days_range, country, state, dimension, videos, historical, max_retries - 1) : raise
|
163
157
|
end
|
164
158
|
|
165
159
|
private
|
166
160
|
|
161
|
+
def retry_time
|
162
|
+
3
|
163
|
+
end
|
164
|
+
|
167
165
|
def type_cast(value, type)
|
168
166
|
case [type]
|
169
167
|
when [Integer] then value.to_i if value
|
data/lib/yt/config.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'yt/models/configuration'
|
2
|
+
|
3
|
+
module Yt
|
4
|
+
# Provides methods to read and write global configuration settings.
|
5
|
+
#
|
6
|
+
# A typical usage is to set the API keys retrieved from the
|
7
|
+
# {http://console.developers.google.com Google Developers Console}.
|
8
|
+
#
|
9
|
+
# @example Set the API key for a server-only YouTube app:
|
10
|
+
# Yt.configure do |config|
|
11
|
+
# config.api_key = 'ABCDEFGHIJ1234567890'
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# @example Set the API client id/secret for a web-client YouTube app:
|
15
|
+
# Yt.configure do |config|
|
16
|
+
# config.client_id = 'ABCDEFGHIJ1234567890'
|
17
|
+
# config.client_secret = 'ABCDEFGHIJ1234567890'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# Note that Yt.configure has precedence over values through with
|
21
|
+
# environment variables (see {Yt::Models::Configuration}).
|
22
|
+
#
|
23
|
+
module Config
|
24
|
+
# Yields the global configuration to the given block.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# Yt.configure do |config|
|
28
|
+
# config.api_key = 'ABCDEFGHIJ1234567890'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# @yield [Yt::Models::Configuration] The global configuration.
|
32
|
+
def configure
|
33
|
+
yield configuration if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the global {Yt::Models::Configuration} object.
|
37
|
+
#
|
38
|
+
# While this method _can_ be used to read and write configuration settings,
|
39
|
+
# it is easier to use {Yt::Config#configure} Yt.configure}.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Yt.configuration.api_key = 'ABCDEFGHIJ1234567890'
|
43
|
+
#
|
44
|
+
# @return [Yt::Models::Configuration] The global configuration.
|
45
|
+
def configuration
|
46
|
+
@configuration ||= Yt::Configuration.new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# @note Config is the only module auto-loaded in the Yt module,
|
51
|
+
# in order to have a syntax as easy as Yt.configure
|
52
|
+
|
53
|
+
extend Config
|
54
|
+
end
|
data/lib/yt/models/account.rb
CHANGED
@@ -65,7 +65,7 @@ module Yt
|
|
65
65
|
# @param [Hash] params the metadata to add to the uploaded video.
|
66
66
|
# @option params [String] :title The video’s title.
|
67
67
|
# @option params [String] :description The video’s description.
|
68
|
-
# @option params [Array<String>] :
|
68
|
+
# @option params [Array<String>] :tags The video’s tags.
|
69
69
|
# @option params [String] :privacy_status The video’s privacy status.
|
70
70
|
# @return [Yt::Models::Video] the newly uploaded video.
|
71
71
|
def upload_video(path_or_url, params = {})
|
@@ -192,6 +192,10 @@ module Yt
|
|
192
192
|
{mine: true}
|
193
193
|
end
|
194
194
|
|
195
|
+
def playlist_items_params
|
196
|
+
{}
|
197
|
+
end
|
198
|
+
|
195
199
|
# @private
|
196
200
|
# Tells `has_many :resumable_sessions` what path to hit to upload a file.
|
197
201
|
def upload_path
|
@@ -223,6 +227,22 @@ module Yt
|
|
223
227
|
def upload_content_type
|
224
228
|
'video/*'
|
225
229
|
end
|
230
|
+
|
231
|
+
def update_video_params
|
232
|
+
{}
|
233
|
+
end
|
234
|
+
|
235
|
+
def update_playlist_params
|
236
|
+
{}
|
237
|
+
end
|
238
|
+
|
239
|
+
def upload_thumbnail_params
|
240
|
+
{}
|
241
|
+
end
|
242
|
+
|
243
|
+
def insert_playlist_item_params
|
244
|
+
{}
|
245
|
+
end
|
226
246
|
end
|
227
247
|
end
|
228
248
|
end
|
data/lib/yt/models/asset.rb
CHANGED
@@ -12,11 +12,12 @@ module Yt
|
|
12
12
|
@data = options.fetch(:data, {})
|
13
13
|
@id = options[:id]
|
14
14
|
@auth = options[:auth]
|
15
|
+
@params = options[:params]
|
15
16
|
end
|
16
17
|
|
17
18
|
def update(attributes = {})
|
18
19
|
underscore_keys! attributes
|
19
|
-
|
20
|
+
do_update body: attributes
|
20
21
|
true
|
21
22
|
end
|
22
23
|
|
@@ -34,6 +35,10 @@ module Yt
|
|
34
35
|
@metadata_effective ||= Yt::Models::AssetMetadata.new data: @data.fetch('metadataEffective', {})
|
35
36
|
end
|
36
37
|
|
38
|
+
def ownership_effective
|
39
|
+
@ownership_effective ||= Yt::Models::Ownership.new data: @data.fetch('ownershipEffective', {})
|
40
|
+
end
|
41
|
+
|
37
42
|
# Soft-deletes the asset.
|
38
43
|
# @note YouTube API does not provide a +delete+ method for the Asset
|
39
44
|
# resource, but only an +update+ method. Updating the +status+ of a
|
@@ -64,11 +69,11 @@ module Yt
|
|
64
69
|
# +'show'+, +'sound_recording'+, +'video_game'+, +'web'+.
|
65
70
|
has_attribute :type
|
66
71
|
|
67
|
-
# @return [Array<
|
72
|
+
# @return [Array<String>] the list of asset labels associated
|
68
73
|
# with the asset. You can apply a label to multiple assets to group
|
69
74
|
# them. You can use the labels as search filters to perform bulk updates,
|
70
75
|
# to download reports, or to filter YouTube Analytics.
|
71
|
-
has_attribute :label
|
76
|
+
has_attribute :label, default: []
|
72
77
|
|
73
78
|
# Status
|
74
79
|
|
@@ -106,6 +111,24 @@ module Yt
|
|
106
111
|
params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
|
107
112
|
end
|
108
113
|
end
|
114
|
+
|
115
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/assets/update
|
116
|
+
def update_params
|
117
|
+
super.tap do |params|
|
118
|
+
params[:expected_response] = Net::HTTPOK
|
119
|
+
params[:path] = "/youtube/partner/v1/assets/#{@id}"
|
120
|
+
params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# @return [Hash] the parameters to submit to YouTube to get an asset.
|
125
|
+
# @see https://developers.google.com/youtube/partner/docs/v1/assets/get
|
126
|
+
def get_params
|
127
|
+
super.tap do |params|
|
128
|
+
params[:path] = "/youtube/partner/v1/assets/#{@id}"
|
129
|
+
params[:params] = {on_behalf_of_content_owner: @auth.owner_name}.merge! @params
|
130
|
+
end
|
131
|
+
end
|
109
132
|
end
|
110
133
|
end
|
111
|
-
end
|
134
|
+
end
|
data/lib/yt/models/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'yt/actions/delete'
|
2
2
|
require 'yt/actions/update'
|
3
3
|
require 'yt/actions/patch'
|
4
|
+
require 'yt/actions/get'
|
4
5
|
|
5
6
|
require 'yt/associations/has_attribute'
|
6
7
|
require 'yt/associations/has_authentication'
|
@@ -17,6 +18,7 @@ module Yt
|
|
17
18
|
include Actions::Delete
|
18
19
|
include Actions::Update
|
19
20
|
include Actions::Patch
|
21
|
+
include Actions::Get
|
20
22
|
|
21
23
|
include Associations::HasAttribute
|
22
24
|
extend Associations::HasReports
|
data/lib/yt/models/channel.rb
CHANGED
@@ -197,10 +197,6 @@ module Yt
|
|
197
197
|
# @return [Integer] the number of times the channel has been viewed.
|
198
198
|
delegate :view_count, to: :statistics_set
|
199
199
|
|
200
|
-
# @!attribute [r] comment_count
|
201
|
-
# @return [Integer] the number of comments for the channel.
|
202
|
-
delegate :comment_count, to: :statistics_set
|
203
|
-
|
204
200
|
# @!attribute [r] video_count
|
205
201
|
# @return [Integer] the number of videos uploaded to the channel.
|
206
202
|
delegate :video_count, to: :statistics_set
|
@@ -283,7 +279,8 @@ module Yt
|
|
283
279
|
# @private
|
284
280
|
# Tells `has_reports` to retrieve the reports from YouTube Analytics API
|
285
281
|
# either as a Channel or as a Content Owner.
|
286
|
-
# @see https://developers.google.com/youtube/analytics/
|
282
|
+
# @see https://developers.google.com/youtube/analytics/channel_reports
|
283
|
+
# @see https://developers.google.com/youtube/analytics/content_owner_reports
|
287
284
|
def reports_params
|
288
285
|
{}.tap do |params|
|
289
286
|
if auth.owner_name
|
data/lib/yt/models/claim.rb
CHANGED
@@ -14,6 +14,17 @@ module Yt
|
|
14
14
|
@asset = options[:asset] if options[:asset]
|
15
15
|
end
|
16
16
|
|
17
|
+
# Updates the attributes of a claim.
|
18
|
+
# @note If you are submitting an update request, and your request does
|
19
|
+
# not specify a value for a property that already has a value, the
|
20
|
+
# property's existing value will be deleted.
|
21
|
+
# @return [Boolean] whether the claim was successfully updated.
|
22
|
+
def update(attributes = {})
|
23
|
+
underscore_keys! attributes
|
24
|
+
do_patch body: attributes
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
17
28
|
# @!attribute [r] claim_history
|
18
29
|
# @return [Yt::Collections::ClaimHistories] the claim's history.
|
19
30
|
has_one :claim_history
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Yt
|
2
|
+
module Models
|
3
|
+
# Provides an object to store global configuration settings.
|
4
|
+
#
|
5
|
+
# This class is typically not used directly, but by calling
|
6
|
+
# {Yt::Config#configure Yt.configure}, which creates and updates a single
|
7
|
+
# instance of {Yt::Models::Configuration}.
|
8
|
+
#
|
9
|
+
# @example Set the API client id/secret for a web-client YouTube app:
|
10
|
+
# Yt.configure do |config|
|
11
|
+
# config.client_id = 'ABCDEFGHIJ1234567890'
|
12
|
+
# config.client_secret = 'ABCDEFGHIJ1234567890'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# @see Yt::Config for more examples.
|
16
|
+
#
|
17
|
+
# An alternative way to set global configuration settings is by storing
|
18
|
+
# them in the following environment variables:
|
19
|
+
#
|
20
|
+
# * +YT_CLIENT_ID+ to store the Client ID for web/device apps
|
21
|
+
# * +YT_CLIENT_SECRET+ to store the Client Secret for web/device apps
|
22
|
+
# * +YT_API_KEY+ to store the API key for server/browser apps
|
23
|
+
# * +YT_LOG_LEVEL+ to store the verbosity level of the logs
|
24
|
+
#
|
25
|
+
# In case both methods are used together,
|
26
|
+
# {Yt::Config#configure Yt.configure} takes precedence.
|
27
|
+
#
|
28
|
+
# @example Set the API client id/secret for a web-client YouTube app:
|
29
|
+
# ENV['YT_CLIENT_ID'] = 'ABCDEFGHIJ1234567890'
|
30
|
+
# ENV['YT_CLIENT_SECRET'] = 'ABCDEFGHIJ1234567890'
|
31
|
+
#
|
32
|
+
class Configuration
|
33
|
+
# @return [String] the Client ID for web/device YouTube applications.
|
34
|
+
# @see https://console.developers.google.com Google Developers Console
|
35
|
+
attr_accessor :client_id
|
36
|
+
|
37
|
+
# @return [String] the Client Secret for web/device YouTube applications.
|
38
|
+
# @see https://console.developers.google.com Google Developers Console
|
39
|
+
attr_accessor :client_secret
|
40
|
+
|
41
|
+
# @return [String] the API key for server/browser YouTube applications.
|
42
|
+
# @see https://console.developers.google.com Google Developers Console
|
43
|
+
attr_accessor :api_key
|
44
|
+
|
45
|
+
# @return [String] the level of output to print for debugging purposes.
|
46
|
+
attr_accessor :log_level
|
47
|
+
|
48
|
+
# Initialize the global configuration settings, using the values of
|
49
|
+
# the specified following environment variables by default.
|
50
|
+
def initialize
|
51
|
+
@client_id = ENV['YT_CLIENT_ID']
|
52
|
+
@client_secret = ENV['YT_CLIENT_SECRET']
|
53
|
+
@api_key = ENV['YT_API_KEY']
|
54
|
+
@log_level = ENV['YT_LOG_LEVEL']
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] whether the logging output is extra-verbose.
|
58
|
+
# Useful when developing (e.g., to print the curl of every request).
|
59
|
+
def developing?
|
60
|
+
log_level.to_s.in? %w(devel)
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Boolean] whether the logging output is verbose.
|
64
|
+
# Useful when debugging (e.g., to print the curl of failing requests).
|
65
|
+
def debugging?
|
66
|
+
log_level.to_s.in? %w(devel debug)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -46,6 +46,22 @@ module Yt
|
|
46
46
|
@display_name = options[:display_name]
|
47
47
|
end
|
48
48
|
|
49
|
+
# Uploads a reference file to YouTube.
|
50
|
+
# @param [String] path_or_url is the video or audio file to upload. Can either be the
|
51
|
+
# path of a local file or the URL of a remote file.
|
52
|
+
# @param [Hash] params the metadata to add to the uploaded reference.
|
53
|
+
# @option params [String] :asset_id The id of the asset the uploaded reference belongs to.
|
54
|
+
# @option params [String] :content_type The type of content being uploaded.
|
55
|
+
# @return [Yt::Models::Reference] the newly uploaded reference.
|
56
|
+
def upload_reference_file(path_or_url, params = {})
|
57
|
+
file = open path_or_url, 'rb'
|
58
|
+
session = resumable_sessions.insert file.size, params
|
59
|
+
|
60
|
+
session.update(body: file) do |data|
|
61
|
+
Yt::Reference.new id: data['id'], data: data, auth: self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
49
65
|
def create_reference(params = {})
|
50
66
|
references.insert params
|
51
67
|
end
|
@@ -60,6 +76,12 @@ module Yt
|
|
60
76
|
|
61
77
|
### PRIVATE API ###
|
62
78
|
|
79
|
+
# @private
|
80
|
+
# Tells `has_many :resumable_sessions` what path to hit to upload a file.
|
81
|
+
def upload_path
|
82
|
+
'/upload/youtube/partner/v1/references'
|
83
|
+
end
|
84
|
+
|
63
85
|
# @private
|
64
86
|
# Tells `has_many :videos` that account.videos should return all the
|
65
87
|
# videos *on behalf of* the content owner (public, private, unlisted).
|
@@ -67,12 +89,39 @@ module Yt
|
|
67
89
|
{for_content_owner: true, on_behalf_of_content_owner: @owner_name}
|
68
90
|
end
|
69
91
|
|
92
|
+
# @private
|
93
|
+
# Tells `has_many :resumable_sessions` what params are set for the object
|
94
|
+
# associated to the uploaded file.
|
95
|
+
def upload_params
|
96
|
+
{part: 'snippet,status', on_behalf_of_content_owner: self.owner_name}
|
97
|
+
end
|
98
|
+
|
70
99
|
# @private
|
71
100
|
# Tells `has_many :video_groups` that content_owner.video_groups should
|
72
101
|
# return all the video-groups *on behalf of* the content owner
|
73
102
|
def video_groups_params
|
74
103
|
{on_behalf_of_content_owner: @owner_name}
|
75
104
|
end
|
105
|
+
|
106
|
+
def playlist_items_params
|
107
|
+
{on_behalf_of_content_owner: @owner_name}
|
108
|
+
end
|
109
|
+
|
110
|
+
def update_video_params
|
111
|
+
{on_behalf_of_content_owner: @owner_name}
|
112
|
+
end
|
113
|
+
|
114
|
+
def update_playlist_params
|
115
|
+
{on_behalf_of_content_owner: @owner_name}
|
116
|
+
end
|
117
|
+
|
118
|
+
def upload_thumbnail_params
|
119
|
+
{on_behalf_of_content_owner: @owner_name}
|
120
|
+
end
|
121
|
+
|
122
|
+
def insert_playlist_item_params
|
123
|
+
{on_behalf_of_content_owner: @owner_name}
|
124
|
+
end
|
76
125
|
end
|
77
126
|
end
|
78
127
|
end
|