Skip to content

Commit ad9a728

Browse files
committed
Unify login process.
Make both Memrise and Beeminder sign in to the service upon object initialization.
1 parent 547828e commit ad9a728

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

memrise.rb

+20-13
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,39 @@ class Memrise
66

77
LOGIN_URL = 'https://www.memrise.com/login/'
88

9-
def initialize agent
9+
public
10+
def initialize agent, args = {}
11+
raise 'Username not provided.' unless args[:username]
12+
raise 'Password not provided.' unless args[:password]
13+
1014
@agent = agent
15+
16+
@username = args[:username]
17+
@password = args[:password]
18+
19+
login
1120
end
1221

13-
def login username, password
14-
raise 'Username not provided.' if username.to_s.empty?
15-
raise 'Password not provided.' if password.to_s.empty?
22+
def points
23+
raise 'Dashboard (Home) not loaded.' unless @dashboard
24+
@dashboard
25+
.search('.content-stats .right .number').first.content
26+
.gsub(',', '').to_i
27+
end
1628

29+
private
30+
def login
1731
login_page = @agent.get LOGIN_URL
1832
login_form = login_page.forms.first
1933

20-
login_form.username = username
21-
login_form.password = password
34+
login_form.username = @username
35+
login_form.password = @password
2236

2337
dashboard = @agent.submit login_form
2438
raise 'Login failed.' if dashboard.search('body.dashboard').empty?
2539
@dashboard = dashboard
2640
end
2741

28-
def points
29-
raise 'Dashboard (Home) not loaded.' unless @dashboard
30-
@dashboard
31-
.search('.content-stats .right .number').first.content
32-
.gsub(',', '').to_i
33-
end
34-
3542
end
3643

3744
memrise = Memrise.new Mechanize.new

0 commit comments

Comments
 (0)