yt 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bec2c87e88e376b5afac03f9764213e285f047d0
4
- data.tar.gz: 8145cf48aeeec52f7fa5b4efc151e978b77fffe1
3
+ metadata.gz: be6a02a5308ac5e0d87af25b8f92842fb7474e10
4
+ data.tar.gz: 65bd602aebf8bae1bad8dfec257a733f4b3aebfb
5
5
  SHA512:
6
- metadata.gz: 2144d12d72d8e21815a2a031008006a8e7e861ed15110f9608e8f5df27ba2babeac4796c7116e47857761e002d280c19c2447455db36023bf434a20607a146f3
7
- data.tar.gz: e8c4c34065211e919f8410ac5d6e683b2dd1d8ab6d5230d9c7363df4210ac9198d796892406a362c2e59beb3c6026317f423ae58c18fd11bc542b020606cef91
6
+ metadata.gz: 1f77000f204e230668a04045f2216d93a589b55819528851d5aeb855eafb60901eba702a00fe7608b719529d65e66a0e87ac176b097f637b8e0e492e5930bd6d
7
+ data.tar.gz: 076a1006983c59b30fa5abd80d0c1ec6d9073db27c826b6f656a436331ff822ef3c0be6087e3a14c22f2d281793414b9906d7293f29230414ec6684711c56e8c
data/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.17.0 - 2015-04-28
10
+
11
+ **How to upgrade**
12
+
13
+ If your code never calls video-specific methods on `video.status`, then you are
14
+ good to go.
15
+
16
+ If it does, then call the same methods on `video`, rather than `video.status`.
17
+ For instance, replace `video.status.deleted?` with `video.deleted?`.
18
+
19
+ * [ENHANCEMENT] Don’t over-delegate methods of Video.
20
+ * [ENHANCEMENT] Complete documentation of Yt::Video.
21
+
9
22
  ## 0.16.0 - 2015-04-27
10
23
 
11
24
  **How to upgrade**
data/README.md CHANGED
@@ -41,7 +41,7 @@ To install on your system, run
41
41
 
42
42
  To use inside a bundled Ruby project, add this line to the Gemfile:
43
43
 
44
- gem 'yt', '~> 0.16.0'
44
+ gem 'yt', '~> 0.17.0'
45
45
 
