Class: Bright::SisApi::OneRoster
- Inherits:
-
Base
show all
- Defined in:
- lib/bright/sis_apis/one_roster.rb
Defined Under Namespace
Classes: InfiniteCampus, Skyward
Constant Summary
collapse
- DEMOGRAPHICS_CONVERSION =
{
"americanIndianOrAlaskaNative" => "American Indian Or Alaska Native",
"asian" => "Asian",
"blackOrAfricanAmerican" => "Black Or African American",
"nativeHawaiianOrOtherPacificIslander" => "Native Hawaiian Or Other Pacific Islander",
"white" => "White",
"hispanicOrLatinoEthnicity" => "Hispanic Or Latino"
}
- @@description =
"Connects to the OneRoster API for accessing student information"
- @@doc_url =
"https://www.imsglobal.org/sites/default/files/spec/oneroster/v1p2/rostering-informationmodel/OneRosterv1p2RosteringService_InfoModelv1p0.html"
- @@api_version =
"1.2"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#connection_retry_wrapper, #filter_students_by_params
Constructor Details
#initialize(options = {}) ⇒ OneRoster
Returns a new instance of OneRoster.
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/bright/sis_apis/one_roster.rb', line 21
def initialize(options = {})
self.connection_options = options[:connection] || {}
end
|
Instance Attribute Details
#connection_options ⇒ Object
Returns the value of attribute connection_options.
10
11
12
|
# File 'lib/bright/sis_apis/one_roster.rb', line 10
def connection_options
@connection_options
end
|
#school_years_cache ⇒ Object
Returns the value of attribute school_years_cache.
10
11
12
|
# File 'lib/bright/sis_apis/one_roster.rb', line 10
def school_years_cache
@school_years_cache
end
|
#schools_cache ⇒ Object
Returns the value of attribute schools_cache.
10
11
12
|
# File 'lib/bright/sis_apis/one_roster.rb', line 10
def schools_cache
@schools_cache
end
|
Instance Method Details
#api_version ⇒ Object
32
33
34
|
# File 'lib/bright/sis_apis/one_roster.rb', line 32
def api_version
Gem::Version.new(connection_options.dig(:api_version) || @@api_version)
end
|
#create_student(student) ⇒ Object
85
86
87
|
# File 'lib/bright/sis_apis/one_roster.rb', line 85
def create_student(student)
raise NotImplementedError
end
|
132
133
134
135
|
# File 'lib/bright/sis_apis/one_roster.rb', line 132
def get_contact_by_api_id(api_id, params = {})
contact_hsh = request(:get, "users/#{api_id}", params)
Contact.new(convert_to_user_data(contact_hsh["user"], bright_type: "Contact")) if contact_hsh and contact_hsh["user"]
end
|
#get_school(params = {}, options = {}) ⇒ Object
98
99
100
|
# File 'lib/bright/sis_apis/one_roster.rb', line 98
def get_school(params = {}, options = {})
get_schools(params, options.merge(limit: 1, wrap_in_collection: false)).first
end
|
#get_school_by_api_id(api_id, params = {}) ⇒ Object
93
94
95
96
|
# File 'lib/bright/sis_apis/one_roster.rb', line 93
def get_school_by_api_id(api_id, params = {})
sc_hsh = request(:get, "schools/#{api_id}", params)
School.new(convert_to_school_data(sc_hsh["org"])) if sc_hsh and sc_hsh["org"]
end
|
#get_schools(params = {}, options = {}) ⇒ Object
102
103
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
129
130
|
# File 'lib/bright/sis_apis/one_roster.rb', line 102
def get_schools(params = {}, options = {})
params[:limit] = params[:limit] || options[:limit] || 100
schools_response_hash = request(:get, "schools", map_school_search_params(params))
total_results = schools_response_hash[:response_headers]["x-total-count"].to_i
if schools_response_hash and schools_response_hash["orgs"]
schools_hash = [schools_response_hash["orgs"]].flatten
schools = schools_hash.compact.collect { |sc_hsh|
School.new(convert_to_school_data(sc_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
46
47
48
|
# File 'lib/bright/sis_apis/one_roster.rb', line 46
def get_student(params = {}, options = {})
get_students(params, options.merge(limit: 1, wrap_in_collection: false)).first
end
|
#get_student_by_api_id(api_id, params = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/bright/sis_apis/one_roster.rb', line 36
def get_student_by_api_id(api_id, params = {})
params = if api_version <= Gem::Version.new("1.1")
{role: "student"}.merge(params)
else
{roles: "student"}.merge(params)
end
st_hsh = request(:get, "users/#{api_id}", params)
Student.new(convert_to_user_data(st_hsh["user"])) if st_hsh and st_hsh["user"]
end
|
#get_students(params = {}, options = {}) ⇒ Object
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
78
79
80
81
82
83
|
# File 'lib/bright/sis_apis/one_roster.rb', line 50
def get_students(params = {}, options = {})
params = if api_version <= Gem::Version.new("1.1")
{role: "student"}.merge(params)
else
{roles: "student"}.merge(params)
end
params[:limit] = params[:limit] || options[:limit] || 100
students_response_hash = request(:get, "users", map_search_params(params))
total_results = students_response_hash[:response_headers]["x-total-count"].to_i
if students_response_hash and students_response_hash["users"]
students_hash = [students_response_hash["users"]].flatten
students = students_hash.compact.collect { |st_hsh|
Student.new(convert_to_user_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/bright/sis_apis/one_roster.rb', line 137
def request(method, path, params = {})
uri = "#{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)
= (uri)
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
89
90
91
|
# File 'lib/bright/sis_apis/one_roster.rb', line 89
def update_student(student)
raise NotImplementedError
end
|