Module: Googol::Subscriptions
- Included in:
- YoutubeAccount
- Defined in:
- lib/googol/youtube_account/subscriptions.rb
Overview
Separate module to group YoutubeAccount methods related to subscriptions.
Instance Method Summary collapse
-
#subscribe_to(channel = {}) ⇒ String
Subscribe a Youtube account to a channel.
-
#subscribe_to!(channel = {}) ⇒ String
Subscribe a Youtube account to a channel.
-
#unsubscribe_from(channel = {}) ⇒ Object
Unsubscribe a Youtube account from a channel.
-
#unsubscribe_from!(channel = {}) ⇒ Object
Unsubscribe a Youtube account from a channel.
Instance Method Details
#subscribe_to(channel = {}) ⇒ String
Subscribe a Youtube account to a channel. If the account is already subscribed, return the existing channel subscription ID.
33 34 35 36 37 38 39 40 41 |
# File 'lib/googol/youtube_account/subscriptions.rb', line 33 def subscribe_to(channel = {}) subscribe_to! channel rescue Googol::RequestError => e if e.to_s =~ /subscriptionDuplicate/ find_subscription_by channel else raise e end end |
#subscribe_to!(channel = {}) ⇒ String
Subscribe a Youtube account to a channel. If the account is already subscribed, raise an error.
14 15 16 17 18 |
# File 'lib/googol/youtube_account/subscriptions.rb', line 14 def subscribe_to!(channel = {}) channel_id = fetch! channel, :channel_id youtube_request! path: '/subscriptions?part=snippet', json: true, method: :post, body: {snippet: {resourceId: {channelId: channel_id}}} end |
#unsubscribe_from(channel = {}) ⇒ Object
Unsubscribe a Youtube account from a channel. If the account is not subscribed, ignore the request.
68 69 70 71 72 73 74 75 76 |
# File 'lib/googol/youtube_account/subscriptions.rb', line 68 def unsubscribe_from(channel = {}) unsubscribe_from! channel rescue Googol::RequestError => e if e.to_s =~ /subscriptionNotFound/ true else raise e end end |
#unsubscribe_from!(channel = {}) ⇒ Object
Unsubscribe a Youtube account from a channel. If the account is not subscribed, raise an error.
53 54 55 |
# File 'lib/googol/youtube_account/subscriptions.rb', line 53 def unsubscribe_from!(channel = {}) delete_subscription!(find_subscription_by channel) end |