Skip to content

Instantly share code, notes, and snippets.

@shunfan
Last active January 24, 2017 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shunfan/0e79896321c7c679ebb73cd6a1b778f2 to your computer and use it in GitHub Desktop.
Save shunfan/0e79896321c7c679ebb73cd6a1b778f2 to your computer and use it in GitHub Desktop.
RHIT Class Registration
#!/usr/bin/ruby
# INSTALL: gem install faraday
require 'faraday'
Faraday::Utils.default_params_encoder = Faraday::FlatParamsEncoder
username = ''
password = ''
term = ''
pin = ''
crn = [] << 0000 << 0000 << 0000 << 0000
class RegisterRobot
def initialize(username, password, term, pin, crn)
@username = username
@password = password
@term = term
@pin = pin
@crn = crn
end
# Log into the Banner
def login
res = @conn.post do |req|
req.url '/BanSS/twbkwbis.P_ValLogin'
req.params['sid'] = @username
req.params['PIN'] = @password
req.headers['Cookie'] = 'TESTID=set'
end
if res.body.include?('Invalid login') || res.body.include?('Error occurred during logon') || res.body.include?('Authorization Failure')
raise '[ERROR] Username and password do not match.'
end
@sessid = res.headers['Set-Cookie']
end
# Select term
def select_term
res = @conn.post do |req|
req.url '/BanSS/bwskfreg.P_AltPin'
req.params['term_in'] = @term
req.headers['Cookie'] = 'TESTID=set; ' + @sessid
end
if !res.body.include?('Registration PIN Verification')
raise '[ERROR] Term is incorrect.'
end
end
# Enter PIN
def enter_pin
res = @conn.post do |req|
req.url '/BanSS/bwskfreg.P_CheckAltPin'
req.params['pin'] = @pin
req.headers['Cookie'] = 'TESTID=set; ' + @sessid
end
if res.body.include? 'Authorization Failure - Invalid Alternate PIN.'
raise '[ERROR] PIN is incorrect.'
end
end
# Register classes
def register
res = @conn.post do |req|
req.url '/BanSS/bwckcoms.P_Regs'
req.params['term_in'] = @term
req.params['RSTS_IN'] = ['DUMMY'] + ['RW'] * @crn.size
req.params['assoc_term_in'] = ['DUMMY'] + [''] * @crn.size
req.params['CRN_IN'] = ['DUMMY'] + @crn
req.params['start_date_in'] = ['DUMMY'] + [''] * @crn.size
req.params['end_date_in'] = ['DUMMY'] + [''] * @crn.size
req.params['SUBJ'] = 'DUMMY'
req.params['CRSE'] = 'DUMMY'
req.params['SEC'] = 'DUMMY'
req.params['LEVL'] = 'DUMMY'
req.params['CRED'] = 'DUMMY'
req.params['GMOD'] = 'DUMMY'
req.params['TITLE'] = 'DUMMY'
req.params['MESG'] = 'DUMMY'
req.params['REG_BTN'] = ['DUMMY', 'Submit Changes']
req.params['regs_row'] = '0'
req.params['wait_row'] = '0'
req.params['add_row'] = @crn.size
req.headers['Cookie'] = 'TESTID=set; ' + @sessid
end
if res.body.include? 'Your Faculty, Advisor or Administrative Staff are reviewing your registration record at this time.'
puts '[INFO] The gate is not open.'
# Try again
register
else
puts '[INFO] Done.'
end
end
def run
@conn = Faraday.new(url: 'https://prod11gbss8.rose-hulman.edu')
login
select_term
enter_pin
register
end
end
robot = RegisterRobot.new(username, password, term, pin, crn)
robot.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment