-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmemrise.rb
40 lines (29 loc) · 872 Bytes
/
memrise.rb
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
31
32
33
34
35
36
37
38
39
40
require 'mechanize'
class Memrise
LOGIN_URL = 'https://www.memrise.com/login/'
public
def initialize args = {}
raise 'Username not provided.' unless args[:username]
raise 'Password not provided.' unless args[:password]
@agent = args[:agent] || Mechanize.new
@username = args[:username]
@password = args[:password]
login
end
def points
raise 'Dashboard (Home) not loaded.' unless @dashboard
@dashboard
.search('.content-stats .right .number').first.content
.gsub(',', '').to_i
end
private
def login
login_page = @agent.get LOGIN_URL
login_form = login_page.forms.first
login_form.username = @username
login_form.password = @password
dashboard = @agent.submit login_form
raise 'Login failed.' if dashboard.search('body.dashboard').empty?
@dashboard = dashboard
end
end