Class: Bright::SisApi::TSIS
Constant Summary collapse
- DATE_FORMAT =
"%m/%d/%Y"
- @@description =
"Connects to the TIES API for accessing TIES TSIS student information"
- @@doc_url =
"#unkown"
Instance Attribute Summary collapse
-
#connection_options ⇒ Object
Returns the value of attribute connection_options.
Instance Method Summary collapse
- #create_student(student) ⇒ Object
- #get_schools(params = {}, options = {}) ⇒ Object
- #get_student(params = {}, options = {}) ⇒ Object
- #get_student_by_api_id(api_id, params = {}) ⇒ Object
- #get_students(params = {}, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ TSIS
constructor
A new instance of TSIS.
- #request(method, path, params = {}) ⇒ Object
- #update_student(student) ⇒ Object
Methods inherited from Base
#connection_retry_wrapper, #filter_students_by_params
Constructor Details
#initialize(options = {}) ⇒ TSIS
Returns a new instance of TSIS.
14 15 16 17 18 19 20 21 22 |
# File 'lib/bright/sis_apis/tsis.rb', line 14 def initialize( = {}) self. = [:connection] || {} # { # :key => "", # :secret => "", # :district_id => "", # :uri => "" # } end |
Instance Attribute Details
#connection_options ⇒ Object
Returns the value of attribute connection_options.
12 13 14 |
# File 'lib/bright/sis_apis/tsis.rb', line 12 def @connection_options end |
Instance Method Details
#create_student(student) ⇒ Object
79 80 81 |
# File 'lib/bright/sis_apis/tsis.rb', line 79 def create_student(student) raise NotImplementedError, "TSIS does not support creating students" end |
#get_schools(params = {}, options = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bright/sis_apis/tsis.rb', line 87 def get_schools(params = {}, = {}) params = (params, ) # schools api end point takes page # in the url itself for some reason schools_response_hash = request(:get, apply_page_to_url("Schools/", [:page]), params) schools = schools_response_hash["Return"].collect { |hsh| School.new(convert_to_school_data(hsh)) } total_results = schools_response_hash["TotalCount"].to_i if [:wrap_in_collection] != false api = self load_more_call = proc { |page| # pages start at one, so add a page here api.get_schools(params, {wrap_in_collection: false, page: (page + 1)}) } ResponseCollection.new({ seed_page: schools, total: total_results, per_page: [:per_page], load_more_call: load_more_call }) else schools end end |
#get_student(params = {}, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bright/sis_apis/tsis.rb', line 28 def get_student(params = {}, = {}) params = (params, .merge({per_page: 1})) # Students only gets you students that are enrolled in a school for a given school year. students_response_hash = request(:get, "Students/", map_search_params(params)) found_student = nil if students_response_hash["Return"] and students_response_hash["Return"].first found_student = Student.new(convert_to_student_data(students_response_hash["Return"].first)) end if found_student.nil? # Students/Family can get you students that are not enrolled in a school for a given school year. family_response_hash = request(:get, "Students/Family/", map_search_params(params)) if family_response_hash["Return"] and family_response_hash["Return"].first found_student = Student.new(convert_to_student_data(family_response_hash["Return"].first)) end end found_student end |
#get_student_by_api_id(api_id, params = {}) ⇒ Object
24 25 26 |
# File 'lib/bright/sis_apis/tsis.rb', line 24 def get_student_by_api_id(api_id, params = {}) get_student(params.merge({sis_student_id: api_id})) end |
#get_students(params = {}, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bright/sis_apis/tsis.rb', line 47 def get_students(params = {}, = {}) params = (params, ) response_hash = if params[:schoolyear] # Students only gets you students that are enrolled in a school for a given school year. request(:get, apply_page_to_url("Students/", [:page]), map_search_params(params)) else # Students/Family can get you students that are not enrolled in a school for a given school year. request(:get, apply_page_to_url("Students/Family/", [:page]), map_search_params(params)) end students = response_hash["Return"].collect { |hsh| Student.new(convert_to_student_data(hsh)) } total_results = response_hash["TotalCount"].to_i if [:wrap_in_collection] != false api = self load_more_call = proc { |page| # pages start at one, so add a page here api.get_students(params, {wrap_in_collection: false, page: (page + 1)}) } ResponseCollection.new({ seed_page: students, total: total_results, per_page: [:per_page], load_more_call: load_more_call }) else students end end |
#request(method, path, params = {}) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/bright/sis_apis/tsis.rb', line 114 def request(method, path, params = {}) uri = "#{[:uri]}/#{path}" body = nil query = URI.encode(params.map { |k, v| "#{k}=#{v}" }.join("&")) if method == :get uri += "?#{query}" else body = query end response = connection_retry_wrapper { connection = Bright::Connection.new(uri) headers = headers_for_auth connection.request(method, body, headers) } if !response.error? response_hash = JSON.parse(response.body) end response_hash end |
#update_student(student) ⇒ Object
83 84 85 |
# File 'lib/bright/sis_apis/tsis.rb', line 83 def update_student(student) raise NotImplementedError, "TSIS does not support updating students" end |