35 lines
805 B
Ruby
35 lines
805 B
Ruby
|
|
class Utils
|
||
|
|
|
||
|
|
def self.username_url(username, site)
|
||
|
|
case site
|
||
|
|
when 'youtube'
|
||
|
|
"https://www.youtube.com/c/#{username}"
|
||
|
|
when 'facebook'
|
||
|
|
"https://www.facebook.com/#{username}"
|
||
|
|
when 'soundcloud'
|
||
|
|
"https://soundcloud.com/#{username}"
|
||
|
|
when 'bandcamp'
|
||
|
|
"http://#{username}.bandcamp.com"
|
||
|
|
when 'fandalism'
|
||
|
|
"http://fandalism.com/#{username}"
|
||
|
|
when 'twitter'
|
||
|
|
"https://twitter.com/#{username}"
|
||
|
|
when 'reverbnation'
|
||
|
|
"http://www.reverbnation.com/#{username}"
|
||
|
|
else
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def self.url_validator(url)
|
||
|
|
result = `curl --output /dev/null --silent --head --fail --show-error '#{url}' 2>&1`.chomp
|
||
|
|
if $?.success?
|
||
|
|
return nil
|
||
|
|
else
|
||
|
|
result =~ /curl: \(\d+\) (.*)/
|
||
|
|
return "#{$1} (#{url})"
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|