Module: Openapply::GetManyStudents
- Included in:
- Client
- Defined in:
- lib/openapply/get_many_students.rb
Instance Method Summary collapse
- #many_ids_updated_time(params) ⇒ Object
- #many_students_details(params, options = {}) ⇒ Object
- #many_students_details_by_ids(ids, options = {}) ⇒ Object
- #many_students_ids(params) ⇒ Object
- #many_students_summaries(params = {}) ⇒ Object
- #url_for_many_students_summaries(status = nil, since_id = nil, since_date = nil, count = api_records) ⇒ Object
Instance Method Details
#many_ids_updated_time(params) ⇒ Object
Note:
Get all student ids & guardian ids with associated last updated timestamp (matching the criteria in params)
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/openapply/get_many_students.rb', line 51 def many_ids_updated_time( params ) response = many_students_summaries( params ) kids = response[:students].map{ |kid| {kid[:id] => kid[:updated_at]} } rents = response[:guardians].map{ |rent| {rent[:id] => rent[:updated_at]} } { ids_updated_at: { students: kids, guardians: rents, } } end |
#many_students_details(params, options = {}) ⇒ Object
Note:
Get all student details matching the criteria in params
10 11 12 13 14 |
# File 'lib/openapply/get_many_students.rb', line 10 def many_students_details( params, ={} ) ids = many_students_ids( params ) return {error: "need an array of ids"} unless ids[:ids] return many_students_details_by_ids( ids[:ids], ) end |
#many_students_details_by_ids(ids, options = {}) ⇒ Object
Note:
Get all student details matching the criteria in params
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/openapply/get_many_students.rb', line 19 def many_students_details_by_ids( ids, ={} ) return {error: 'no ids provided'} if ids.nil? or ids.empty? students = [] guardians = [] ids = [ids] unless ids.is_a? Array ids.each do |id| response = one_student_details_by_id( id, ) # pp response students << response[:student] guardians << response[:guardians] end return { students: students, guardians: guardians, } end |
#many_students_ids(params) ⇒ Object
Note:
Get all student ids matching the criteria in params
40 41 42 43 44 |
# File 'lib/openapply/get_many_students.rb', line 40 def many_students_ids( params ) response = many_students_summaries( params ) ids = response[:students].map{ |kid| kid[:id] } { ids: ids } end |
#many_students_summaries(params = {}) ⇒ Object
Note:
Get all student summaries matching the criteria in params
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/openapply/get_many_students.rb', line 67 def many_students_summaries( params={} ) # status=nil,since_id=nil,since_date=nil,count=api_records) return {error: 'no query provided'} if params.empty? students = [] guardians = [] count = params[:count] count ||= api_records() since_date = params[:since_date] statuses = params[:status] statuses = [statuses] if not statuses.nil? and statuses.is_a? String statuses.each do |status| page_number = nil since_id = params[:since_id] # loop until all pages recieved while page_number.nil? or page_number > 1 url = url_for_many_students_summaries(status, since_id, since_date, count) answer = oa_answer( url ) break if answer.nil? or answer[:students].nil? or answer[:students].empty? students += answer[:students] guardians += answer[:linked][:parents] last_student = answer[:students].last since_id = last_student[:id] page_number = answer[:meta][:pages].to_i unless answer[:meta].nil? page_number = 0 if answer[:meta].nil? end end return { students: students, guardians: guardians, } end |
#url_for_many_students_summaries(status = nil, since_id = nil, since_date = nil, count = api_records) ⇒ Object
Note:
Get url to query for student summaries matching the criteria in params
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/openapply/get_many_students.rb', line 105 def url_for_many_students_summaries(status=nil, since_id=nil, since_date=nil, count=api_records) = [] << "status=#{status}" unless status.to_s.eql? "" << "since_id=#{since_id}" unless since_id.to_s.eql? "" << "since_date=#{since_date}" unless since_date.to_s.eql? "" << "count=#{count}" << "auth_token=#{api_key}" return "#{api_path}?#{.join('&')}" end |