Class: VkMusicLoader::Authorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/vk_music_loader/authorizer.rb

Constant Summary collapse

AUTH_FILE_PATH =
File.expand_path('~') + '/.vk_music_loader/auth_data'
API_CHECK_AUDIO_METHOD_PATH =
'http://api.xn--41a.ws/api.php'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_key = nil) ⇒ Authorizer

Returns a new instance of Authorizer.



7
8
9
# File 'lib/vk_music_loader/authorizer.rb', line 7

def initialize(auth_key = nil)
  @auth_key = auth_key
end

Class Method Details

.auth_key_valid?(auth_key) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'lib/vk_music_loader/authorizer.rb', line 11

def self.auth_key_valid?(auth_key)
  uri = URI(API_CHECK_AUDIO_METHOD_PATH)
  uri.query = URI.encode_www_form(key: auth_key, method: :by_owner, owner_id: :dummy)

  req = Net::HTTP::Get.new(uri)
  res = Net::HTTP.new(uri.host, uri.port).request(req)

  res.body != 'wrong key' && res.body != 'key wrong format'
end

Instance Method Details

#performObject



21
22
23
# File 'lib/vk_music_loader/authorizer.rb', line 21

def perform
  get_auth_token
end