bright 0.1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,11 +14,11 @@ module Bright
14
14
  raise NotImplementedError
15
15
  end
16
16
 
17
- def create_student(student, additional_params = {})
17
+ def create_student(student)
18
18
  raise NotImplementedError
19
19
  end
20
20
 
21
- def update_student(student, additional_params = {})
21
+ def update_student(student)
22
22
  raise NotImplementedError
23
23
  end
24
24
 
@@ -5,12 +5,12 @@ module Bright
5
5
  module SisApi
6
6
  class TSIS < Base
7
7
  DATE_FORMAT = '%m/%d/%Y'
8
-
8
+
9
9
  @@description = "Connects to the TIES API for accessing TIES TSIS student information"
10
10
  @@doc_url = "#unkown"
11
-
11
+
12
12
  attr_accessor :connection_options
13
-
13
+
14
14
  def initialize(options = {})
15
15
  self.connection_options = options[:connection] || {}
16
16
  # {
@@ -20,17 +20,17 @@ module Bright
20
20
  # :uri => ""
21
21
  # }
22
22
  end
23
-
23
+
24
24
  def get_student_by_api_id(api_id, params = {})
25
25
  self.get_student(params.merge({:sis_student_id => api_id}))
26
26
  end
27
-
27
+
28
28
  def get_student(params = {}, options = {})
29
29
  params = self.apply_options(params, options.merge({:per_page => 1}))
30
30
 
31
31
  # Students only gets you students that are enrolled in a school for a given school year.
32
32
  students_response_hash = self.request(:get, 'Students/', self.map_search_params(params))
33
- found_student = nil
33
+ found_student = nil
34
34
  if students_response_hash["Return"] and students_response_hash["Return"].first
35
35
  found_student = Student.new(convert_to_student_data(students_response_hash["Return"].first))
36
36
  end
@@ -43,10 +43,10 @@ module Bright
43
43
  end
44
44
  found_student
45
45
  end
46
-
46
+
47
47
  def get_students(params = {}, options = {})
48
48
  params = self.apply_options(params, options)
49
-
49
+
50
50
  if params[:schoolyear]
51
51
  # Students only gets you students that are enrolled in a school for a given school year.
52
52
  response_hash = self.request(:get, self.apply_page_to_url('Students/', options[:page]), self.map_search_params(params))
@@ -54,10 +54,10 @@ module Bright
54
54
  # Students/Family can get you students that are not enrolled in a school for a given school year.
55
55
  response_hash = self.request(:get, self.apply_page_to_url('Students/Family/', options[:page]), self.map_search_params(params))
56
56
  end
57
-
57
+
58
58
  students = response_hash["Return"].collect{|hsh| Student.new(convert_to_student_data(hsh))}
59
59
  total_results = response_hash["TotalCount"].to_i
60
-
60
+
61
61
  if options[:wrap_in_collection] != false
62
62
  api = self
63
63
  load_more_call = proc { |page|
@@ -66,24 +66,24 @@ module Bright
66
66
  }
67
67
 
68
68
  ResponseCollection.new({
69
- :seed_page => students,
69
+ :seed_page => students,
70
70
  :total => total_results,
71
- :per_page => options[:per_page],
71
+ :per_page => options[:per_page],
72
72
  :load_more_call => load_more_call
73
73
  })
74
74
  else
75
75
  students
76
76
  end
77
77
  end
78
-
79
- def create_student(student, additional_params = {})
78
+
79
+ def create_student(student)
80
80
  raise NotImplementedError, "TSIS does not support creating students"
81
81
  end
82
-
83
- def update_student(student, additional_params = {})
82
+
83
+ def update_student(student)
84
84
  raise NotImplementedError, "TSIS does not support updating students"
85
85
  end
86
-
86
+
87
87
  def get_schools(params = {}, options = {})
88
88
  params = self.apply_options(params, options)
89
89
 
@@ -110,7 +110,7 @@ module Bright
110
110
  schools
111
111
  end
112
112
  end
113
-
113
+
114
114
  def request(method, path, params = {})
115
115
  uri = "#{self.connection_options[:uri]}/#{path}"
116
116
  body = nil
@@ -120,22 +120,24 @@ module Bright
120
120
  else
121
121
  body = query
122
122
  end
123
-
124
- headers = self.headers_for_auth(uri)
125
123
 
126
- connection = Bright::Connection.new(uri)
127
- response = connection.request(method, body, headers)
124
+ response = connection_retry_wrapper {
125
+ connection = Bright::Connection.new(uri)
126
+ headers = self.headers_for_auth
127
+ connection.request(method, body, headers)
128
+ }
129
+
128
130
  if !response.error?
