Class: Bright::SisApi::Aeries

Inherits:
Base show all
Defined in:
lib/bright/sis_apis/aeries.rb

Constant Summary collapse

DATE_FORMAT =
"%Y-%m-%dT%H:%M:%S"
@@description =
"Connects to the Aeries API for accessing student information"
@@doc_url =
"http://www.aeries.com/downloads/docs.1234/TechnicalSpecs/Aeries_API_Documentation.pdf"
@@api_version =
""

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#connection_retry_wrapper, #filter_students_by_params

Constructor Details

#initialize(options = {}) ⇒ Aeries

Returns a new instance of Aeries.



12
13
14
15
16
17
18
# File 'lib/bright/sis_apis/aeries.rb', line 12

def initialize(options = {})
  self.connection_options = options[:connection] || {}
  # {
  #   :certficate => "",
  #   :uri => ""
  # }
end

Instance Attribute Details

#connection_optionsObject

Returns the value of attribute connection_options.



10
11
12
# File 'lib/bright/sis_apis/aeries.rb', line 10

def connection_options
  @connection_options
end

Instance Method Details

#create_student(student) ⇒ Object

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/bright/sis_apis/aeries.rb', line 57

def create_student(student)
  raise NotImplementedError
end

#get_schools(params = {}) ⇒ Object



65
66
67
68
69
# File 'lib/bright/sis_apis/aeries.rb', line 65

def get_schools(params = {})
  schools_response_hash = request(:get, "api/v2/schools", params)

  schools_response_hash.collect { |h| School.new(convert_to_school_data(h)) }
end

#get_student(params) ⇒ Object



24
25
26
# File 'lib/bright/sis_apis/aeries.rb', line 24

def get_student(params)
  get_students(params.merge(limit: 1)).first
end

#get_student_by_api_id(api_id) ⇒ Object



20
21
22
# File 'lib/bright/sis_apis/aeries.rb', line 20

def get_student_by_api_id(api_id)
  get_students({api_id: api_id, limit: 1}).first
end

#get_students(params) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bright/sis_apis/aeries.rb', line 28

def get_students(params)
  if params.has_key?(:school) or params.has_key?(:school_api_id)
    school_api_id = params.delete(:school) || params.delete(:school_api_id)
    students = get_students_by_school(school_api_id, params)
  else
    threads = []
    get_schools.each do |school|
      threads << Thread.new do
        get_students_by_school(school, params)
      end
    end
    students = threads.collect(&:value).flatten.compact
  end
  filter_students_by_params(students, params)
end

#get_students_by_school(school, params = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bright/sis_apis/aeries.rb', line 44

def get_students_by_school(school, params = {})
  school_api_id = school.is_a?(School) ? school.api_id : school
  path = if params.has_key?(:api_id)
    "api/schools/#{school_api_id}/students/#{params[:api_id]}"
  elsif params.has_key?(:sis_student_id)
    "api/schools/#{school_api_id}/students/sn/#{params[:sis_student_id]}"
  else
    "api/schools/#{school_api_id}/students"
  end
  students_response_hash = request(:get, path, map_student_search_params(params))
  students_response_hash.collect { |shsh| Student.new(convert_to_student_data(shsh)) }
end

#request(method, path, params = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/bright/sis_apis/aeries.rb', line 71

def request(method, path, params = {})
  uri = "#{connection_options[:uri]}/#{path}"
  body = nil
  if method == :get
    query = URI.encode_www_form(params)
    uri += "?#{query}"
  else
    body = JSON.dump(params)
  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)
  else
    puts "#{response.inspect}"
    puts "#{response.body}"
  end
  response_hash
end

#update_student(student) ⇒ Object

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/bright/sis_apis/aeries.rb', line 61

def update_student(student)
  raise NotImplementedError
end