File tree 1 file changed +20
-13
lines changed
1 file changed +20
-13
lines changed Original file line number Diff line number Diff line change @@ -6,32 +6,39 @@ class Memrise
6
6
7
7
LOGIN_URL = 'https://www.memrise.com/login/'
8
8
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
+
10
14
@agent = agent
15
+
16
+ @username = args [ :username ]
17
+ @password = args [ :password ]
18
+
19
+ login
11
20
end
12
21
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
16
28
29
+ private
30
+ def login
17
31
login_page = @agent . get LOGIN_URL
18
32
login_form = login_page . forms . first
19
33
20
- login_form . username = username
21
- login_form . password = password
34
+ login_form . username = @ username
35
+ login_form . password = @ password
22
36
23
37
dashboard = @agent . submit login_form
24
38
raise 'Login failed.' if dashboard . search ( 'body.dashboard' ) . empty?
25
39
@dashboard = dashboard
26
40
end
27
41
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
-
35
42
end
36
43
37
44
memrise = Memrise . new Mechanize . new
You can’t perform that action at this time.
0 commit comments