129
131
  response_hash = JSON.parse(response.body)
130
132
  end
131
133
  response_hash
132
134
  end
133
-
135
+
134
136
  protected
135
-
137
+
136
138
  def map_search_params(params)
137
139
  params = params.dup
138
-
140
+
139
141
  params["studentname"] = params.delete(:name)
140
142
  params["studentname"] ||= "#{params.delete(:last_name)}, #{params.delete(:first_name)} #{params.delete(:middle_name)}".strip
141
143
  params["studentids"] = params.delete(:sis_student_id)
@@ -147,10 +149,10 @@ module Bright
147
149
  k = k.to_s.gsub(/[^A-Za-z]/, "").downcase
148
150
  [k,v]
149
151
  end]
150
-
152
+
151
153
  params.reject{|k,v| v.respond_to?(:empty?) ? v.empty? : v.nil?}
152
154
  end
153
-
155
+
154
156
  def convert_to_student_data(attrs)
155
157
  catt = {}
156
158
  if attrs["StudentName"]
@@ -170,7 +172,7 @@ module Bright
170
172
  catt[:middle_name] = attrs["MiddleName"].strip
171
173
  catt[:last_name] = (attrs["LastName"] || attrs["SurName"]).strip
172
174
  end
173
-
175
+
174
176
  catt[:state_student_id] = (attrs["StateId"] || attrs["StudentStateId"]).to_s
175
177
  catt[:sis_student_id] = attrs["StudentId"].to_s
176
178
  catt[:api_id] = attrs["StudentId"].to_s
@@ -180,18 +182,18 @@ module Bright
180
182
 
181
183
  bd = attrs["BirthDate"] || attrs["StudentBirthDate"]
182
184
  if !(bd.nil? or bd.empty?)
183
- begin
185
+ begin
184
186
  catt[:birth_date] = Date.strptime(bd, DATE_FORMAT)
185
187
  rescue => e
186
188
  puts "#{e.inspect} #{bd}"
187
189
  end
188
190
  end
189
-
191
+
190
192
  catt[:addresses] = [self.convert_to_address_data(attrs["Address"])] if attrs["Address"]
191
-
193
+
192
194
  catt.reject{|k,v| v.respond_to?(:empty?) ? v.empty? : v.nil?}
193
195
  end
194
-
196
+
195
197
  def convert_to_address_data(attrs)
196
198
  cattrs = {}
197
199
 
@@ -204,38 +206,38 @@ module Bright
204
206
  cattrs[:state] = attrs["State"]
205
207
  cattrs[:postal_code] = attrs["Zip"]
206
208
  cattrs[:type] = attrs["Type"].to_s.downcase
207
-
209
+
208
210
  cattrs.reject{|k,v| v.respond_to?(:empty?) ? v.empty? : v.nil?}
209
211
  end
210
-
212
+
211
213
  def convert_to_school_data(attrs)
212
214
  cattrs = {}
213
-
215
+
214
216
  cattrs[:name] = attrs["Name"]
215
217
  cattrs[:api_id] = cattrs[:number] = attrs["SchoolId"]
216
218
  cattrs[:address] = convert_to_address_data(attrs)
217
-
219
+
218
220
  cattrs.reject{|k,v| v.respond_to?(:empty?) ? v.empty? : v.nil?}
219
221
  end
220
-
222
+
221
223
  def apply_options(params, options)
222
224
  options[:per_page] = params[:rpp] ||= params.delete(:per_page) || options[:per_page] || 100
223
225
  options[:page] = params.delete(:page) || options[:page]
224
226
  params[:schoolyear] ||= params.delete(:school_year) || options[:school_year]
225
227
  params
226
228
  end
227
-
229
+
228
230
  def apply_page_to_url(url, page)
229
231
  "#{url}#{url[-1] == "/" ? "" : "/"}#{page}"
230
232
  end
231
-
233
+
232
234
  def headers_for_auth(uri)
233
235
  t = Time.now.utc.httpdate
234
236
  string_to_sign = "GET\n#{t}\n#{uri}"
235
-
237
+
236
238
  signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), self.connection_options[:secret], string_to_sign)).strip
237
239
  authorization = "TIES" + " " + self.connection_options[:key] + ":" + signature
