Class: Bright::SisApi::BrightSis
- Inherits:
-
Base
show all
- Defined in:
- lib/bright/sis_apis/bright_sis.rb
Constant Summary
collapse
- DEMOGRAPHICS_CONVERSION =
{
"I"=>"American Indian Or Alaska Native",
"A"=>"Asian",
"B"=>"Black Or African American",
"P"=>"Native Hawaiian Or Other Pacific Islander",
"W"=>"White",
"M"=>"Other"
}
- @@description =
"Connects to the Bright SIS Data Store"
- @@doc_url =
""
- @@api_version =
"v1"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#connection_retry_wrapper, #filter_students_by_params
Constructor Details
#initialize(options = {}) ⇒ BrightSis
Returns a new instance of BrightSis.
20
21
22
23
24
25
26
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 20
def initialize(options = {})
self.connection_options = options[:connection] || {}
end
|
Instance Attribute Details
#connection_options ⇒ Object
Returns the value of attribute connection_options.
9
10
11
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 9
def connection_options
@connection_options
end
|
Instance Method Details
#create_student(student) ⇒ Object
66
67
68
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 66
def create_student(student)
raise NotImplementedError
end
|
#get_schools(params = {}, options = {}) ⇒ Object
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
99
100
101
102
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 74
def get_schools(params = {}, options = {})
params[:limit] = params[:limit] || options[:limit] || 100
schools_response_hash = self.request(:get, 'schools', self.map_school_search_params(params))
total_results = schools_response_hash[:response_headers]["total"].to_i
if schools_response_hash and schools_response_hash["schools"]
schools_hash = [schools_response_hash["schools"]].flatten
schools = schools_hash.compact.collect {|st_hsh|
School.new(convert_to_school_data(st_hsh))
}
end
if options[:wrap_in_collection] != false
api = self
load_more_call = proc { |page|
params[:offset] = (params[:limit].to_i * page)
api.get_schools(params, {:wrap_in_collection => false})
}
ResponseCollection.new({
:seed_page => schools,
:total => total_results,
:per_page => params[:limit],
:load_more_call => load_more_call,
:no_threads => options[:no_threads]
})
else
schools
end
end
|
#get_student(params = {}, options = {}) ⇒ Object
32
33
34
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 32
def get_student(params = {}, options = {})
self.get_students(params, options.merge(:limit => 1, :wrap_in_collection => false)).first
end
|
#get_student_by_api_id(api_id, options = {}) ⇒ Object
28
29
30
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 28
def get_student_by_api_id(api_id, options = {})
self.get_students({"uuid" => api_id}, options.merge(:limit => 1, :wrap_in_collection => false)).first
end
|
#get_students(params = {}, options = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 36
def get_students(params = {}, options = {})
params[:limit] = params[:limit] || options[:limit] || 100
students_response_hash = self.request(:get, 'students', self.map_student_search_params(params))
total_results = students_response_hash[:response_headers]["total"].to_i
if students_response_hash and students_response_hash["students"]
students_hash = [students_response_hash["students"]].flatten
students = students_hash.compact.collect {|st_hsh|
Student.new(convert_to_student_data(st_hsh))
}
end
if options[:wrap_in_collection] != false
api = self
load_more_call = proc { |page|
params[:offset] = (params[:limit].to_i * page)
api.get_students(params, {:wrap_in_collection => false})
}
ResponseCollection.new({
:seed_page => students,
:total => total_results,
:per_page => params[:limit],
:load_more_call => load_more_call,
:no_threads => options[:no_threads]
})
else
students
end
end
|
#request(method, path, params = {}) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 104
def request(method, path, params = {})
uri = "#{self.connection_options[:uri]}/#{path}"
body = nil
if method == :get
query = URI.encode_www_form(params)
uri += "?#{query}" unless query.strip == ""
else
body = JSON.dump(params)
end
response = connection_retry_wrapper {
connection = Bright::Connection.new(uri)
= self.
connection.request(method, body, )
}
if !response.error?
response_hash = JSON.parse(response.body)
response_hash[:response_headers] = response.
else
puts "#{response.inspect}"
puts "#{response.body}"
end
response_hash
end
|
#update_student(student) ⇒ Object
70
71
72
|
# File 'lib/bright/sis_apis/bright_sis.rb', line 70
def update_student(student)
raise NotImplementedError
end
|