Module: Openapply::GetManyStudents

Included in:
Client
Defined in:
lib/openapply/get_many_students.rb

Instance Method Summary collapse

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)

Parameters:

  • params (:status)
    • (String or Array of Strings) - list the status wanted

  • params (:since_id)
    • (Integer) - get all ids matching the criteria LARGER than the given number

  • params (:since_date)
    • (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)

  • params (:count)
    • (Integer) - The number of customers to return - large numbers need a large timeout



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

Parameters:

  • params (:status)
    • (String or Array of Strings) - list the status wanted

  • params (:since_id)
    • (Integer) - get all ids matching the criteria LARGER than the given number

  • params (:since_date)
    • (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)

  • params (:count)
    • (Integer) - The number of customers to return - large numbers need a large timeout

  • options (:get_payments) (defaults to: {})

    (Boolean) - get student payments



10
11
12
13
14
# File 'lib/openapply/get_many_students.rb', line 10

def many_students_details( params, options={} )
  ids = many_students_ids( params )
  return {error: "need an array of ids"}          unless ids[:ids]
  return many_students_details_by_ids( ids[:ids], options )
end

#many_students_details_by_ids(ids, options = {}) ⇒ Object

Note:

Get all student details matching the criteria in params

Parameters:

  • ids
    • (Array of Integers) - list ids wanted to lookup

  • options (:get_payments) (defaults to: {})

    (Boolean) - get student payments



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, options={} )
  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, options )
    # 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

Parameters:

  • params (:status)
    • (String or Array of Strings) - list the status wanted

  • params (:since_id)
    • (Integer) - get all ids matching the criteria LARGER than the given number

  • params (:since_date)
    • (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)

  • params (:count)
    • (Integer) - The number of customers to return - large numbers need a large timeout



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

Parameters:

  • params (:status) (defaults to: {})
    • (String or Array of Strings) - list the status wanted

  • params (:since_id) (defaults to: {})
    • (Integer) - get all ids matching the criteria LARGER than the given number

  • params (:since_date) (defaults to: {})
    • (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)

  • params (:count) (defaults to: {})
    • (Integer) - The number of customers to return - large numbers need a large timeout



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

Parameters:

  • status (defaults to: nil)
    • (String or Array of Strings) - list the status wanted

  • since_id (defaults to: nil)
    • (Integer) - get all ids matching the criteria LARGER than the given number

  • since_date (defaults to: nil)
    • (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)

  • count (defaults to: api_records)
    • (Integer) - The number of customers to return - large numbers need a large timeout



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)
  url_options = []
  url_options << "status=#{status}"         unless status.to_s.eql? ""
  url_options << "since_id=#{since_id}"     unless since_id.to_s.eql? ""
  url_options << "since_date=#{since_date}" unless since_date.to_s.eql? ""
  url_options << "count=#{count}"
  url_options << "auth_token=#{api_key}"

  return "#{api_path}?#{url_options.join('&')}"
end