238
-
240
+
239
241
  {
240
242
  'Authorization' => authorization,
241
243
  'DistrictNumber' => self.connection_options[:district_id],
@@ -245,4 +247,4 @@ module Bright
245
247
  end
246
248
  end
247
249
  end
248
- end
250
+ end
@@ -2,38 +2,38 @@ require 'securerandom'
2
2
 
3
3
  module Bright
4
4
  class Student < Model
5
- @attribute_names = [:client_id, :api_id, :first_name, :middle_name, :last_name, :nick_name,
6
- :birth_date, :grade, :projected_graduation_year, :gender,
7
- :hispanic_ethnicity, :race, :image, :primary_language, :secondary_language,
8
- :homeless_code, :frl_status, :sis_student_id,
5
+ @attribute_names = [:client_id, :api_id, :first_name, :middle_name, :last_name, :nick_name,
6
+ :birth_date, :grade, :grade_school_year, :projected_graduation_year, :gender,
7
+ :hispanic_ethnicity, :race, :image, :primary_language, :secondary_language,
8
+ :homeless_code, :frl_status, :sis_student_id,
9
9
  :state_student_id, :last_modified]
10
10
  attr_accessor *@attribute_names
11
-
11
+
12
12
  def self.attribute_names
13
13
  @attribute_names
14
14
  end
15
-
15
+
16
16
  # TODO:: map contact info (addresses, email, phone, etc)
17
- attr_accessor :enrollment, :addresses
17
+ attr_accessor :enrollment, :addresses, :email_address, :phone_numbers, :school, :contacts
18
18
 
19
19
  def initialize(*args)
20
20
  super
21
21
  self.client_id ||= SecureRandom.uuid
22
22
  self
23
23
  end
24
-
24
+
25
25
  def name
26
26
  "#{self.first_name} #{self.middle_name} #{self.last_name}".gsub(/\s+/, " ").strip
27
27
  end
28
-
28
+
29
29
  def <=>(other)
30
30
  (self.sis_student_id and self.sis_student_id == other.sis_student_id) or
31
31
  (self.state_student_id and self.state_student_id == other.state_student_id) or
32
32
  (self.first_name == other.first_name and self.middle_name == other.middle_name and self.last_name == other.last_name and self.birth_date == other.birth_date)
33
33
  end
34
-
34
+
35
35
  alias id client_id
36
-
36
+
37
37
  def addresses=(array)
38
38
  if array.size <= 0 or array.first.is_a?(Address)
39
39
  @addresses = array
@@ -43,11 +43,54 @@ module Bright
43
43
  end
44
44
  @addresses ||= []
45
45
  end
46
-
46
+
47
47
  def addresses
48
48
  @addresses ||= []
49
49
  end
50
- end
51
- end
52
50
 
51
+ def phone_numbers=(array)
52
+ if array.size <= 0 or array.first.is_a?(PhoneNumber)
53
+ @phone_numbers = array
54
+ elsif array.first.is_a?(Hash)
55
+ @phone_numbers = array.collect{|a| PhoneNumber.new(a)}
56
+ end
57
+ @phone_numbers ||= []
58
+ end
59
+
60
+ def phone_numbers
61
+ @phone_numbers ||= []
62
+ end
63
+
64
+ def email_address=(email)
65
+ if email.is_a?(EmailAddress)
66
+ @email_address = email
67
+ elsif email.is_a?(Hash)
68
+ @email_address = EmailAddress.new(email)
69
+ end
70
+ @email_address
71
+ end
72
+
73
+ def school=(school_val)
74
+ if school_val.is_a?(School)
75
+ @school = school_val
76
+ elsif school_val.is_a?(Hash)
77
+ @school = School.new(school_val)
78
+ end
79
+ @school
80
+ end
81
+
82
+ def contacts=(array)
83
+ if array.size <= 0 or array.first.is_a?(Contact)
84
+ @contacts = array
85
+ elsif array.first.is_a?(Hash)
86
+ @contacts = array.collect{|a| Contact.new(a)}
87
+ end
88
+ @contacts ||= []
89
+ end
53
90
 
91
+ def contacts
92
+ @contacts ||= []
93
+ end
94
+
95
+ end
96
+ end
@@ -1,3 +1,3 @@
1
1
  module Bright
2
- VERSION = "0.1.0"
2
+ VERSION = "1.1"
3
3
  end
data/lib/bright.rb CHANGED
@@ -1,20 +1,34 @@
1
- require "bright/version"
2
- require "bright/errors"
1
+ require_relative "bright/version"
2
+ require_relative "bright/errors"
3
3
 
4
- require "bright/model"
5
- require "bright/student"
6
- require "bright/address"
7
- require "bright/enrollment"
8
- require "bright/school"
4
+ require_relative "bright/helpers/blank_helper.rb"
5
+ require_relative "bright/helpers/boolean_parser_helper.rb"
9
6
 
10
- require "bright/connection"
11
- require "bright/response_collection"
7
+ require_relative "bright/model"
8
+ require_relative "bright/student"
9
+ require_relative "bright/address"
10
+ require_relative "bright/phone_number"
11
+ require_relative "bright/email_address"
12
+ require_relative "bright/enrollment"
13
+ require_relative "bright/school"
14
+ require_relative "bright/contact"
12
15
 
13
- require "bright/sis_apis/base.rb"
14
- require "bright/sis_apis/tsis.rb"
15
- require "bright/sis_apis/power_school.rb"
16
- require "bright/sis_apis/aeries.rb"
17
16
 
18
- module Bright
17
+ require_relative "bright/connection"
18
+ require_relative "bright/response_collection"
19
+ require_relative "bright/cursor_response_collection"
20
+
21
+ require_relative "bright/sis_apis/base.rb"
22
+ require_relative "bright/sis_apis/tsis.rb"
23
+ require_relative "bright/sis_apis/power_school.rb"
24
+ require_relative "bright/sis_apis/aeries.rb"
25
+ require_relative "bright/sis_apis/infinite_campus.rb"
26
+ require_relative "bright/sis_apis/skyward.rb"
27
+ require_relative "bright/sis_apis/bright_sis.rb"
28
+ require_relative "bright/sis_apis/synergy.rb"
19
29
 
30
+ module Bright
31
+ class << self
32
+ attr_accessor :devmode
33
+ end
20
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bright
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arux Software
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpi
@@ -39,40 +39,68 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: parallel
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.7'
48
- type: :development
61
+ version: '1.2'
62
+ type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.7'
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.2.10
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.2.10
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '10.0'
89
+ version: 12.3.3
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '10.0'
96
+ version: 12.3.3
69
97
  description: Bright is a simple Student Information System API abstraction library
70
- used in and sponsored by FeePay. It is written by Stephen Heuer, Steven Novotny,
98
+ used in and sponsored by Arux Software. It is written by Stephen Heuer, Steven Novotny,
71
99
  and contributors. The aim of the project is to abstract as many parts as possible
72
100
  away from the user to offer a consistent interface across all supported Student
73
101
  Information System APIs.
74
102
  email:
75
- - sheuer@aruxsoftware.com
103
+ - hello@arux.software
76
104
  executables: []
77
105
  extensions: []
78
106
  extra_rdoc_files: []
@@ -86,15 +114,23 @@ files:
86
114
  - lib/bright.rb
87
115
  - lib/bright/address.rb
88
116
  - lib/bright/connection.rb
117
+ - lib/bright/contact.rb
118
+ - lib/bright/cursor_response_collection.rb
119
+ - lib/bright/email_address.rb
89
120
  - lib/bright/enrollment.rb
90
121
  - lib/bright/errors.rb
122
+ - lib/bright/helpers/blank_helper.rb
123
+ - lib/bright/helpers/boolean_parser_helper.rb
91
124
  - lib/bright/model.rb
125
+ - lib/bright/phone_number.rb
92
126
  - lib/bright/response_collection.rb
93
127
  - lib/bright/school.rb
94
128
  - lib/bright/sis_apis/aeries.rb
95
129
  - lib/bright/sis_apis/base.rb
130
+ - lib/bright/sis_apis/bright_sis.rb
96
131
  - lib/bright/sis_apis/infinite_campus.rb
97
132
  - lib/bright/sis_apis/power_school.rb
133
+ - lib/bright/sis_apis/skyward.rb
98
134
  - lib/bright/sis_apis/synergy.rb
99
135
  - lib/bright/sis_apis/tsis.rb
100
136
  - lib/bright/student.rb
@@ -103,7 +139,7 @@ homepage: ''
103
139
  licenses:
104
140
  - MIT
105
141
  metadata: {}
106
- post_install_message:
142
+ post_install_message:
107
143
  rdoc_options: []
108
144
  require_paths:
109
145
  - lib
@@ -118,9 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
154
  - !ruby/object:Gem::Version
119
155
  version: '0'
120
156
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.2.2
123
- signing_key:
157
+ rubygems_version: 3.3.7
158
+ signing_key:
124
159
  specification_version: 4
125
160
  summary: Framework and tools for dealing with Student Information Systems
126
161
  test_files: []