require mechanize class Promua def initialize parser Mechanize new sit

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'mechanize'
class Promua
def initialize
@parser = Mechanize.new
@site_url = "https://my.prom.ua/cabinet/sign-in"
@cabinet_url = "https://my.prom.ua/cabinet/product/edit/"
end
def sing_in
login_page = @parser.get(@site_url)
form = login_page.forms
cookie = (((@parser.cookies.find { |c| c.name == 'csrf_token' }).to_s).split("="))[1]
login_post = @parser.post("https://my.prom.ua/cabinet/auth/phone_login", {
phone_email:ENV['PROMUA_LOGIN'],
password: ENV['PROMUA_PASSWORD'],
csrf_token: cookie,
_save: 'YES'
})
end
def change_product id
product = @parser.get(@cabinet_url + id) do |page|
puts "===============" + product.to_s
end
end
end