cycu_csys_bookmarker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cycu_csys_bookmarker.rb +61 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ceb9c89ce448055b0593b5c10909cbcbf35f64af
4
+ data.tar.gz: c1969965213c25bbd05edc885d04a9a46a00c92f
5
+ SHA512:
6
+ metadata.gz: 56614bcead57206bbd4a9097131ad0a55a2086fc00d656a1dac9afc75ef9044f259a62ff9b8edbe580e2343e33bed3dd4529ed1feb0ebb93a40e553277a2e9b5
7
+ data.tar.gz: 4faa211cb9ab9b99d7662f2c8f4acbe214ebbed36b6c136a75cf5a7ae999336028cc01a8cd0ebb17ae3db8c84c33eab9dd9a6dcf7a7bee8e86cd439d430e9f4f
@@ -0,0 +1,61 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ require 'json'
4
+
5
+ class CycuCsysBookmarker
6
+ def initialize(student_id, password)
7
+ @student_id = student_id
8
+ @password = password
9
+ @http = Net::HTTP.new('csys.cycu.edu.tw')
10
+ @loggedin = false
11
+ init_cookie()
12
+ end
13
+
14
+ def login
15
+ return false if @loggedin
16
+ init_secure_random()
17
+ resp = @http.post('/sso/sso.srv', "cmd=login&userid=#{@student_id}&hash=#{login_hash}", {'Cookie' => @cookie})
18
+ resp_json = JSON.parse(resp.body)
19
+ @page_id = resp_json['pageId']
20
+ @loggedin = true
21
+ end
22
+
23
+ def logout
24
+ return false unless @loggedin
25
+ resp = @http.post('/sso/sso.srv', 'cmd=logout', {'Cookie' => @cookie})
26
+ @loggedin = false
27
+ end
28
+
29
+ def bookmark(list = [])
30
+ return false unless @loggedin
31
+ headers = { 'Cookie' => @cookie, 'Page-Id' => @page_id }
32
+ path = '/student/op/StudentCourseTrace.srv'
33
+
34
+ list.each do |item|
35
+ resp = @http.post(path, "cmd=insert&op_code=#{item}", headers)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def init_cookie
42
+ resp = @http.get('/index.jsp')
43
+ raw_cookies = resp.response['set-cookie']
44
+
45
+ cookies = []
46
+ raw_cookies.split(/, ?/).each do |raw_cookie|
47
+ cookies << raw_cookie.split(';')[0]
48
+ end
49
+ @cookie = cookies.join(';')
50
+ end
51
+
52
+ def init_secure_random
53
+ resp = @http.post('/sso/sso.srv', 'cmd=login_init', {'Cookie' => @cookie})
54
+ resp_json = JSON.parse(resp.body)
55
+ @secure_random = resp_json['secureRandom']
56
+ end
57
+
58
+ def login_hash
59
+ OpenSSL::HMAC.hexdigest('sha256', @password, @student_id + @secure_random)
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cycu_csys_bookmarker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sh Lin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Automatically bookmark courses for you on CYCU's CSYS system.
14
+ email: commit@atifans.net
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/cycu_csys_bookmarker.rb
20
+ homepage: http://rubygems.org/gems/cycu_csys_bookmarker
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: CYCU courses bookmarker.
44
+ test_files: []