Skip to content

Instantly share code, notes, and snippets.

@antonrogov
Created June 21, 2010 15:29
Show Gist options
  • Save antonrogov/447019 to your computer and use it in GitHub Desktop.
Save antonrogov/447019 to your computer and use it in GitHub Desktop.
# to create a new student
s1 = Sevis::Student.new(
:personal_info => {
:birth_date => '1986/12/01',
#...
},
:educational_info => {
:edu_level => {
:level => '...'
#...
}
}
)
s1.personal_info.birth_date = Time.parse('1986/12/01')
s1.educational_info.level = '...'
s1.new_record? # true
# to validate student record
s1.valid?
s1.errors # {"personal_info" => {"first_name" => "can't be blank"}, "issue_reason" => "can't be blank"}
# to update existing student simply add id field (request_id from sevis)
s2 = Sevis::Student.new(:id => 123, ...)
s2.new_record? # false
# to create a new batch operation
b = Sevis::Batch.new
b.students << s1
b.students << s2
# to validate all records
b.valid? # will set b.errors and s1.errors and s2.errors accrodingly
b.errors # errors from all records
# to batch upload student records
log = b.upload # generates batch id, new students ids and returns transaction log
# to request batch status
log = b.check_status! # will download attached PDFs to Sevis.pdf_download_dir if
# batch is completed and update students pdf attribute with
# correct path, returns transaction log
b.completed? # calls check_status! if status hasn't been checked yet and returns true
# if all records had been processed, on subsequent calls doesn't query
# SEVIS
# to request status of another batch
b2 = Sevis::Batch.new(:id => 123)
b2.completed?
@teejayvanslyke
Copy link

This looks like it's in the right direction. Can you formalize these in specs?

Thank you,

T.J.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment