yt 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/HISTORY.md +3 -0
- data/README.md +2 -4
- data/bin/yt +0 -7
- data/lib/yt/actions/delete.rb +3 -3
- data/lib/yt/actions/insert.rb +3 -3
- data/lib/yt/actions/list.rb +4 -6
- data/lib/yt/actions/update.rb +7 -5
- data/lib/yt/associations/authentications.rb +114 -0
- data/lib/yt/associations.rb +1 -0
- data/lib/yt/collections/annotations.rb +2 -2
- data/lib/yt/collections/authentications.rb +42 -0
- data/lib/yt/collections/base.rb +1 -1
- data/lib/yt/collections/playlist_items.rb +1 -1
- data/lib/yt/collections/snippets.rb +1 -2
- data/lib/yt/collections/subscriptions.rb +1 -1
- data/lib/yt/collections/user_infos.rb +2 -2
- data/lib/yt/config.rb +0 -2
- data/lib/yt/errors/missing_auth.rb +50 -0
- data/lib/yt/errors/no_items.rb +5 -9
- data/lib/yt/errors/request_error.rb +52 -0
- data/lib/yt/models/account.rb +17 -44
- data/lib/yt/models/annotation.rb +117 -115
- data/lib/yt/models/authentication.rb +27 -0
- data/lib/yt/models/base.rb +9 -5
- data/lib/yt/models/channel.rb +6 -4
- data/lib/yt/models/configuration.rb +27 -35
- data/lib/yt/models/description.rb +61 -59
- data/lib/yt/models/details_set.rb +26 -24
- data/lib/yt/models/id.rb +3 -1
- data/lib/yt/models/playlist.rb +38 -36
- data/lib/yt/models/playlist_item.rb +29 -27
- data/lib/yt/models/rating.rb +18 -16
- data/lib/yt/models/request.rb +95 -73
- data/lib/yt/models/resource.rb +19 -17
- data/lib/yt/models/snippet.rb +39 -37
- data/lib/yt/models/status.rb +20 -18
- data/lib/yt/models/subscription.rb +24 -22
- data/lib/yt/models/url.rb +68 -68
- data/lib/yt/models/user_info.rb +51 -49
- data/lib/yt/models/video.rb +6 -4
- data/lib/yt/version.rb +1 -1
- data/spec/associations/device_auth/authentications_spec.rb +78 -0
- data/spec/associations/device_auth/channels_spec.rb +2 -4
- data/spec/associations/device_auth/details_sets_spec.rb +4 -5
- data/spec/associations/device_auth/ids_spec.rb +2 -3
- data/spec/associations/device_auth/playlist_items_spec.rb +3 -4
- data/spec/associations/device_auth/playlists_spec.rb +14 -15
- data/spec/associations/device_auth/ratings_spec.rb +2 -4
- data/spec/associations/device_auth/snippets_spec.rb +5 -7
- data/spec/associations/device_auth/subscriptions_spec.rb +2 -4
- data/spec/associations/device_auth/user_infos_spec.rb +2 -5
- data/spec/associations/device_auth/videos_spec.rb +3 -5
- data/spec/associations/server_auth/details_sets_spec.rb +1 -1
- data/spec/associations/server_auth/ids_spec.rb +1 -1
- data/spec/associations/server_auth/playlist_items_spec.rb +1 -1
- data/spec/associations/server_auth/playlists_spec.rb +1 -1
- data/spec/associations/server_auth/snippets_spec.rb +1 -1
- data/spec/associations/server_auth/videos_spec.rb +1 -1
- data/spec/collections/playlist_items_spec.rb +3 -4
- data/spec/collections/subscriptions_spec.rb +2 -3
- data/spec/errors/missing_auth_spec.rb +10 -0
- data/spec/errors/no_items_spec.rb +2 -1
- data/spec/errors/request_error_spec.rb +18 -0
- data/spec/models/configuration_spec.rb +0 -17
- data/spec/models/description_spec.rb +5 -5
- data/spec/models/request_spec.rb +1 -7
- data/spec/models/subscription_spec.rb +2 -3
- data/spec/models/url_spec.rb +6 -6
- data/spec/support/fail_matcher.rb +1 -1
- data/spec/support/global_hooks.rb +33 -0
- metadata +15 -14
- data/lib/yt/errors/base.rb +0 -43
- data/lib/yt/errors/error.rb +0 -8
- data/lib/yt/errors/failed.rb +0 -17
- data/lib/yt/errors/unauthenticated.rb +0 -34
- data/spec/errors/failed_spec.rb +0 -9
- data/spec/errors/unauthenticated_spec.rb +0 -9
- data/spec/support/device_app.rb +0 -15
- data/spec/support/server_app.rb +0 -10
data/lib/yt/models/playlist.rb
CHANGED
@@ -1,50 +1,52 @@
|
|
1
1
|
require 'yt/models/resource'
|
2
2
|
|
3
3
|
module Yt
|
4
|
-
|
5
|
-
|
4
|
+
module Models
|
5
|
+
class Playlist < Resource
|
6
|
+
has_many :playlist_items
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def delete
|
9
|
+
do_delete {@id = nil}
|
10
|
+
!exists?
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
def update(options = {})
|
14
|
+
options[:title] ||= title
|
15
|
+
options[:description] ||= description
|
16
|
+
options[:tags] ||= tags
|
17
|
+
options[:privacy_status] ||= privacy_status
|
18
|
+
|
19
|
+
snippet = options.slice :title, :description, :tags
|
20
|
+
status = {privacyStatus: options[:privacy_status]}
|
21
|
+
body = {id: @id, snippet: snippet, status: status}
|
22
|
+
|
23
|
+
do_update(params: {part: 'snippet,status'}, body: body) do |data|
|
24
|
+
@id = data['id']
|
25
|
+
@snippet = Snippet.new data: data['snippet'] if data['snippet']
|
26
|
+
@status = Status.new data: data['status'] if data['status']
|
27
|
+
true
|
28
|
+
end
|
28
29
|
end
|
29
|
-
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def exists?
|
32
|
+
!@id.nil?
|
33
|
+
end
|
34
34
|
|
35
|
-
|
35
|
+
private
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def delete_params
|
38
|
+
super.tap do |params|
|
39
|
+
params[:path] = '/youtube/v3/playlists'
|
40
|
+
params[:params] = {id: @id}
|
41
|
+
end
|
41
42
|
end
|
42
|
-
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def update_params
|
45
|
+
super.tap do |params|
|
46
|
+
params[:path] = '/youtube/v3/playlists'
|
47
|
+
params[:body_type] = :json
|
48
|
+
params[:expected_response] = Net::HTTPOK
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -1,41 +1,43 @@
|
|
1
1
|
require 'yt/models/base'
|
2
2
|
|
3
3
|
module Yt
|
4
|
-
|
5
|
-
|
4
|
+
module Models
|
5
|
+
class PlaylistItem < Base
|
6
|
+
attr_reader :id, :video, :position
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def initialize(options = {})
|
9
|
+
@id = options[:id]
|
10
|
+
@auth = options[:auth]
|
11
|
+
if options[:snippet]
|
12
|
+
@position = options[:snippet]['position']
|
13
|
+
@video = Video.new video_params_for options
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def delete
|
18
|
+
do_delete {@id = nil}
|
19
|
+
!exists?
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def exists?
|
23
|
+
!@id.nil?
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
private
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def delete_params
|
29
|
+
super.tap do |params|
|
30
|
+
params[:path] = '/youtube/v3/playlistItems'
|
31
|
+
params[:params] = {id: @id}
|
32
|
+
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def video_params_for(options = {})
|
36
|
+
{}.tap do |params|
|
37
|
+
params[:id] = options[:snippet].fetch('resourceId', {})['videoId']
|
38
|
+
params[:snippet] = options[:snippet].except 'resourceId'
|
39
|
+
params[:auth] = options[:auth]
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
data/lib/yt/models/rating.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
require 'yt/models/base'
|
2
2
|
|
3
3
|
module Yt
|
4
|
-
|
5
|
-
|
4
|
+
module Models
|
5
|
+
class Rating < Base
|
6
|
+
attr_reader :rating
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def initialize(options = {})
|
9
|
+
@rating = options[:rating].to_sym if options[:rating]
|
10
|
+
@video_id = options[:video_id]
|
11
|
+
@auth = options[:auth]
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def update(new_rating)
|
15
|
+
do_update(params: {rating: new_rating}) {@rating = new_rating}
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
+
private
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def update_params
|
21
|
+
super.tap do |params|
|
22
|
+
params[:method] = :post
|
23
|
+
params[:path] = '/youtube/v3/videos/rate'
|
24
|
+
params[:params] = {id: @video_id}
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/yt/models/request.rb
CHANGED
@@ -4,99 +4,121 @@ require 'json' # for JSON.parse
|
|
4
4
|
require 'active_support/core_ext' # for Hash.from_xml, Hash.to_param
|
5
5
|
|
6
6
|
require 'yt/config'
|
7
|
-
require 'yt/errors/
|
8
|
-
require 'yt/errors/
|
7
|
+
require 'yt/errors/missing_auth'
|
8
|
+
require 'yt/errors/request_error'
|
9
9
|
|
10
10
|
module Yt
|
11
|
-
|
12
|
-
|
13
|
-
options
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
module Models
|
12
|
+
class Request
|
13
|
+
def initialize(options = {})
|
14
|
+
@auth = options[:auth]
|
15
|
+
@body = options[:body]
|
16
|
+
@body_type = options.fetch :body_type, :json
|
17
|
+
@expected_response = options.fetch :expected_response, Net::HTTPSuccess
|
18
|
+
@format = options.fetch :format, :json
|
19
|
+
@headers = options.fetch :headers, {}
|
20
|
+
@host = options.fetch :host, google_api_host
|
21
|
+
@method = options.fetch :method, :get
|
22
|
+
@path = options[:path]
|
23
|
+
@query = options.fetch(:params, {}).to_param
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def run
|
27
|
+
case response
|
28
|
+
when @expected_response
|
29
|
+
response.tap{|response| response.body = parse_format response.body}
|
30
|
+
when Net::HTTPUnauthorized
|
31
|
+
raise Errors::MissingAuth, request_error_message
|
28
32
|
else
|
29
|
-
raise
|
33
|
+
raise Yt::Error, request_error_message
|
30
34
|
end
|
31
35
|
end
|
32
|
-
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
private
|
38
|
+
|
39
|
+
def response
|
40
|
+
@response ||= Net::HTTP.start(*net_http_options) do |http|
|
41
|
+
http.request http_request
|
42
|
+
end
|
39
43
|
end
|
40
|
-
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
elsif Yt.configuration.api_key
|
48
|
-
params = URI.decode_www_form @uri.query || ''
|
49
|
-
params << [:key, Yt.configuration.api_key]
|
50
|
-
@uri.query = URI.encode_www_form params
|
51
|
-
else
|
52
|
-
raise Errors::Unauthenticated, to_error
|
45
|
+
def http_request
|
46
|
+
@http_request ||= net_http_class.new(uri.request_uri).tap do |request|
|
47
|
+
set_headers! request
|
48
|
+
set_body! request
|
49
|
+
end
|
53
50
|
end
|
54
|
-
end
|
55
51
|
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
def set_headers!(request)
|
53
|
+
if @body_type == :json
|
54
|
+
request.initialize_http_header 'Content-Type' => 'application/json'
|
55
|
+
request.initialize_http_header 'Content-length' => '0' unless @body
|
56
|
+
end
|
57
|
+
@headers.each{|name, value| request.add_field name, value}
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
request.initialize_http_header 'Content-Type' => 'application/json'
|
66
|
-
request.initialize_http_header 'Content-length' => '0' unless @body
|
67
|
-
request.body = @body.to_json if @body
|
68
|
-
when :form
|
69
|
-
request.set_form_data @body if @body
|
60
|
+
def set_body!(request)
|
61
|
+
case @body_type
|
62
|
+
when :json then request.body = @body.to_json
|
63
|
+
when :form then request.set_form_data @body
|
64
|
+
end if @body
|
70
65
|
end
|
71
|
-
@headers.each{|k,v| request.add_field k, v}
|
72
66
|
|
73
|
-
|
74
|
-
|
67
|
+
def net_http_options
|
68
|
+
[uri.host, uri.port, use_ssl: true]
|
75
69
|
end
|
76
|
-
end
|
77
70
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
def net_http_class
|
72
|
+
"Net::HTTP::#{@method.capitalize}".constantize
|
73
|
+
end
|
74
|
+
|
75
|
+
def uri
|
76
|
+
@uri ||= build_uri
|
77
|
+
end
|
84
78
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
msg[:headers] = @headers
|
89
|
-
msg[:url] = @uri.to_s
|
90
|
-
msg[:body] = @body
|
79
|
+
def build_uri
|
80
|
+
add_authorization! if @host == google_api_host
|
81
|
+
URI::HTTPS.build host: @host, path: @path, query: @query
|
91
82
|
end
|
92
83
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
84
|
+
def add_authorization!
|
85
|
+
if @auth.respond_to? :access_token
|
86
|
+
@headers['Authorization'] = "Bearer #{@auth.access_token}"
|
87
|
+
elsif Yt.configuration.api_key
|
88
|
+
params = URI.decode_www_form @query || ''
|
89
|
+
params << [:key, Yt.configuration.api_key]
|
90
|
+
@query = URI.encode_www_form params
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def google_api_host
|
95
|
+
'www.googleapis.com'
|
96
|
+
end
|
98
97
|
|
99
|
-
|
98
|
+
def parse_format(body)
|
99
|
+
case @format
|
100
|
+
when :xml then Hash.from_xml body
|
101
|
+
when :json then JSON body
|
102
|
+
end if body
|
103
|
+
end
|
104
|
+
|
105
|
+
def request_error_message
|
106
|
+
{}.tap do |message|
|
107
|
+
message[:request_curl] = as_curl
|
108
|
+
message[:response_body] = JSON(response.body) rescue response.body
|
109
|
+
end.to_json
|
110
|
+
end
|
111
|
+
|
112
|
+
def as_curl
|
113
|
+
'curl'.tap do |curl|
|
114
|
+
curl << " -X #{http_request.method}"
|
115
|
+
http_request.each_header do |name, value|
|
116
|
+
curl << %Q{ -H "#{name}: #{value}"}
|
117
|
+
end
|
118
|
+
curl << %Q{ -d '#{http_request.body}'} if http_request.body
|
119
|
+
curl << %Q{ "#{@uri.to_s}"}
|
120
|
+
end
|
121
|
+
end
|
100
122
|
end
|
101
123
|
end
|
102
124
|
end
|
data/lib/yt/models/resource.rb
CHANGED
@@ -2,26 +2,28 @@ require 'yt/models/base'
|
|
2
2
|
require 'yt/models/url'
|
3
3
|
|
4
4
|
module Yt
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module Models
|
6
|
+
class Resource < Base
|
7
|
+
attr_reader :auth
|
8
|
+
has_one :id
|
9
|
+
has_one :snippet, delegate: [:title, :description, :thumbnail_url, :published_at, :tags]
|
10
|
+
has_one :status, delegate: [:privacy_status, :public?, :private?, :unlisted?]
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def initialize(options = {})
|
13
|
+
@url = URL.new(options[:url]) if options[:url]
|
14
|
+
@id = options[:id] || (@url.id if @url)
|
15
|
+
@auth = options[:auth]
|
16
|
+
@snippet = Snippet.new(data: options[:snippet]) if options[:snippet]
|
17
|
+
@status = Status.new(data: options[:status]) if options[:status]
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def kind
|
21
|
+
@url ? @url.kind.to_s : self.class.to_s.demodulize.underscore
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def username
|
25
|
+
@url.username if @url
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/yt/models/snippet.rb
CHANGED
@@ -1,48 +1,50 @@
|
|
1
1
|
require 'yt/models/description'
|
2
2
|
|
3
3
|
module Yt
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Models
|
5
|
+
class Snippet
|
6
|
+
def initialize(options = {})
|
7
|
+
@data = options[:data]
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
# Return the title of the YouTube resource.
|
11
|
+
#
|
12
|
+
# @return [String] Title of the YouTube resource
|
13
|
+
def title
|
14
|
+
@title ||= @data.fetch 'title', ''
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# Return the description of a YouTube resource.
|
18
|
+
#
|
19
|
+
# @return [Yt::Description] A Yt::Description object for the YouTube resource
|
20
|
+
def description
|
21
|
+
@description ||= Description.new @data.fetch('description', '')
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
# Return the publication date of a YouTube resource.
|
25
|
+
#
|
26
|
+
# @return [Time or nil] The publication date for the YouTube resource
|
27
|
+
def published_at
|
28
|
+
@published_at ||= Time.parse @data['publishedAt']
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
# Return the tags of a YouTube resource.
|
32
|
+
#
|
33
|
+
# @return [Array] An array of Yt::Tag object, one for each tag of the resource.
|
34
|
+
#
|
35
|
+
# @note YouTube API only includes tags in a resource’s snippet if the
|
36
|
+
# resource is a video belonging to the authenticated account.
|
37
|
+
def tags
|
38
|
+
@tags ||= @data.fetch 'tags', []
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
# Return the URL of a thumbnail image of the YouTube resource.
|
42
|
+
#
|
43
|
+
# @return [String] A URL.
|
44
|
+
def thumbnail_url(size = :default)
|
45
|
+
@thumbnails ||= @data.fetch 'thumbnails', {}
|
46
|
+
@thumbnails.fetch(size.to_s, {})['url']
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
data/lib/yt/models/status.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
module Yt
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Models
|
3
|
+
class Status
|
4
|
+
def initialize(options = {})
|
5
|
+
@data = options[:data]
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# @return [Boolean] Is the resource public?
|
9
|
+
def public?
|
10
|
+
privacy_status == 'public'
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# @return [Boolean] Is the resource private?
|
14
|
+
def private?
|
15
|
+
privacy_status == 'private'
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
# @return [Boolean] Is the resource unlisted?
|
19
|
+
def unlisted?
|
20
|
+
privacy_status == 'unlisted'
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
def privacy_status
|
24
|
+
@privacy_status ||= @data['privacyStatus']
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
require 'yt/models/base'
|
2
2
|
|
3
3
|
module Yt
|
4
|
-
|
4
|
+
module Models
|
5
|
+
class Subscription < Base
|
5
6
|
|
6
|
-
|
7
|
+
attr_reader :id
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(options = {})
|
10
|
+
@id = options[:id]
|
11
|
+
@auth = options[:auth]
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def delete(options = {})
|
15
|
+
begin
|
16
|
+
do_delete {@id = nil}
|
17
|
+
rescue Yt::Error => error
|
18
|
+
ignorable_errors = error.reasons & ['subscriptionNotFound']
|
19
|
+
raise error unless options[:ignore_errors] && ignorable_errors.any?
|
20
|
+
end
|
21
|
+
!exists?
|
19
22
|
end
|
20
|
-
!exists?
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def exists?
|
25
|
+
!@id.nil?
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
private
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def delete_params
|
31
|
+
super.tap do |params|
|
32
|
+
params[:path] = '/youtube/v3/subscriptions'
|
33
|
+
params[:params] = {id: @id}
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|