module VkMusic::Utility::ProfileIdResolver
Get user or group id from url
Constants
- AUDIOS_PATH
audios list page
- CLUB_PATH
vk.com user club regex
- USER_PATH
vk.com user path regex
- VK_PATH
vk.com url regex
Public Class Methods
call(agent, url)
click to toggle source
@param agent [Mechanize] @param url [String] URL to profile page @return [Integer?] ID of profile or nil
if not a profile page
# File lib/vk_music/utility/profile_id_resolver.rb, line 27 def call(agent, url) path = url.match(VK_PATH)&.captures&.first return unless path direct_match = direct_match(path) return direct_match if direct_match request = VkMusic::Request::Profile.new(profile_custom_path: path) request.call(agent) request.id rescue Mechanize::ResponseCodeError nil end
Private Class Methods
direct_match(path)
click to toggle source
# File lib/vk_music/utility/profile_id_resolver.rb, line 43 def direct_match(path) audios_match = path.match(AUDIOS_PATH) return Integer(audios_match.captures.first, 10) if audios_match user_match = path.match(USER_PATH) return Integer(user_match.captures.first, 10) if user_match club_match = path.match(CLUB_PATH) return -1 * Integer(club_match.captures.first, 10) if club_match nil end