Class: Bright::SisApi::Base

Inherits:
Object show all
Defined in:
lib/bright/sis_apis/base.rb

Direct Known Subclasses

Aeries, BrightSis, Focus, OneRoster, PowerSchool, Synergy, TSIS

Instance Method Summary collapse

Instance Method Details

#connection_retry_wrapper(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bright/sis_apis/base.rb', line 23

def connection_retry_wrapper(&block)
  retry_attempts = connection_options[:retry_attempts] || 2
  retries = 0
  begin
    yield
  rescue Bright::ResponseError => e
    retries += 1
    if e.server_error? && retries <= retry_attempts.to_i
      puts "retrying #{retries}: #{e.class} - #{e}"
      sleep(retries * 3)
      retry
    else
      raise
    end
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Net::ReadTimeout, Net::OpenTimeout, SocketError, EOFError => e
    retries += 1
    if retries <= retry_attempts.to_i
      puts "retrying #{retries}: #{e.class} - #{e}"
      sleep(retries * 3)
      retry
    else
      raise
    end
  end
end

#filter_students_by_params(students, params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bright/sis_apis/base.rb', line 4

def filter_students_by_params(students, params)
  total = params[:limit]
  count = 0
  found = []

  keys = (Student.attribute_names & params.keys.collect(&:to_sym))
  puts "filtering on #{keys.join(",")}"
  students.each do |student|
    break if total and count >= total

    should = keys.all? do |m|
      student.send(m) =~ Regexp.new(Regexp.escape(params[m]), Regexp::IGNORECASE)
    end
    count += 1 if total and should
    found << student if should
  end
  found
end