yt 0.5.4 → 0.5.5

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