jam-cloud/web/lib/utils.rb

38 lines
956 B
Ruby

class Utils
USERNAME_SITES = %W{youtube facebook soundcloud bandcamp fandalism twitter reverbnation}
SITE_TYPES = ['url'].concat(USERNAME_SITES)
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.site_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