Module: PsUtilities::PreBuiltGet

Included in:
Connection
Defined in:
lib/ps_utilities/pre_built_get.rb

Instance Method Summary collapse

Instance Method Details

#get_all_active_students(params = {}) ⇒ Object Also known as: all_active_students, active_students

return all active students within the district (special case of #get_all_matching_students) - a recursive search

Parameters:

  • params (Hash) (defaults to: {})
    • page_size: is the only parameter accepted - default is 100



8
9
10
11
12
# File 'lib/ps_utilities/pre_built_get.rb', line 8

def get_all_active_students(params={})
  page_size = params[:page_size] || 100
  params    = {status_code: 0, page_size: page_size}
  get_all_matching_students(params)
end

#get_all_matching_students(params) ⇒ Hash of an Array of Student Summaries Also known as: all_matching_students, matching_students, find_all_students, find_students

Note:
  • the api_path sent to the api call looks like: “/ws/v1/district/student?expansions=school_enrollment,contact&q=enroll_status==A;name.last_name==J*”

return all students within the district matching the filters are passed in – this is a Recursive search and will collect all students or “x” or “0” or “John” or “Br*” or multiple field match

{status_code: "0", last_name: "Br*"}

[

  {"id"=>4916, "local_id"=>112406, "student_username"=>"cccc406", "name"=>{"first_name"=>"Ssssss", "last_name"=>"CCCCC"},
  "local_id"=>112520, "student_username"=>"jjjj520", "name"=>{"first_name"=>"Ppppppp", "last_name"=>"JJJJJJJJ"},
  "local_id"=>112766, "student_username"=>"aaaa766", "name"=>{"first_name"=>"Sssss", "middle_name"=>"Aaaaaaaa", "last_name"=>"Aaaaaaaaaa"}
]

}

Parameters:

  • params (Hash)
    • enter a match criteria in the following format (* are allowed for wildcard matching):

    “xxxxx*” or “12345”

Returns:

  • (Hash of an Array of Student Summaries)
    • see below format



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ps_utilities/pre_built_get.rb', line 31

def get_all_matching_students(params)
  params[:page_size] ||= 100
  count    = get_matching_students_count(params)
  pages    = calc_pages(count, params[:page_size])
  answer   = {}
  students = []
  (1..pages).each do |page|
    params[:page_number] = page
    answer    = get_matching_students_page(params)
    students << (answer.dig("students","student") || [])
  end
  # answer["students"]["student"] = students.flatten
  # return answer
  { students: students.flatten }
end

#get_one_student(params) ⇒ Hash Also known as: get_student

Note:

the data within “u_students_extension” - is unique for each school

retrieves all individual student’s details - you must use the DCID !!! { :student=>

{ "@expansions"=> "demographics, addresses, alerts, phones, school_enrollment, ethnicity_race, contact, contact_info, initial_enrollment, schedule_setup, fees, lunch",
  "@extensions"=> "s_stu_crdc_x,activities,c_studentlocator,u_students_extension,u_studentsuserfields,s_stu_ncea_x,s_stu_edfi_x,studentcorefields",
  "_extension_data"=> {
    "_table_extension"=> [
      { "recordFound"=>false,
        "_field"=> [
          {"name"=>"preferredname", "type"=>"String", "value"=>"Guy"},
          {"name"=>"student_email", "type"=>"String", "value"=>"[email protected]"}
        ],
        "name"=>"u_students_extension"
      },
      { "recordFound"=>false,
        "_field"=> [
          {"name"=>"transcriptaddrzip", "type"=>"String", "value"=>1858},
          {"name"=>"transcriptaddrcountry", "type"=>"String", "value"=>"CH"},
          {"name"=>"transcriptaddrcity", "type"=>"String", "value"=>"Bex"},
          {"name"=>"transcriptaddrstate", "type"=>"String", "value"=>"VD"},
          {"name"=>"transcriptaddrline1", "type"=>"String", "value"=>"LAS"},
          {"name"=>"transcriptaddrline2", "type"=>"String", "value"=>"CP 108"}
        ],
        "name"=>"u_studentsuserfields"
      }
    ]
  },
  "id"=>7337,
  "local_id"=>555807,
  "student_username"=>"guy807",
  "name"=>{"first_name"=>"Mountain", "last_name"=>"BIV"},
  "demographics"=>{"gender"=>"M", "birth_date"=>"2002-08-26", "projected_graduation_year"=>2021},
  "addresses"=>"",
  "alerts"=>"",
  "phones"=>"",
  "school_enrollment"=> {
    "enroll_status"=>"A",
    "enroll_status_description"=>"Active",
    "enroll_status_code"=>0,
    "grade_level"=>9,
    "entry_date"=>"2018-06-22",
    "exit_date"=>"2019-08-06",
    "school_number"=>2,
    "school_id"=>2,
    "full_time_equivalency"=>{"fteid"=>970, "name"=>"FTE Admissions"}
  },
  "ethnicity_race"=>{"federal_ethnicity"=>"NO"},
  "contact"=>{"guardian_email"=>"[email protected]"},
  "contact_info"=>{"email"=>"[email protected]"},
  "initial_enrollment"=>{"district_entry_grade_level"=>0, "school_entry_grade_level"=>0},
  "schedule_setup"=>{"next_school"=>33, "sched_next_year_grade"=>10},
  "fees"=>"",
  "lunch"=>{"balance_1"=>"0.00", "balance_2"=>"0.00", "balance_3"=>"0.00", "balance_4"=>"0.00", "lunch_id"=>0}
}

}

Parameters:

  • params (Hash)
    • use either: “12345” or “12345”

Returns:

  • (Hash)
    • in the format of:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ps_utilities/pre_built_get.rb', line 108

def get_one_student(params)
  # api_path = "/ws/v1/district/student/{dcid}?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
  ps_dcid    = params[:dcid] || params[:dc_id] || params[:id]
  api_path   = "/ws/v1/student/#{ps_dcid.to_i}"
  options    = { query:
                  { "extensions" => "s_stu_crdc_x,activities,c_studentlocator,u_students_extension,u_studentsuserfields,s_stu_ncea_x,s_stu_edfi_x,studentcorefields",
                    "expansions" => "demographics,addresses,alerts,phones,school_enrollment,ethnicity_race,contact,contact_info,initial_enrollment,schedule_setup,fees,lunch"
                  }
                }
  return {"errorMessage"=>{"message"=>"A valid dcid must be entered."}} if "#{ps_dcid.to_i}".eql? "0"

  answer = api(:get, api_path, options)
  return { student: (answer["student"] || []) }  if answer.code.to_s.eql? "200"
  # return { student: (answer.parsed_response["student"] || []) } if answer.code.to_s.eql? "200"
  return {"errorMessage"=>"#{answer.response}"}
end