yt-andrewroth 0.25.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. data/.gitignore +27 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +5 -0
  5. data/CHANGELOG.md +732 -0
  6. data/Gemfile +4 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +489 -0
  9. data/Rakefile +11 -0
  10. data/YOUTUBE_IT.md +835 -0
  11. data/bin/yt +30 -0
  12. data/gemfiles/Gemfile.activesupport-3.x +4 -0
  13. data/gemfiles/Gemfile.activesupport-4.x +4 -0
  14. data/lib/yt.rb +21 -0
  15. data/lib/yt/actions/base.rb +32 -0
  16. data/lib/yt/actions/delete.rb +19 -0
  17. data/lib/yt/actions/delete_all.rb +32 -0
  18. data/lib/yt/actions/insert.rb +42 -0
  19. data/lib/yt/actions/list.rb +139 -0
  20. data/lib/yt/actions/modify.rb +37 -0
  21. data/lib/yt/actions/patch.rb +19 -0
  22. data/lib/yt/actions/update.rb +19 -0
  23. data/lib/yt/associations/has_attribute.rb +55 -0
  24. data/lib/yt/associations/has_authentication.rb +214 -0
  25. data/lib/yt/associations/has_many.rb +22 -0
  26. data/lib/yt/associations/has_one.rb +22 -0
  27. data/lib/yt/associations/has_reports.rb +320 -0
  28. data/lib/yt/collections/advertising_options_sets.rb +34 -0
  29. data/lib/yt/collections/annotations.rb +62 -0
  30. data/lib/yt/collections/assets.rb +58 -0
  31. data/lib/yt/collections/authentications.rb +47 -0
  32. data/lib/yt/collections/base.rb +62 -0
  33. data/lib/yt/collections/channels.rb +31 -0
  34. data/lib/yt/collections/claim_histories.rb +34 -0
  35. data/lib/yt/collections/claims.rb +56 -0
  36. data/lib/yt/collections/content_details.rb +30 -0
  37. data/lib/yt/collections/content_owner_details.rb +34 -0
  38. data/lib/yt/collections/content_owners.rb +32 -0
  39. data/lib/yt/collections/device_flows.rb +23 -0
  40. data/lib/yt/collections/file_details.rb +30 -0
  41. data/lib/yt/collections/ids.rb +27 -0
  42. data/lib/yt/collections/live_streaming_details.rb +30 -0
  43. data/lib/yt/collections/ownerships.rb +34 -0
  44. data/lib/yt/collections/partnered_channels.rb +28 -0
  45. data/lib/yt/collections/players.rb +30 -0
  46. data/lib/yt/collections/playlist_items.rb +53 -0
  47. data/lib/yt/collections/playlists.rb +28 -0
  48. data/lib/yt/collections/policies.rb +28 -0
  49. data/lib/yt/collections/ratings.rb +23 -0
  50. data/lib/yt/collections/references.rb +46 -0
  51. data/lib/yt/collections/related_playlists.rb +43 -0
  52. data/lib/yt/collections/reports.rb +161 -0
  53. data/lib/yt/collections/resources.rb +57 -0
  54. data/lib/yt/collections/resumable_sessions.rb +51 -0
  55. data/lib/yt/collections/snippets.rb +27 -0
  56. data/lib/yt/collections/statistics_sets.rb +30 -0
  57. data/lib/yt/collections/statuses.rb +27 -0
  58. data/lib/yt/collections/subscribed_channels.rb +46 -0
  59. data/lib/yt/collections/subscribers.rb +33 -0
  60. data/lib/yt/collections/subscriptions.rb +50 -0
  61. data/lib/yt/collections/user_infos.rb +36 -0
  62. data/lib/yt/collections/video_categories.rb +35 -0
  63. data/lib/yt/collections/videos.rb +137 -0
  64. data/lib/yt/config.rb +54 -0
  65. data/lib/yt/errors/forbidden.rb +13 -0
  66. data/lib/yt/errors/missing_auth.rb +81 -0
  67. data/lib/yt/errors/no_items.rb +13 -0
  68. data/lib/yt/errors/request_error.rb +74 -0
  69. data/lib/yt/errors/server_error.rb +13 -0
  70. data/lib/yt/errors/unauthorized.rb +50 -0
  71. data/lib/yt/models/account.rb +216 -0
  72. data/lib/yt/models/advertising_options_set.rb +38 -0
  73. data/lib/yt/models/annotation.rb +132 -0
  74. data/lib/yt/models/asset.rb +111 -0
  75. data/lib/yt/models/asset_metadata.rb +38 -0
  76. data/lib/yt/models/asset_snippet.rb +46 -0
  77. data/lib/yt/models/authentication.rb +83 -0
  78. data/lib/yt/models/base.rb +32 -0
  79. data/lib/yt/models/channel.rb +302 -0
  80. data/lib/yt/models/claim.rb +156 -0
  81. data/lib/yt/models/claim_event.rb +67 -0
  82. data/lib/yt/models/claim_history.rb +29 -0
  83. data/lib/yt/models/configuration.rb +70 -0
  84. data/lib/yt/models/content_detail.rb +65 -0
  85. data/lib/yt/models/content_owner.rb +48 -0
  86. data/lib/yt/models/content_owner_detail.rb +18 -0
  87. data/lib/yt/models/description.rb +58 -0
  88. data/lib/yt/models/device_flow.rb +16 -0
  89. data/lib/yt/models/file_detail.rb +21 -0
  90. data/lib/yt/models/id.rb +9 -0
  91. data/lib/yt/models/iterator.rb +16 -0
  92. data/lib/yt/models/live_streaming_detail.rb +23 -0
  93. data/lib/yt/models/match_policy.rb +34 -0
  94. data/lib/yt/models/ownership.rb +75 -0
  95. data/lib/yt/models/player.rb +18 -0
  96. data/lib/yt/models/playlist.rb +218 -0
  97. data/lib/yt/models/playlist_item.rb +112 -0
  98. data/lib/yt/models/policy.rb +36 -0
  99. data/lib/yt/models/policy_rule.rb +124 -0
  100. data/lib/yt/models/rating.rb +37 -0
  101. data/lib/yt/models/reference.rb +172 -0
  102. data/lib/yt/models/resource.rb +136 -0
  103. data/lib/yt/models/resumable_session.rb +52 -0
  104. data/lib/yt/models/right_owner.rb +58 -0
  105. data/lib/yt/models/snippet.rb +50 -0
  106. data/lib/yt/models/statistics_set.rb +26 -0
  107. data/lib/yt/models/status.rb +32 -0
  108. data/lib/yt/models/subscription.rb +38 -0
  109. data/lib/yt/models/timestamp.rb +13 -0
  110. data/lib/yt/models/url.rb +90 -0
  111. data/lib/yt/models/user_info.rb +26 -0
  112. data/lib/yt/models/video.rb +630 -0
  113. data/lib/yt/models/video_category.rb +12 -0
  114. data/lib/yt/request.rb +278 -0
  115. data/lib/yt/version.rb +3 -0
  116. data/spec/collections/claims_spec.rb +30 -0
  117. data/spec/collections/playlist_items_spec.rb +44 -0
  118. data/spec/collections/playlists_spec.rb +27 -0
  119. data/spec/collections/policies_spec.rb +30 -0
  120. data/spec/collections/references_spec.rb +30 -0
  121. data/spec/collections/reports_spec.rb +30 -0
  122. data/spec/collections/subscriptions_spec.rb +25 -0
  123. data/spec/collections/videos_spec.rb +43 -0
  124. data/spec/errors/forbidden_spec.rb +10 -0
  125. data/spec/errors/missing_auth_spec.rb +24 -0
  126. data/spec/errors/no_items_spec.rb +10 -0
  127. data/spec/errors/request_error_spec.rb +44 -0
  128. data/spec/errors/server_error_spec.rb +10 -0
  129. data/spec/errors/unauthorized_spec.rb +10 -0
  130. data/spec/models/account_spec.rb +138 -0
  131. data/spec/models/annotation_spec.rb +180 -0
  132. data/spec/models/asset_spec.rb +20 -0
  133. data/spec/models/channel_spec.rb +127 -0
  134. data/spec/models/claim_event_spec.rb +62 -0
  135. data/spec/models/claim_history_spec.rb +27 -0
  136. data/spec/models/claim_spec.rb +211 -0
  137. data/spec/models/configuration_spec.rb +44 -0
  138. data/spec/models/content_detail_spec.rb +45 -0
  139. data/spec/models/content_owner_detail_spec.rb +6 -0
  140. data/spec/models/description_spec.rb +94 -0
  141. data/spec/models/file_detail_spec.rb +13 -0
  142. data/spec/models/live_streaming_detail_spec.rb +6 -0
  143. data/spec/models/ownership_spec.rb +59 -0
  144. data/spec/models/player_spec.rb +13 -0
  145. data/spec/models/playlist_item_spec.rb +120 -0
  146. data/spec/models/playlist_spec.rb +138 -0
  147. data/spec/models/policy_rule_spec.rb +63 -0
  148. data/spec/models/policy_spec.rb +41 -0
  149. data/spec/models/rating_spec.rb +12 -0
  150. data/spec/models/reference_spec.rb +249 -0
  151. data/spec/models/request_spec.rb +163 -0
  152. data/spec/models/resource_spec.rb +57 -0
  153. data/spec/models/right_owner_spec.rb +71 -0
  154. data/spec/models/snippet_spec.rb +13 -0
  155. data/spec/models/statistics_set_spec.rb +13 -0
  156. data/spec/models/status_spec.rb +13 -0
  157. data/spec/models/subscription_spec.rb +30 -0
  158. data/spec/models/url_spec.rb +78 -0
  159. data/spec/models/video_category_spec.rb +21 -0
  160. data/spec/models/video_spec.rb +669 -0
  161. data/spec/requests/as_account/account_spec.rb +125 -0
  162. data/spec/requests/as_account/authentications_spec.rb +139 -0
  163. data/spec/requests/as_account/channel_spec.rb +259 -0
  164. data/spec/requests/as_account/channels_spec.rb +18 -0
  165. data/spec/requests/as_account/playlist_item_spec.rb +56 -0
  166. data/spec/requests/as_account/playlist_spec.rb +244 -0
  167. data/spec/requests/as_account/resource_spec.rb +18 -0
  168. data/spec/requests/as_account/thumbnail.jpg +0 -0
  169. data/spec/requests/as_account/video.mp4 +0 -0
  170. data/spec/requests/as_account/video_spec.rb +408 -0
  171. data/spec/requests/as_content_owner/account_spec.rb +25 -0
  172. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +15 -0
  173. data/spec/requests/as_content_owner/asset_spec.rb +20 -0
  174. data/spec/requests/as_content_owner/channel_spec.rb +1934 -0
  175. data/spec/requests/as_content_owner/claim_history_spec.rb +20 -0
  176. data/spec/requests/as_content_owner/content_owner_spec.rb +241 -0
  177. data/spec/requests/as_content_owner/match_policy_spec.rb +17 -0
  178. data/spec/requests/as_content_owner/ownership_spec.rb +25 -0
  179. data/spec/requests/as_content_owner/playlist_spec.rb +782 -0
  180. data/spec/requests/as_content_owner/video_spec.rb +1239 -0
  181. data/spec/requests/as_server_app/channel_spec.rb +74 -0
  182. data/spec/requests/as_server_app/playlist_item_spec.rb +30 -0
  183. data/spec/requests/as_server_app/playlist_spec.rb +53 -0
  184. data/spec/requests/as_server_app/video_spec.rb +58 -0
  185. data/spec/requests/as_server_app/videos_spec.rb +40 -0
  186. data/spec/requests/unauthenticated/video_spec.rb +22 -0
  187. data/spec/spec_helper.rb +20 -0
  188. data/spec/support/fail_matcher.rb +15 -0
  189. data/spec/support/global_hooks.rb +48 -0
  190. data/yt.gemspec +32 -0
  191. metadata +416 -0