46
46
  Since the gem follows [Semantic Versioning](http://semver.org),
47
47
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -5,17 +5,76 @@ module Yt
5
5
  # YouTube resources with reports are: {Yt::Models::Channel channels} and
6
6
  # {Yt::Models::Channel videos}.
7
7
  module HasReports
8
- # @!macro has_report
9
- # @!method $1_on(date)
10
- # @return [Float] the $1 for a single day.
11
- # @param [#to_date] date The single day to get the $1 for.
8
+ # @!macro [new] report
9
+ # Returns the $1 of the video grouped by the given dimension.
12
10
  # @!method $1(options = {})
13
- # @return [Hash<Date, Float>] the $1 for a range of a days.
14
- # @param [Hash] options the range of days to get the $1 for.
15
- # @option options [#to_date] :since The first day of the range.
16
- # Also aliased as *:from*.
17
- # @option options [#to_date] :until The last day of the range.
18
- # Also aliased as *:to*.
11
+ # @param [Hash] options the time-range and dimensions for the $1.
12
+ # @option options [#to_date] :since The first day of the time-range.
13
+ # Also aliased as +:from+.
14
+ # @option options [#to_date] :until The last day of the time-range.
15
+ # Also aliased as +:to+.
16
+
17
+ # @!macro [new] daily_report
18
+ # @option options [Symbol] :by (:day) The dimension to collect $1 by.
19
+ # Valid values are: +:day+.
20
+ # @return [Hash<Date, Float>] if grouped by day, the $1 of the video
21
+ # for each day in the time-range.
22
+ # @example Get the video’s $1 for each day of last week:
23
+ # video.$1 since: 2.weeks.ago, until: 1.week.ago, by: :day
24
+ # # => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.2, …}
25
+ # @macro report
26
+
27
+ # @!macro [new] views_report
28
+ # @option options [Symbol] :by (:day) The dimension to collect $1 by.
29
+ # Valid values are: +:day+, +:traffic_source+, +:playback_location+,
30
+ # +:embedded_player_location+, +:related_video+.
31
+ # @return [Hash<Date, Float>] if grouped by day, the $1 of the video
32
+ # for each day in the time-range.
33
+ # @example Get the video’s $1 for each day of last week:
34
+ # video.$1 since: 2.weeks.ago, until: 1.week.ago, by: :day
35
+ # # => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.2, …}
36
+ # @return [Hash<Symbol, Float>] if grouped by traffic source, the
37
+ # $1 of the video for each traffic source.
38
+ # @example Get yesterday’s video’s $1 grouped by traffic source:
39
+ # video.$1 from: 1.day.ago, to: 1.day.ago, by: :traffic_source
40
+ # # => {advertising: 53.0, channel: 7.0, …}
41
+ # @return [Hash<Symbol, Float>] if grouped by playback location, the
42
+ # $1 of the video for each traffic playback location.
43
+ # @example Get yesterday’s video’s $1 grouped by playback location:
44
+ # video.$1 from: 1.day.ago, to: 1.day.ago, by: :playback_location
45
+ # # => {embedded: 53.0, watch: 467.0, …}
46
+ # @return [Hash<Symbol, Float>] if grouped by embedded player location,
47
+ # the $1 of the video for each embedded player location.
48
+ # @example Get yesterday’s video’s $1 by embedded player location:
49
+ # video.$1 from: 1.day.ago, to: 1.day.ago, by: :embedded_player_location
50
+ # # => {"fullscreen.net" => 92.0, "yahoo.com" => 14.0, …}
51
+ # @return [Hash<Yt::Video, Float>] if grouped by related video, the
52
+ # $1 of the video for each related video.
53
+ # @example Get yesterday’s video’s $1 by related video:
54
+ # video.$1 from: 1.day.ago, to: 1.day.ago, by: :related_video
55
+ # # => {#<Yt::Video @id=…> => 33.0, #<Yt::Video @id=…> => 12.0, …}
56
+ # @macro report
57
+
58
+ # @!macro [new] demographics_report
59
+ # @option options [Symbol] :by (:gender_age_group) The dimension to
60
+ # show viewer percentage by.
61
+ # Valid values are: +:gender+, +:age_group+, +:gender_age_group+.
62
+ # @return [Hash<Symbol, Float>] if grouped by gender, the video’s
63
+ # viewer percentage by gender.
64
+ # @example Get yesterday’s video’s viewer percentage by gender:
65
+ # video.$1 from: 1.day.ago, to: 1.day.ago, by: :gender
66
+ # # => {female: 53.0, male: 47.0}
67
+ # @return [Hash<String, Float>] if grouped by age group, the video’s
68
+ # viewer percentage by age group.
69
+ # @example Get yesterday’s video’s $1 grouped by age group:
70
+ # video.$1 from: 1.day.ago, to: 1.day.ago, by: :age_group
71
+ # # => {"18-24" => 4.54, "35-24" => 12.31, "45-34" => 8.92, …}
72
+ # @return [Hash<Symbol, [Hash<String, Float>]>] if grouped by gender
73
+ # and age group, the video’s viewer percentage by gender/age group.
74
+ # @example Get yesterday’s video’s $1 by gender and age group:
75
+ # video.$1 from: 1.day.ago, to: 1.day.ago
76
+ # # => {female: {"18-24" => 12.12, "25-34" => 16.16, …}, male:…}
77
+ # @macro report
19
78
 
20
79
  # Defines two public instance methods to access the reports of a
21
80
  # resource for a specific metric.
@@ -4,10 +4,10 @@ module Yt
4
4
  #
5
5
  # YouTube resources with viewer percentage reports are:
6
6
  # {Yt::Models::Channel channels} and {Yt::Models::Channel videos}.
7
- # @deprecated Use {#viewer_percentage} instead.
7
+ # @deprecated
8
8
  module HasViewerPercentages
9
9
  # @!macro has_viewer_percentages
10
- # @!deprecated Use {#viewer_percentage} instead.
10
+ # @deprecated
11
11
  # @!method viewer_percentages
12
12
  # @return [Hash<Symbol,Hash<String,Float>>] the viewer percentages.
13
13
  # The first-level hash identifies the genres (:female, :male).
@@ -14,7 +14,7 @@ module Yt
14
14
  # object to upload. If the request succeeds, YouTube returns a unique
15
15
  # URL to upload the object file (and eventually resume the upload).
16
16
  # @param [Integer] content_length the size (bytes) of the object to upload.
17
- # @param [Hash] options the metadata to add to the uploaded object.
17
+ # @param [Hash] body the metadata to add to the uploaded object.
18
18
  def insert(content_length, body = {})
19
19
  @headers = headers_for content_length
20
20
  do_insert body: body, headers: @headers
@@ -19,11 +19,6 @@ module Yt
19
19
  true
20
20
  end
21
21
 
22
- # Return the list of ad formats that the video is allowed to show.
23
- # Valid values for this property are: long, overlay, standard_instream,
24
- # third_party, trueview_inslate, or trueview_instream.
25
- # @return [Array<String>] the list of ad formats that the video is
26
- # allowed to show.
27
22
  def ad_formats
28
23
  @data['adFormats']
29
24
  end
@@ -17,24 +17,10 @@ module Yt
17
17
  to_seconds value
18
18
  end
19
19
 
20
- # @return [Boolean] whether the video is available in 3D.
21
- has_attribute :stereoscopic?, from: :dimension do |dimension|
22
- dimension == '3d'
23
- end
24
-
25
- # @return [Boolean] whether the video is available in high definition.
26
- has_attribute :hd?, from: :definition do |definition|
27
- definition == 'hd'
28
- end
29
-
30
- # @return [Boolean] whether captions are available for the video.
31
- has_attribute :captioned?, from: :caption do |caption|
32
- caption == 'true'
33
- end
34
-
35
- # @return [Boolean] whether the video represents licensed content, which
36
- # means that the content has been claimed by a YouTube content partner.
37
- has_attribute :licensed?, default: false, from: :licensed_content
20
+ has_attribute :dimension
21
+ has_attribute :definition
22
+ has_attribute :caption
23
+ has_attribute :licensed_content
38
24
 
39
25
  private
40
26
 
@@ -12,14 +12,8 @@ module Yt
12
12
  @data = options[:data] || {}
13
13
  end
14
14
 
15
- # @return [Integer] the file size of the video (in bytes).
16
15
  has_attribute :file_size, type: Integer
17
-
18
- # @return [String] the file type of the file. May be one of:
19
- # archive, audio, document, image, other, project, or video.
20
16
  has_attribute :file_type
21
-
22
- # @return [String] the container of the video (e.g. 'mov').
23
17
  has_attribute :container
24
18
  end
25
19
  end
@@ -12,29 +12,10 @@ module Yt
12
12
  @data = options[:data] || {}
13
13
  end
14
14
 
15
- # @return [Time] if the broadcast has begun, the time that the broadcast
16
- # actually started.
17
- # @return [nil] if the broadcast has not begun.
18
15
  has_attribute :actual_start_time, type: Time
19
-
20
- # @return [Time] if the broadcast is over, the time that the broadcast
21
- # actually ended.
22
- # @return [nil] if the broadcast is not over.
23
16
  has_attribute :actual_end_time, type: Time
24
-
25
- # @return [Time] the time that the broadcast is scheduled to begin.
26
17
  has_attribute :scheduled_start_time, type: Time
27
-
28
- # @return [Time] if the broadcast is scheduled to end, the time that the
29
- # broadcast is scheduled to end.
30
- # @return [nil] if the broadcast is scheduled to continue indefinitely.
31
18
  has_attribute :scheduled_end_time, type: Time
32
-
33
- # @return [Integer] if the broadcast has current viewers and the
34
- # broadcast owner has not hidden the viewcount for the video, the
35
- # number of viewers currently watching the broadcast.
36
- # @return [nil] if the broadcast has ended or the broadcast owner has
37
- # hidden the viewcount for the video.
38
19
  has_attribute :concurrent_viewers, type: Integer
39
20
  end
40
21
  end
@@ -11,8 +11,6 @@ module Yt
11
11
  @data = options[:data]
12
12
  end
13
13
 
14
- # @return [String] the HTML code of an <iframe> tag that embeds a
15
- # player that will play the video.
16
14
  has_attribute :embed_html
17
15
  end
18
16
  end
@@ -7,6 +7,9 @@ module Yt
7
7
  module Models
8
8
  class Resource < Base
9
9
  attr_reader :auth
10
+
11
+ # @!attribute [r] id
12
+ # @return [String] the ID that YouTube uses to identify each resource.
10
13
  has_one :id
11
14
 
12
15
  has_one :snippet
@@ -67,17 +70,17 @@ module Yt
67
70
  {}.tap do |body|
68
71
  update_parts.each do |name, part|
69
72
  if should_include_part_in_update? part, attributes
70
- body[name] = build_update_body_part part, attributes
73
+ body[name] = build_update_body_part name, part, attributes
71
74
  sanitize_brackets! body[name] if part[:sanitize_brackets]
72
75
  end
73
76
  end
74
77
  end
75
78
  end
76
79
 
77
- def build_update_body_part(part, attributes = {})
80
+ def build_update_body_part(name, part, attributes = {})
78
81
  {}.tap do |body_part|
79
82
  part[:keys].map do |key|
80
- body_part[camelize key] = attributes.fetch key, send(key)
83
+ body_part[camelize key] = attributes.fetch key, public_send(name).public_send(key)
81
84
  end
82
85
  end
83
86
  end
@@ -22,9 +22,6 @@ module Yt
22
22
  # @return [String] if the resource is a channel, the channel’s title.
23
23
  # @return [String] if the resource is a playlist, the playlist’s title.
24
24
  # @return [String] if the resource is a playlist item, the item’s title.
25
- # @return [String] if the resource is a video, the video’s title. Has a
26
- # maximum of 100 characters and may contain all valid UTF-8 characters
27
- # except < and >.
28
25
  has_attribute :title, default: ''
29
26
 
30
27
  # @return [Yt::Models::Description] if the resource is a channel, the
@@ -33,9 +30,6 @@ module Yt
33
30
  # playlist’s description.
34
31
  # @return [Yt::Models::Description] if the resource is a playlist item,
35
32
  # the item’s description.
36
- # @return [Yt::Models::Description] if the resource is a video, the
37
- # video’s description. Has a maximum of 5000 bytes and may contain all
38
- # valid UTF-8 characters except < and >.
39
33
  has_attribute :description, default: '' do |description_text|
40
34
  Description.new description_text
41
35
  end
@@ -46,23 +40,21 @@ module Yt
46
40
  # the playlist was created.
47
41
  # @return [Time] if the resource is a playlist item, the date and time
48
42
  # that the item was added to the playlist.
49
- # @return [Time] if the resource is a video, the date and time that the
50
- # video was published.
51
43
  has_attribute :published_at, type: Time
52
44
 
53
45
  # @param [Symbol, String] size The size of the thumbnail to retrieve.
54
46
  # @return [String] if the resource is a channel and +size+ is +default+,
55
47
  # the URL of an 88x88px image.
56
- # @return [String] if the resource is a playlist, a PlaylistItem or a
57
- # Video and +size+ is +default+, the URL of an 120x90px image.
48
+ # @return [String] if the resource is a playlist or a playlist item and
49
+ # +size+ is +default+, the URL of an 120x90px image.
58
50
  # @return [String] if the resource is a channel and +size+ is +medium+,
59
51
  # the URL of an 240x240px image.
60
- # @return [String] if the resource is a playlist, a PlaylistItem or a
61
- # Video and +size+ is +medium+, the URL of an 320x180px image.
52
+ # @return [String] if the resource is a playlist or a playlist item and
53
+ # +size+ is +medium+, the URL of an 320x180px image.
62
54
  # @return [String] if the resource is a channel and +size+ is +high+,
63
55
  # the URL of an 800x800px image.
64
- # @return [String] if the resource is a playlist, a PlaylistItem or a
65
- # Video and +size+ is +high+, the URL of an 480x360px image.
56
+ # @return [String] if the resource is a playlist or a playlist item and
57
+ # +size+ is +high+, the URL of an 480x360px image.
66
58
  # @return [nil] if the +size+ is not +default+, +medium+ or +high+.
67
59
  def thumbnail_url(size = :default)
68
60
  thumbnails.fetch(size.to_s, {})['url']
@@ -72,8 +64,6 @@ module Yt
72
64
  # uses to uniquely identify the channel that the playlist belongs to.
73
65
  # @return [String] if the resource is a playlist item, the ID that YouTube
74
66
  # uses to uniquely identify the channel that the playlist belongs to.
75
- # @return [String] if the resource is a video, the ID that YouTube uses
76
- # to uniquely identify the channel that the video was uploaded to.
77
67
  # @return [nil] if the resource is a channel.
78
68
  has_attribute :channel_id
79
69
 
@@ -81,8 +71,6 @@ module Yt
81
71
  # channel that the playlist belongs to.
82
72
  # @return [String] if the resource is a playlist item, the title of the
83
73
  # channel that the playlist item belongs to.
84
- # @return [String] if the resource is a video, the title of the channel
85
- # that the video was uploaded to.
86
74
  # @return [nil] if the resource is a channel.
87
75
  has_attribute :channel_title
88
76
 
@@ -92,32 +80,18 @@ module Yt
92
80
  # list of keyword tags associated with the playlist.
93
81
  # @return [Array<Yt::Models::Tag>] if the resource is a playlist item,
94
82
  # an empty array.
95
- # @return [Array<Yt::Models::Tag>] if the resource is a video, the list
96
- # of keyword tags associated with the video.
97
83
  has_attribute :tags, default: []
98
84
 
99
- # @return [String] if the resource is a video, the YouTube video
100
- # category associated with the video.
101
- # @return [nil] if the resource is a channel.
102
- # @return [nil] if the resource is a playlist.
103
- # @return [nil] if the resource is a playlist item.
104
- # @see https://developers.google.com/youtube/v3/docs/videoCategories/list
105
85
  has_attribute :category_id
106
86
 
107
87
  BROADCAST_TYPES = %q(live none upcoming)
108
88
 
109
- # @return [String] if the resource is a video, whether the resource is a
110
- # live broadcast. Valid values are: live, none, upcoming.
111
- # @return [nil] if the resource is a channel.
112
- # @return [nil] if the resource is a playlist.
113
- # @return [nil] if the resource is a playlist item.
114
89
  has_attribute :live_broadcast_content
115
90
 
116
91
  # @return [String] if the resource is a playlist item, the ID that
117
92
  # YouTube uses to uniquely identify the playlist that the item is in.
118
93
  # @return [nil] if the resource is a channel.
119
94
  # @return [nil] if the resource is a playlist.
120
- # @return [nil] if the resource is a video.
121
95
  has_attribute :playlist_id
122
96
 
123
97
  # @return [Integer] if the resource is a playlist item, the order in
@@ -125,14 +99,12 @@ module Yt
125
99
  # first item has a position of 0, the second item of 1, and so forth.
126
100
  # @return [nil] if the resource is a channel.
127
101
  # @return [nil] if the resource is a playlist.
128
- # @return [nil] if the resource is a video.
129
102
  has_attribute :position, type: Integer
130
103
 
131
104
  # @return [String] if the resource is a playlist item, the ID of the
132
105
  # video the playlist item represents in the playlist.
133
106
  # @return [nil] if the resource is a channel.
134
107
  # @return [nil] if the resource is a playlist.
135
- # @return [nil] if the resource is a video.
136
108
  def video_id
137
109
  resource_id['videoId']
138
110
  end
@@ -141,7 +113,6 @@ module Yt
141
113
  # the playlist.
142
114
  # @return [nil] if the resource is a channel.
143
115
  # @return [nil] if the resource is a playlist.
144
- # @return [nil] if the resource is a video.
145
116
  def video
146
117
  @video ||= Video.new id: video_id, auth: @auth if video_id
147
118
  end
@@ -41,283 +41,16 @@ module Yt
41
41
  privacy_status == 'unlisted'
42
42
  end
43
43
 
44
- # Upload status (Video only)
45
-
46
- # Returns the upload status of a video.
47
- # @return [String] if the resource is a video, the status of the
48
- # uploaded video. Valid values are: deleted, failed, processed,
49
- # rejected, uploading.
50
- # @return [nil] if the resource is not a video.
51
44
  has_attribute :upload_status
52
-
53
- # Returns whether an uploaded video was deleted.
54
- # @return [Boolean] if the resource is a video, whether the uploaded
55
- # video was deleted by the user.
56
- # @return [nil] if the resource is not a video.
57
- def deleted?
58
- upload_status == 'deleted' if video?
59
- end
60
-
61
- # Returns whether a video failed to upload. If true, the reason why
62
- # the video upload failed can be obtained with +failure_reason+.
63
- # @return [Boolean] if the resource is a video, whether the video failed
64
- # to upload.
65
- # @return [nil] if the resource is not a video.
66
- def failed?
67
- upload_status == 'failed' if video?
68
- end
69
-
70
- # Returns whether an uploaded video is being processed by YouTube.
71
- # @return [Boolean] if the resource is a video, whether the uploaded
72
- # video is being processed by YouTube.
73
- # @return [nil] if the resource is not a video.
74
- def processed?
75
- upload_status == 'processed' if video?
76
- end
77
-
78
- # Returns whether the video was rejected by YouTube. If true, the reason
79
- # why the video was rejected can be obtained with +rejection_reason+.
80
- # @return [Boolean] if the resource is a video, whether the video was
81
- # rejected by YouTube.
82
- # @return [nil] if the resource is not a video.
83
- def rejected?
84
- upload_status == 'rejected' if video?
85
- end
86
-
87
- # Returns whether a video is being uploaded to YouTube.
88
- # @return [Boolean] if the resource is a video, whether the video is
89
- # being uploaded.
90
- # @return [nil] if the resource is not a video.
91
- def uploading?
92
- upload_status == 'uploaded' if video?
93
- end
94
-
95
- # @deprecated Use {uploading?} instead.
96
- def uploaded?
97
- uploading?
98
- end
99
-
100
- # Failure reason (Video only)
101
-
102
- # Returns the reason why a video failed to upload.
103
- # @return [String] if resource is a video with a 'failed' upload status,
104
- # the reason why the video failed to upload. Valid values are: codec,
105
- # conversion, emptyFile, invalidFile, tooSmall, uploadAborted.
106
- # @return [nil] if the resource is not a video or upload has not failed.
107
45
  has_attribute :failure_reason
108
-
109
- # Returns whether a video upload failed because of the codec.
110
- # @return [Boolean] if the resource is a video, whether the video uses
111
- # a codec not supported by YouTube.
112
- # @return [nil] if the resource is not a video or upload has not failed.
113
- # @see https://support.google.com/youtube/answer/1722171
114
- def uses_unsupported_codec?
115
- failure_reason == 'codec' if video?
116
- end
117
-
118
- # Returns whether YouTube was unable to convert an uploaded video.
119
- # @return [Boolean] if the resource is a video, whether YouTube was
120
- # unable to convert the video.
121
- # @return [nil] if the resource is not a video or upload has not failed.
122
- def has_failed_conversion?
123
- failure_reason == 'conversion' if video?
124
- end
125
-
126
- # Returns whether a video upload failed because the file was empty.
127
- # @return [Boolean] if the resource is a video, whether the video file
128
- # is empty.
129
- # @return [nil] if the resource is not a video or upload has not failed.
130
- def empty?
131
- failure_reason == 'emptyFile' if video?
132
- end
133
-
134
- # Returns whether a video upload failed because of the file format.
135
- # @return [Boolean] if the resource is a video, whether the video uses
136
- # a file format not supported by YouTube.
137
- # @return [nil] if the resource is not a video or upload has not failed.
138
- # @see https://support.google.com/youtube/troubleshooter/2888402?hl=en
139
- def invalid?
140
- failure_reason == 'invalidFile' if video?
141
- end
142
-
143
- # Returns whether a video upload failed because the file was too small.
144
- # @return [Boolean] if the resource is a video, whether the video file
145
- # is too small for YouTube.
146
- # @return [nil] if the resource is not a video or upload has not failed.
147
- def too_small?
148
- failure_reason == 'tooSmall' if video?
149
- end
150
-
151
- # Returns whether a video upload failed because the upload was aborted.
152
- # @return [Boolean] if the resource is a video, whether the uploading
153
- # process was aborted.
154
- # @return [nil] if the resource is not a video or upload has not failed.
155
- def aborted?
156
- failure_reason == 'uploadAborted' if video?
157
- end
158
-
159
- # Rejection reason (Video only)
160
-
161
- # Returns the reason why a video was rejected by YouTube.
162
- # @return [String] if resource is a video with a 'rejected' upload
163
- # status, the reason why the video was rejected. Valid values are:
164
- # claim, copyright, duplicate, inappropriate, length, termsOfUse,
165
- # trademark, uploaderAccountClosed, uploaderAccountSuspended.
166
- # @return [nil] if the resource is not a rejected video.
167
46
  has_attribute :rejection_reason
168
-
169
- # Returns whether a video was rejected because it was claimed.
170
- # @return [Boolean] if the resource is a rejected video, whether the
171
- # video was claimed by a different account.
172
- # @return [nil] if the resource is not a rejected video.
173
- def claimed?
174
- rejection_reason == 'claim' if video?
175
- end
176
-
177
- # Returns whether a video was rejected because of copyright infringement.
178
- # @return [Boolean] if the resource is a rejected video, whether the
179
- # video commits a copyright infringement.
180
- # @return [nil] if the resource is not a rejected video.
181
- def infringes_copyright?
182
- rejection_reason == 'copyright' if video?
183
- end
184
-
185
- # Returns whether a video was rejected because it is a duplicate.
186
- # @return [Boolean] if the resource is a rejected video, whether the
187
- # video is a duplicate of another uploaded video.
188
- # @return [nil] if the resource is not a rejected video.
189
- def duplicate?
190
- rejection_reason == 'duplicate' if video?
191
- end
192
-
193
- # Returns whether a video was rejected because of inappropriate content.
194
- # @return [Boolean] if the resource is a rejected video, whether the
195
- # video contains inappropriate content.
196
- # @return [nil] if the resource is not a rejected video.
197
- def inappropriate?
198
- rejection_reason == 'inappropriate' if video?
199
- end
200
-
201
- # Returns whether a video was rejected because it is too long.
202
- # @return [Boolean] if the resource is a rejected video, whether the
203
- # video exceeds the maximum duration.
204
- # @return [nil] if the resource is not a rejected video.
205
- # @see https://support.google.com/youtube/answer/71673?hl=en
206
- def too_long?
207
- rejection_reason == 'length' if video?
208
- end
209
-
210
- # Returns whether a video was rejected because it violates terms of use.
211
- # @return [Boolean] if the resource is a rejected video, whether the
212
- # video commits a terms of use violation.
213
- # @return [nil] if the resource is not a rejected video.
214
- def violates_terms_of_use?
215
- rejection_reason == 'termsOfUse' if video?
216
- end
217
-
218
- # Returns whether a video was rejected because of trademark infringement.
219
- # @return [Boolean] if the resource is a rejected video, whether the
220
- # video commits a trademark infringement.
221
- # @return [nil] if the resource is not a rejected video.
222
- # @see https://support.google.com/youtube/answer/2801979?hl=en
223
- def infringes_trademark?
224
- rejection_reason == 'trademark' if video?
225
- end
226
-
227
- # Returns whether a video was rejected because the account was closed.
228
- # @return [Boolean] if the resource is a rejected video, whether the
229
- # account associated with the video has been closed.
230
- # @return [nil] if the resource is not a rejected video.
231
- def belongs_to_closed_account?
232
- rejection_reason == 'uploaderAccountClosed' if video?
233
- end
234
-
235
- # Returns whether a video was rejected because the account was suspended.
236
- # @return [Boolean] if the resource is a rejected video, whether the
237
- # account associated with the video has been suspended.
238
- # @return [nil] if the resource is not a rejected video.
239
- def belongs_to_suspended_account?
240
- rejection_reason == 'uploaderAccountSuspended' if video?
241
- end
242
-
243
- # Scheduled publication (Video only)
244
-
245
- # Returns the date and time when a video is scheduled to be published.
246
- # @return [Time] if resource is a private video scheduled to be
247
- # published, the date and time when the video is scheduled to publish.
248
- # @return [nil] if the resource is not a private video scheduled to be
249
- # published.
250
- def scheduled_at
251
- publish_at if scheduled?
252
- end
253
-
254
- # Returns whether the video is scheduled to be published.
255
- # @return [Boolean] if the resource is a video, whether it is currently
256
- # private and is scheduled to become public in the future.
257
- # @return [nil] if the resource is not a video.
258
- def scheduled?
259
- private? && publish_at if video?
260
- end
261
-
262
- # License (Video only)
263
-
264
- # Returns the video’s license.
265
- # @return [String] if resource is a video, its license. Valid values are:
266
- # creativeCommon, youtube.
267
- # @return [nil] if the resource is not a video.
268
47
  has_attribute :license
269
-
270
- # Returns whether the video uses a Creative Commons license.
271
- # @return [Boolean] if the resource is a video, whether it uses a
272
- # Creative Commons license.
273
- # @return [nil] if the resource is not a video.
274
- # @see https://support.google.com/youtube/answer/2797468?hl=en
275
- def licensed_as_creative_commons?
276
- license == 'creativeCommon' if video?
277
- end
278
-
279
- # Returns whether the video uses the Standard YouTube license.
280
- # @return [Boolean] if the resource is a video, whether it uses the
281
- # Standard YouTube license.
282
- # @return [nil] if the resource is not a video.
283
- # @see https://www.youtube.com/static?template=terms
284
- def licensed_as_standard_youtube?
285
- license == 'youtube' if video?
286
- end
287
-
288
- # Embed (Video only)
289
-
290
- # Returns whether the video can be embedded on another website.
291
- # @return [Boolean] if the resource is a video, whether it can be
292
- # embedded on another website.
293
- # @return [nil] if the resource is not a video.
294
- has_attribute :embeddable?, from: :embeddable
295
-
296
- # @deprecated Use {#embeddable?} instead.
297
- def embeddable
298
- embeddable?
299
- end
300
-
301
- # Public stats (Video only)
302
-
303
- # Returns whether the video statistics are publicly viewable.
304
- # @return [Boolean] if the resource is a video, whether the extended
305
- # video statistics on the video’s watch page are publicly viewable.
306
- # By default, those statistics are viewable, and statistics like a
307
- # video’s viewcount and ratings will still be publicly visible even
308
- # if this property’s value is set to false.
309
- # @return [nil] if the resource is not a video.
310
- has_attribute :has_public_stats_viewable?, from: :public_stats_viewable
311
-
312
- # @deprecated Use {#has_public_stats_viewable?} instead.
313
- def public_stats_viewable
314
- has_public_stats_viewable?
315
- end
48
+ has_attribute :embeddable
49
+ has_attribute :public_stats_viewable
50
+ has_attribute :publish_at, type: Time
316
51
 
317
52
  private
318
53
 
319
- has_attribute :publish_at, type: Time
320
-
321
54
  def video?
322
55
  upload_status.present?
323
56
  end