Skip to content

Commit

Permalink
Audit channel link on video description (youtube association)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangkyu committed Feb 16, 2016
1 parent f7cc1c3 commit 90557e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@ For more information about changelogs, check
[Keep a Changelog](http://keepachangelog.com) and
[Vandamme](http://tech-angels.github.io/vandamme).

## 0.1.3 - 2016.02.16

* [FEATURE] Add `has_link_to_own_channel?`

## 0.1.2 - 2016.02.11

* [FEATURE] Add `has_subscribe_annotations?`
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -31,4 +31,6 @@ Yt::Audit.has_brand_anchoring?('rF711XAtrVg', 'Budweiser')
# => true
Yt::Audit.has_subscribe_annotations?('rF711XAtrVg')
# => false
Yt::Audit.has_link_to_own_channel?('rF711XAtrVg')
# => false
```
10 changes: 10 additions & 0 deletions lib/yt/audit.rb
Expand Up @@ -29,5 +29,15 @@ def self.has_subscribe_annotations?(video_id)
annotation.link && annotation.link[:type] == :subscribe
end
end

# Audit youtube association of a video
# @param [String] video_id the video to audit.
# @return [Boolean] if the video description has link to its own channel.
def self.has_link_to_own_channel?(video_id)
video = Yt::Video.new(id: video_id)
video.description.split(' ')
.select {|word| Yt::URL.new(word).kind == :channel }
.any? {|link| Yt::Channel.new(url: link).id == video.channel_id }
end
end
end
2 changes: 1 addition & 1 deletion lib/yt/audit/version.rb
@@ -1,5 +1,5 @@
module Yt
module Audit
VERSION = "0.1.2"
VERSION = "0.1.3"
end
end
8 changes: 8 additions & 0 deletions test/yt/audit_test.rb
Expand Up @@ -34,4 +34,12 @@ def test_has_subscribe_annotations
def test_does_not_have_subscribe_annotations
assert_equal false, Yt::Audit.has_subscribe_annotations?(@bad_video_id)
end

def test_has_youtube_association
assert_equal true, Yt::Audit.has_link_to_own_channel?(@good_video_id)
end

def test_does_not_have_youtube_association
assert_equal false, Yt::Audit.has_link_to_own_channel?(@bad_video_id)
end
end

0 comments on commit 90557e1

Please sign in to comment.