@@ -0,0 +1,156 @@
1
+ require 'yt/models/base'
2
+
3
+ module Yt
4
+ module Models
5
+ # Provides methods to interact with YouTube ContentID claims.
6
+ # @see https://developers.google.com/youtube/partner/docs/v1/claims
7
+ class Claim < Base
8
+ attr_reader :auth
9
+
10
+ def initialize(options = {})
11
+ @data = options[:data]
12
+ @id = options[:id]
13
+ @auth = options[:auth]
14
+ end
15
+
16
+ # @!attribute [r] claim_history
17
+ # @return [Yt::Collections::ClaimHistories] the claim's history.
18
+ has_one :claim_history
19
+
20
+ # Soft-deletes the claim.
21
+ # @note YouTube API does not provide a +delete+ method for the Asset
22
+ # resource, but only an +update+ method. Updating the +status+ of a
23
+ # Asset to "inactive" can be considered a soft-deletion.
24
+ # @return [Boolean] whether the claim is inactive.
25
+ def delete
26
+ body = {status: :inactive}
27
+ do_patch(body: body) {|data| @data = data}
28
+ inactive?
29
+ end
30
+
31
+ # @return [String] the ID that YouTube assigns and uses to uniquely
32
+ # identify the claim.
33
+ has_attribute :id
34
+
35
+ # @return [String] the unique YouTube asset ID that identifies the asset
36
+ # associated with the claim.
37
+ has_attribute :asset_id
38
+
39
+ # @return [String] the unique YouTube video ID that identifies the video
40
+ # associated with the claim.
41
+ has_attribute :video_id
42
+
43
+ # Status
44
+
45
+ # Returns the claim’s status.
46
+ # @return [String] the claim’s status. Possible values are: +'active'+,
47
+ # +'appealed'+, +'disputed'+, +'inactive'+, +'pending'+, +'potential'+,
48
+ # +'takedown'+, +'unknown'+.
49
+ # @note When updating a claim, you can update its status from active to
50
+ # inactive to effectively release the claim, but the API does not
51
+ # support other updates to a claim’s status.
52
+ has_attribute :status
53
+
54
+ # @return [Boolean] whether the claim is active.
55
+ def active?
56
+ status == 'active'
57
+ end
58
+
59
+ # @return [Boolean] whether the claim is appealed.
60
+ def appealed?
61
+ status == 'appealed'
62
+ end
63
+
64
+ # @return [Boolean] whether the claim is disputed.
65
+ def disputed?
66
+ status == 'disputed'
67
+ end
68
+
69
+ # @return [Boolean] whether the claim is inactive.
70
+ def inactive?
71
+ status == 'inactive'
72
+ end
73
+
74
+ # @return [Boolean] whether the claim is pending.
75
+ def pending?
76
+ status == 'pending'
77
+ end
78
+
79
+ # @return [Boolean] whether the claim is potential.
80
+ def potential?
81
+ status == 'potential'
82
+ end
83
+
84
+ # @return [Boolean] whether the claim is takedown.
85
+ def takedown?
86
+ status == 'takedown'
87
+ end
88
+
89
+ # @return [Boolean] whether the claim status is unknown.
90
+ def has_unknown_status?
91
+ status == 'unknown'
92
+ end
93
+
94
+ # Content Type
95
+
96
+ # Returns the audiovisual portion of the claimed content.
97
+ # @return [String] the audiovisual portion of the claimed content.
98
+ # Possible values are: +'audio'+, +'audiovisual'+, +'video'+.
99
+ has_attribute :content_type
100
+
101
+ # @return [Boolean] whether the claim covers only the audio.
102
+ def audio?
103
+ content_type == 'audio'
104
+ end
105
+
106
+ # @return [Boolean] whether the claim covers only the video.
107
+ def video?
108
+ content_type == 'video'
109
+ end
110
+
111
+ # @return [Boolean] whether the claim covers both audio and video.
112
+ def audiovisual?
113
+ content_type == 'audiovisual'
114
+ end
115
+
116
+ # @return [Time] the date and time that the claim was created.
117
+ has_attribute :created_at, type: Time, from: :time_created
118
+
119
+ # @return [Boolean] whether a third party created the claim.
120
+ has_attribute :third_party?, from: :third_party_claim do |value|
121
+ value == true
122
+ end
123
+
124
+ # Return whether the video should be blocked where not explicitly owned.
125
+ # @return [Boolean] whether the claimed video should be blocked anywhere
126
+ # it is not explicitly owned. For example, if you upload a video for an
127
+ # asset that you own in the United States and Canada, and you claim the
128
+ # video with a usage policy to monetize the video everywhere. Since the
129
+ # policy is only applied in countries where you own the asset, YouTube
130
+ # will actually monetize the video in the United States and Canada.
131
+ # By default, the video will still be viewable in other countries even
132
+ # though it will not be monetized in those countries. However, if you
133
+ # set this property to true, then the video will be monetized in the
134
+ # United States and Canada and blocked in all other countries.
135
+ has_attribute :block_outside_ownership?, from: :block_outside_ownership
136
+
137
+ # @return [String] The unique ID that YouTube uses to identify the
138
+ # reference that generated the match.
139
+ has_attribute :match_reference_id, from: :match_info do |match_info|
140
+ (match_info || {})['referenceId']
141
+ end
142
+
143
+
144
+ private
145
+
146
+ # @see https://developers.google.com/youtube/partner/docs/v1/claims/update
147
+ def patch_params
148
+ super.tap do |params|
149
+ params[:expected_response] = Net::HTTPOK
150
+ params[:path] = "/youtube/partner/v1/claims/#{id}"
151
+ params[:params] = {on_behalf_of_content_owner: @auth.owner_name}
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,67 @@
1
+ require 'yt/models/base'
2
+
3
+ module Yt
4
+ module Models
5
+ class ClaimEvent < Base
6
+ def initialize(options = {})
7
+ @data = options[:data]
8
+ end
9
+
10
+ REASONS = %w(asset_transfer_request audio_muted audio_replaced audioswap_removed
11
+ channel_transferred channel_whitelisted closed_audio_claim_on_visual_reference
12
+ closed_audio_revshare closed_by_admin closed_cover_revshare
13
+ closed_invalid_reference_segment closed_manually closed_partner_exclusion
14
+ closed_private_video closed_reference_conflict copyrighted_content_matched
15
+ counter_received dispute_resolution duplicate invalid_claim muting_audio
16
+ ownership_removed partner_deactivated pending_activation pending_adsense
17
+ pending_fingerprint pending_for_review reference_removed released replaced
18
+ review_expired revshare_disabled risk_of_error song_erased
19
+ suspended_monetization_on_channel video_classifier_rejecion video_content_modified
20
+ video_removed video_taken_down)
21
+
22
+ # @return [Time] the date and time when the event occurred.
23
+ has_attribute :time, type: Time
24
+
25
+ # @return [String] the reason an event occurred.
26
+ has_attribute :reason
27
+
28
+ # @return [String] the event's type.
29
+ has_attribute :type
30
+
31
+ # @return [String] the source type which triggered the event.
32
+ has_attribute :source_type, from: :source do |source|
33
+ (source || {})['type']
34
+ end
35
+
36
+ # @return [String] the ID of the content owner that initiated
37
+ # the event.
38
+ has_attribute :source_content_owner_id, from: :source do |source|
39
+ (source || {})['contentOwnerId']
40
+ end
41
+
42
+ # @return [String] the email address of the user who initiated
43
+ # the event.
44
+ has_attribute :source_user_email, from: :source do |source|
45
+ (source || {})['userEmail']
46
+ end
47
+
48
+ # @return [String] the reason that explains why a
49
+ # dispute_create event occurred.
50
+ has_attribute :dispute_reason, from: :type_details do |type_details|
51
+ (type_details || {})['disputeReason']
52
+ end
53
+
54
+ # @return [String] a free-text explanation of the reason that a claim
55
+ # was disputed. This property is returned for dispute_create events.
56
+ has_attribute :dispute_notes, from: :type_details do |type_details|
57
+ (type_details || {})['disputeNotes']
58
+ end
59
+
60
+ # @return [String] the event status that resulted from a claim_update
61
+ # event.
62
+ has_attribute :update_status, from: :type_details do |type_details|
63
+ (type_details || {})['updateStatus']
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ require 'yt/models/base'
2
+ require 'yt/models/claim_event'
3
+
4
+ module Yt
5
+ module Models
6
+ # Provides methods to interact with YouTube ContentID claims.
7
+ # @see https://developers.google.com/youtube/partner/docs/v1/claims
8
+ class ClaimHistory < Base
9
+ def initialize(options = {})
10
+ @data = options[:data]
11
+ @id = options[:id]
12
+ @auth = options[:auth]
13
+ end
14
+
15
+ # @return [String] the ID that YouTube assigns and uses to uniquely
16
+ # identify the claim.
17
+ has_attribute :id
18
+
19
+ # @return [String] the unique YouTube channel ID of the channel to
20
+ # which the claimed video was uploaded.
21
+ has_attribute :uploader_channel_id
22
+
23
+ # @return [Array<String>] the list of events associated with the claim.
24
+ has_attribute :events, from: :event do |event_info|
25
+ event_info.map{|event| ClaimEvent.new data: event}
26
+ end
27
+ end
28
+ end
29
+ end
@@ -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
@@ -0,0 +1,65 @@
1
+ require 'yt/models/base'
2
+
3
+ module Yt
4
+ module Models
5
+ # @private
6
+ # Encapsulates information about the video content, including the length
7
+ # of the video and an indication of whether captions are available.
8
+ # @see https://developers.google.com/youtube/v3/docs/videos#resource
9
+ class ContentDetail < Base
10
+ attr_reader :data
11
+
12
+ def initialize(options = {})
13
+ @data = options[:data]
14
+ end
15
+
16
+ # @return [Integer] the duration of the video (in seconds).
17
+ has_attribute :duration, default: 0 do |value|
18
+ to_seconds value
19
+ end
20
+
21
+ has_attribute :dimension
22
+ has_attribute :definition
23
+ has_attribute :caption
24
+ has_attribute :licensed_content
25
+ has_attribute :content_rating, default: {}
26
+
27
+ def youtube_rating
28
+ content_rating['ytRating']
29
+ end
30
+
31
+ private
32
+
33
+ # @return [Integer] the duration of the resource as reported by YouTube.
34
+ # @see https://developers.google.com/youtube/v3/docs/videos
35
+ #
36
+ # According to YouTube documentation, the value is an ISO 8601 duration
37
+ # in the format PT#M#S, in which the letters PT indicate that the value
38
+ # specifies a period of time, and the letters M and S refer to length in
39
+ # minutes and seconds, respectively. The # characters preceding the M and
40
+ # S letters are both integers that specify the number of minutes (or
41
+ # seconds) of the video. For example, a value of PT15M51S indicates that
42
+ # the video is 15 minutes and 51 seconds long.
43
+ #
44
+ # The ISO 8601 duration standard, though, is not +always+ respected by
45
+ # the results returned by YouTube API. For instance: video 2XwmldWC_Ls
46
+ # reports a duration of 'P1W2DT6H21M32S', which is to be interpreted as
47
+ # 1 week, 2 days, 6 hours, 21 minutes, 32 seconds. Mixing weeks with
48
+ # other time units is not strictly part of ISO 8601; in this context,
49
+ # weeks will be interpreted as "the duration of 7 days". Similarly, a
50
+ # day will be interpreted as "the duration of 24 hours".
51
+ # Video tPEE9ZwTmy0 reports a duration of 'PT2S'. Skipping time units
52
+ # such as minutes is not part of the standard either; in this context,
53
+ # it will be interpreted as "0 minutes and 2 seconds".
54
+ def to_seconds(iso8601_duration)
55
+ match = iso8601_duration.match %r{^P(?:|(?<weeks>\d*?)W)(?:|(?<days>\d*?)D)(?:|T(?:|(?<hours>\d*?)H)(?:|(?<min>\d*?)M)(?:|(?<sec>\d*?)S))$}
56
+ weeks = (match[:weeks] || '0').to_i
57
+ days = (match[:days] || '0').to_i
58
+ hours = (match[:hours] || '0').to_i
59
+ minutes = (match[:min] || '0').to_i
60
+ seconds = (match[:sec]).to_i
61
+ (((((weeks * 7) + days) * 24 + hours) * 60) + minutes) * 60 + seconds
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,48 @@
1
+ require 'yt/models/account'
2
+
3
+ module Yt
4
+ module Models
5
+ # Provides methods to interact with YouTube CMS accounts.
6
+ # @see https://cms.youtube.com
7
+ # @see https://developers.google.com/youtube/analytics/v1/content_owner_reports
8
+ class ContentOwner < Account
9
+
10
+ # @!attribute [r] partnered_channels
11
+ # @return [Yt::Collections::PartneredChannels] the channels managed by the CMS account.
12
+ has_many :partnered_channels
13
+
14
+ # @!attribute [r] claims
15
+ # @return [Yt::Collections::Claims] the claims administered by the content owner.
16
+ has_many :claims
17
+
18
+ # @!attribute [r] assets
19
+ # @return [Yt::Collection::Assets] the assets administered by the content owner.
20
+ has_many :assets
21
+
22
+ # @!attribute [r] references
23
+ # @return [Yt::Collections::References] the references administered by the content owner.
24
+ has_many :references
25
+
26
+ # @!attribute [r] policies
27
+ # @return [Yt::Collections::Policies] the policies saved by the content owner.
28
+ has_many :policies
29
+
30
+ def initialize(options = {})
31
+ super options
32
+ @owner_name = options[:owner_name]
33
+ end
34
+
35
+ def create_reference(params = {})
36
+ references.insert params
37
+ end
38
+
39
+ def create_asset(params = {})
40
+ assets.insert params
41
+ end
42
+
43
+ def create_claim(params = {})
44
+ claims.insert params
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ require 'yt/models/base'
2
+
3
+ module Yt
4
+ module Models
5
+ # @private
6
+ # Encapsulates channel data that is relevant for YouTube Partners linked
7
+ # with the channel.
8
+ # @see https://developers.google.com/youtube/v3/docs/channels#contentOwnerDetails
9
+ class ContentOwnerDetail < Base
10
+ def initialize(options = {})
11
+ @data = options[:data] || {}
12
+ end
13
+
14
+ has_attribute :content_owner
15
+ has_attribute :time_linked, type: Time
16
+ end
17
+ end
18
+ end