Module: VkMusic::Utility::ProfileIdResolver

Defined in:
lib/vk_music/utility/profile_id_resolver.rb

Overview

Get user or group id from url

Constant Summary collapse

VK_PATH =

vk.com url regex

%r{(?:https?://)?(?:vk\.com/)?([^/?&]+)}.freeze
AUDIOS_PATH =

audios list page

/audios(-?\d+)/.freeze
USER_PATH =

vk.com user path regex

/id(\d+)/.freeze
CLUB_PATH =

vk.com user club regex

/(?:club|group|public|event)(\d+)/.freeze

Class Method Summary collapse

Class Method Details

.call(agent, url) ⇒ Integer?

Returns ID of profile or nil if not a profile page.

Parameters:

  • agent (Mechanize)
  • url (String)

    URL to profile page

Returns:

  • (Integer?)

    ID of profile or nil if not a profile page



27
28
29
30
31
32
33
34
35
36
37
38
39
# 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