Class: Bright::SisApi::Focus
- Inherits:
-
Base
show all
- Defined in:
- lib/bright/sis_apis/focus.rb
Constant Summary
collapse
- DEFAULT_NO_THREADS =
2
- 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 Focus OneRoster API for accessing student information"
- @@doc_url =
""
- @@api_version =
"1.1"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#connection_retry_wrapper, #filter_students_by_params
Constructor Details
#initialize(options = {}) ⇒ Focus
Returns a new instance of Focus.
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/bright/sis_apis/focus.rb', line 23
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/focus.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/focus.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/focus.rb', line 10
def schools_cache
@schools_cache
end
|
Instance Method Details
#api_version ⇒ Object
34
35
36
|
# File 'lib/bright/sis_apis/focus.rb', line 34
def api_version
Gem::Version.new(connection_options.dig(:api_version) || @@api_version)
end
|
#create_student(student) ⇒ Object
77
78
79
|
# File 'lib/bright/sis_apis/focus.rb', line 77
def create_student(student)
raise NotImplementedError
end
|
124
125
126
127
|
# File 'lib/bright/sis_apis/focus.rb', line 124
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
90
91
92
|
# File 'lib/bright/sis_apis/focus.rb', line 90
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
85
86
87
88
|
# File 'lib/bright/sis_apis/focus.rb', line 85
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/bright/sis_apis/focus.rb', line 94
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
43
44
45
|
# File 'lib/bright/sis_apis/focus.rb', line 43
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
38
39
40
41
|
# File 'lib/bright/sis_apis/focus.rb', line 38
def get_student_by_api_id(api_id, params = {})
st_hsh = request(:get, "students/#{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
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
|
# File 'lib/bright/sis_apis/focus.rb', line 47
def get_students(params = {}, options = {})
params[:limit] = params[:limit] || options[:limit] || 100
students_response_hash = request(:get, "students", 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] || DEFAULT_NO_THREADS
})
else
students
end
end
|
#request(method, path, params = {}) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/bright/sis_apis/focus.rb', line 129
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
81
82
83
|
# File 'lib/bright/sis_apis/focus.rb', line 81
def update_student(student)
raise NotImplementedError
end
|