Class: VkApi::FakeBrowser

Inherits:
Object
  • Object
show all
Defined in:
lib/vk-api/fake_browser.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ FakeBrowser

Returns a new instance of FakeBrowser.



2
3
4
# File 'lib/vk-api/fake_browser.rb', line 2

def initialize(params)
  @params = params
end

Instance Method Details

#request(url) ⇒ Object



47
48
49
50
# File 'lib/vk-api/fake_browser.rb', line 47

def request(url)
  agent.get(url)
  Oj.load agent.page.body
end

#responseObject



44
45
46
# File 'lib/vk-api/fake_browser.rb', line 44

def response
  @response ||= agent.page.uri.fragment.split('&').map{ |s| s.split '=' }.inject({}){ |a, (k,v)| a[k] = v; a }
end

#security_hack(login) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vk-api/fake_browser.rb', line 26

def security_hack()
  form = agent.page.form_with(action: /security_check/)

  if form
    hint = (agent.page / '.field_prefix').last.inner_html[1, 2]
    if [/#{hint}$/]
      form['code'] = [-10, 8]
      form.submit
    else
      raise VkApi::AuthError.new({
            error: 'Auth error',
            description: 'error 17'
          })
    end
  end

  agent
end

#sign_in(login, pass, type = :client) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vk-api/fake_browser.rb', line 6

def (, pass, type = :client)
  url = authorization_url type: type

  agent.get(url)
  agent.page.form_with(action: /login.vk.com/){|form| form.email = ; form.pass = pass}.submit

  url = agent
          .page
          .body
          .gsub("\n",'')
          .gsub('  ','')
          .match(/function allow.+?location.href\s?=\s?['"\s](.+?)['"].+\}/)
          .to_a
          .last

  agent.get(url)
rescue => err
  raise VkApi::AuthError.new({error: 'Auth error', description: 'Invalid login or password', more: err})
end