ps_utilities 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daddd46f3c769ec3b61c29558b7cc82d70ea60372eadf8b5b01bba22f1a37068
4
- data.tar.gz: 31cdcb88c3c8e66a5fd1c5005cf00e62eb1a1d8cb8000db52ef63c1ef0437e51
3
+ metadata.gz: c62242e43417fc95e14b36ba194604f4dfa79aac9e45887793ab982abedeb814
4
+ data.tar.gz: e0cf20edad5ba754ff741a99629e4554b38a831973dbb66ca51f61cdf74afc08
5
5
  SHA512:
6
- metadata.gz: 1aea5bd941ef10d5373fb9409aa04fece491cf148c1acce8d9a5000309e4c079818e41b954a7f91bfb11ac582c0fb1ac5f97bb16b9d631f149c4a83ec7d12839
7
- data.tar.gz: 577b9af25d14b005a8e57126c00ace8e98021062dc4ef03e752067dea68ea206523d91564cc299c74643b5bf79408399c2b8e799daf7f6411089b3dcb86fa563
6
+ metadata.gz: 8603dbf338731a62a39f386b6458579e4f49a3eca1eb41b2320beedafa352792f2a539cae7abc9f043934c17ccaec84085b7d1a692ba8d66b90a0116a07f70c4
7
+ data.tar.gz: 2a300ec71565e9e48e081740b402b87f450ca83e1effcfaf3705a0090d46938923353204a217c53538521758ba0d35c32ae5e0d8748459158385d84a4ff6b2f7
@@ -66,14 +66,13 @@ module PsUtilities
66
66
  end
67
67
 
68
68
  # verb = :delete, :get, :patch, :post, :put
69
- # options = {query: {}, body: {}}
70
- # get usually needs a query info
71
- # put usually needs a body with data
69
+ # options = {query: {}, body: {}} - get uses :query, put and post use :body
72
70
  def api(verb, api_path, options={})
73
71
  count = 0
74
72
  retries = 3
75
73
  ps_url = base_uri + api_path
76
74
  options = options.merge(headers)
75
+ pp ps_url
77
76
  pp options
78
77
  begin
79
78
  HTTParty.send(verb, ps_url, options)
@@ -87,6 +86,14 @@ module PsUtilities
87
86
  end
88
87
  end
89
88
 
89
+ def header_defaults
90
+ { headers:
91
+ { 'User-Agent' => "PsUtilities - #{version}",
92
+ 'Accept' => 'application/json',
93
+ 'Content-Type' => 'application/json'}
94
+ }
95
+ end
96
+
90
97
  # In PowerSchool go to System>System Settings>Plugin Management Configuration>your plugin>Data Provider Configuration to manually check plugin expiration date
91
98
  def authenticate
92
99
  ps_url = base_uri + auth_path
@@ -133,13 +140,5 @@ module PsUtilities
133
140
  }
134
141
  end
135
142
 
136
- def header_defaults
137
- { headers:
138
- { 'User-Agent' => "PsUtilitiesGem - v#{PsUtilities::Version::VERSION}",
139
- 'Accept' => 'application/json',
140
- 'Content-Type' => 'application/json'}
141
- }
142
- end
143
-
144
143
  end
145
144
  end
@@ -33,22 +33,41 @@ module PsUtilities
33
33
  # ]
34
34
  # }
35
35
 
36
+ # params = {dcid: "xxxxxxx"} or {id: "12345"}
37
+ def get_student(params)
38
+ # api_path = "/ws/v1/district/student/{dcid}?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
39
+ ps_dcid = params[:dcid] || params[:dc_id] || params[:id]
40
+ api_path = "/ws/v1/student/#{ps_dcid.to_i}"
41
+ options = { query:
42
+ { "extensions" => "s_stu_crdc_x,activities,c_studentlocator,u_students_extension,u_studentsuserfields,s_stu_ncea_x,s_stu_edfi_x,studentcorefields",
43
+ "expansions" => "demographics,addresses,alerts,phones,school_enrollment,ethnicity_race,contact,contact_info,initial_enrollment,schedule_setup,fees,lunch"
44
+ }
45
+ }
46
+ return {"errorMessage"=>{"message"=>"A valid dcid must be entered."}} if "#{ps_dcid.to_i}".eql? "0"
47
+
48
+ answer = api(:get, api_path, options)
49
+ { student: (answer["student"] || []) }
50
+ end
51
+
36
52
  # params = {username: "xxxxxxx"} or {local_id: "12345"}
37
- def get_one_student(params)
53
+ def find_student(params)
38
54
  # api_path = "/ws/v1/district/student?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
39
55
  api_path = "/ws/v1/district/student"
40
- options = {query:
41
- {"expansions" => "school_enrollment,contact,contact_info"}}
56
+ options = { query:
57
+ {"expansions" => "contact,contact_info,phones"}}
42
58
  query = []
43
59
  query << "student_username==#{params[:username]}" if params.has_key?(:username)
44
60
  query << "local_id==#{params[:local_id]}" if params.has_key?(:local_id)
45
61
 
46
62
  options[:query]["q"] = query.join(";")
63
+ pp options
47
64
  return {"errorMessage"=>{"message"=>"A valid parameter must be entered."}} if query.empty?
48
65
 
49
66
  answer = api(:get, api_path, options)
50
67
  { student: (answer.dig("students","student") || []) }
51
68
  end
69
+ alias_method :find_student_by_local_id, :find_student
70
+ alias_method :find_student_by_username, :find_student
52
71
  # {student:
53
72
  # {"id"=>5023,
54
73
  # "local_id"=>112193,
@@ -2,6 +2,267 @@ module PsUtilities
2
2
 
3
3
  module PreBuiltPost
4
4
 
5
+ # params[:students] (Array of Hashes) - kids with their attributes
6
+ # params = {dcid: 7531, student_id: 23456}
7
+ # or
8
+ # params = { [ {dcid: 7531, student_id: 23456},
9
+ # {dcid: 9753, student_id: 65432} ] }
10
+ def create_students(params)
11
+ action = "INSERT"
12
+ kids_api_array = build_kids_api_array(action, params)
13
+ options = { body: { students: { student: kids_api_array } }.to_json }
14
+ answer = api(:post, "/ws/v1/student", options)
15
+ end
16
+ alias_method :create_student, :create_students
17
+ # { "results": {
18
+ # "update_count": 2
19
+ # "result": [
20
+ # { "client_uid": 124,
21
+ # "status": "SUCCESS",
22
+ # "action": "INSERT",
23
+ # "success_message" :{
24
+ # "id": 442,
25
+ # "ref": "https://server/ws/v1/student/442" }
26
+ # },
27
+ # { ... }
28
+ # ]
29
+ # }
30
+ # }
31
+
32
+ # params[:students] (Array of Hashes) - kids with their attributes
33
+ def update_students(params)
34
+ action = "UPDATE"
35
+ kids_api_array = build_kids_api_array(action, params)
36
+ options = { body: { students: { student: kids_api_array } }.to_json }
37
+ answer = api(:post, "/ws/v1/student", options)
38
+ end
39
+ alias_method :update_student, :update_students
40
+ # { "results": {
41
+ # "update_count": 2
42
+ # "result": [
43
+ # { "client_uid": 124,
44
+ # "status": "SUCCESS",
45
+ # "action": "INSERT",
46
+ # "success_message" :{
47
+ # "id": 442,
48
+ # "ref": "https://server/ws/v1/student/442" }
49
+ # },
50
+ # { ... }
51
+ # ]
52
+ # }
53
+ # }
54
+
55
+ def build_kids_api_array(action, params)
56
+ unless params[:students].is_a? Array
57
+ return {"errorMessage"=>{"message"=>"Student Data (in Hash format) must be in an Array."}}
58
+ end
59
+ kids_api_array = []
60
+ params[:students].each do |kid|
61
+ kid[:las_extensions] = true if params[:las_extensions]
62
+ kids_api_array << build_kid_attributes(action, kid)
63
+ end
64
+ return kids_api_array
65
+ end
66
+
67
+ def build_kid_attributes(action, kid)
68
+ # ALWAYS NEEDED INFO
69
+ attribs = {action: action}
70
+ attribs[:id] = kid[:id] || kid[:dcid]
71
+ attribs[:client_uid] = kid[:student_id].to_s
72
+ attribs[:student_username] = kid[:username]
73
+
74
+ # REQUIRED ON ENROLLMENT (optional later)
75
+ attribs[:name] = {}
76
+ case action
77
+ when 'INSERT'
78
+ # must be set on creation
79
+ attribs[:local_id] = kid[:oa_id].to_i
80
+ # to create an account both first and last name must be present
81
+ attribs[:name][:last_name] = kid[:last_name] if kid[:last_name] or kid[:first_name]
82
+ attribs[:name][:first_name] = kid[:first_name] if kid[:last_name] or kid[:first_name]
83
+ attribs[:name][:middle_name] = kid[:middle_name] if kid[:middle_name]
84
+ # school_enrollment can only be SET on INSERT!
85
+ attribs[:school_enrollment] = {}
86
+ if kid[:enroll_status_code]
87
+ attribs[:school_enrollment][:enroll_status_code] = kid[:enroll_status_code]
88
+ elsif kid[:status_code]
89
+ attribs[:school_enrollment][:status_code] = kid[:status_code]
90
+ end
91
+ attribs[:school_enrollment][:grade_level] = kid[:grade_level] if kid[:grade_level]
92
+ attribs[:school_enrollment][:entry_date] = kid[:entry_date] if kid[:entry_date]
93
+ attribs[:school_enrollment][:exit_date] = kid[:exit_date] if kid[:exit_date]
94
+ attribs[:school_enrollment][:school_number] = kid[:school_number] if kid[:school_number]
95
+ attribs[:school_enrollment][:school_id] = kid[:school_id] if kid[:school_id]
96
+ when 'UPDATE'
97
+ # don't allow nil / blank name updates
98
+ attribs[:name][:last_name] = kid[:last_name] if kid[:last_name]
99
+ attribs[:name][:first_name] = kid[:first_name] if kid[:first_name]
100
+ attribs[:name][:middle_name] = kid[:middle_name] if kid[:middle_name]
101
+ end
102
+
103
+ # OPTIONAL
104
+ attribs[:contact] = {}
105
+ if kid[:emergency_phone1] && kid[:emergency_contact_name1]
106
+ attribs[:contact][:emergency_phone1] = kid[:emergency_phone1]
107
+ attribs[:contact][:emergency_contact_name1] = kid[:emergency_contact_name1]
108
+ end
109
+ if kid[:emergency_phone2] && kid[:emergency_contact_name2]
110
+ attribs[:contact][:emergency_phone2] = kid[:emergency_phone2]
111
+ attribs[:contact][:emergency_contact_name2] = kid[:emergency_contact_name2]
112
+ end
113
+ if kid[:doctor_phone] && kid[:doctor_name]
114
+ attribs[:contact][:doctor_phone] = kid[:doctor_phone]
115
+ attribs[:contact][:doctor_name] = kid[:doctor_name]
116
+ end
117
+ attribs[:contact][:guardian_email] = kid[:guardian_email] if kid[:guardian_email]
118
+ attribs[:contact][:guardian_fax] = kid[:guardian_fax] if kid[:guardian_fax]
119
+ attribs[:contact][:mother] = kid[:mother] if kid[:mother]
120
+ attribs[:contact][:father] = kid[:father] if kid[:father]
121
+ attribs[:contact] = nil if attribs[:contact].empty?
122
+ #
123
+ attribs[:demographics] = {}
124
+ attribs[:demographics][:gender] = kid[:gender] if kid[:gender]
125
+ attribs[:demographics][:birth_date] = kid[:birth_date] if kid[:birth_date]
126
+ attribs[:demographics][:projected_graduation_year] = kid[:projected_graduation_year] if kid[:projected_graduation_year]
127
+ attribs[:demographics][:ssn] = kid[:ssn] if kid[:ssn]
128
+ #
129
+ attribs[:schedule_setup] = {}
130
+ attribs[:schedule_setup][:home_room] = kid[:home_room] if kid[:home_room]
131
+ attribs[:schedule_setup][:next_school] = kid[:next_school] if kid[:next_school]
132
+ attribs[:schedule_setup][:sched_next_year_grade] = kid[:sched_next_year_grade] if kid[:sched_next_year_grade]
133
+ #
134
+ attribs[:school_enrollment] = {}
135
+ if kid[:enroll_status_code]
136
+ attribs[:school_enrollment][:enroll_status_code] = kid[:enroll_status_code]
137
+ elsif kid[:status_code]
138
+ attribs[:school_enrollment][:status_code] = kid[:status_code]
139
+ end
140
+ attribs[:school_enrollment][:grade_level] = kid[:grade_level] if kid[:grade_level]
141
+ attribs[:school_enrollment][:entry_date] = kid[:entry_date] if kid[:entry_date]
142
+ attribs[:school_enrollment][:exit_date] = kid[:exit_date] if kid[:exit_date]
143
+ attribs[:school_enrollment][:school_number] = kid[:school_number] if kid[:school_number]
144
+ #
145
+ attribs[:contact_info] = {email: kid[:email]} if kid[:email]
146
+ attribs[:phone] = {main: {number: kid[:mobile]}} if kid[:mobile]
147
+
148
+ # Update LAS Database Extensions as needed
149
+ attribs["_extension_data"] = calc_las_extensions(kid) if kid[:las_extensions].to_s.eql?("true")
150
+
151
+ # return attributes - first remove, nils, empty strings and empty hashes
152
+ answer = attribs.reject { |k,v| v.nil? || v.to_s.empty? || v.to_s.eql?("{}")}
153
+ pp answer
154
+ return answer
155
+ end
156
+ # Data structure to send to API
157
+ # options = {body: {
158
+ # "students":{
159
+ # "student":[
160
+ # {
161
+ # "client_uid":"124",
162
+ # "action":"UPDATE",
163
+ # "id":"442",
164
+ # "name":{
165
+ # "first_name":"Aaronia",
166
+ # "last_name":"Stephaniia"
167
+ # },
168
+ # },
169
+ # { ... }
170
+ # ]
171
+ # }
172
+ # }
173
+ # }
174
+
175
+ def calc_las_extensions(kid)
176
+ # attribs = {}
177
+ # attribs["_table_extension"] = []
178
+ attribs = { "_table_extension" => [] }
179
+ if kid[:email] or kid[:preferred_name]
180
+ db_extensions =
181
+ { "recordFound"=>false,
182
+ "name"=>"u_students_extension",
183
+ "_field"=> [ ]
184
+ }
185
+ if kid[:email]
186
+ db_extensions["_field"] << {"name"=>"student_email", "type"=>"String", "value"=>"#{kid[:email]}"}
187
+ end
188
+ if kid[:preferredname]
189
+ db_extensions["_field"] << {"name"=>"preferredname", "type"=>"String", "value"=>"#{kid[:preferredname]}"}
190
+ end
191
+ if kid[:preferred_name]
192
+ db_extensions["_field"] << {"name"=>"preferredname", "type"=>"String", "value"=>"#{kid[:preferred_name]}"}
193
+ end
194
+ attribs["_table_extension"] << db_extensions
195
+ # { "recordFound"=>false,
196
+ # "name"=>"u_students_extension",
197
+ # "_field"=> [
198
+ # {"name"=>"preferredname", "type"=>"String", "value"=>"Niko"},
199
+ # {"name"=>"student_email", "type"=>"String", "value"=>"#{kid[:email]}"}
200
+ # ]
201
+ # }
202
+ end
203
+ if kid[:transcriptaddrline1] or kid[:transcriptaddrline2] or
204
+ kid[:transcriptaddrcity] or kid[:transcriptaddrstate] or
205
+ kid[:transcriptaddrzip] or kid[:transcriptaddrcountry]
206
+ db_extensions =
207
+ { "recordFound"=>false,
208
+ "name"=>"u_studentsuserfields",
209
+ "_field"=> [ ]
210
+ }
211
+ if kid[:transcriptaddrline1]
212
+ db_extensions["_field"] << {"name"=>"transcriptaddrline1", "type"=>"String", "value"=>"#{kid[:transcriptaddrline1]}"}
213
+ end
214
+ if kid[:transcriptaddrline2]
215
+ db_extensions["_field"] << {"name"=>"transcriptaddrline2", "type"=>"String", "value"=>"#{kid[:transcriptaddrline2]}"}
216
+ end
217
+ if kid[:transcriptaddrcity]
218
+ db_extensions["_field"] << {"name"=>"transcriptaddrcity", "type"=>"String", "value"=>"#{kid[:transcriptaddrcity]}"}
219
+ end
220
+ if kid[:transcriptaddrzip]
221
+ db_extensions["_field"] << {"name"=>"transcriptaddrzip", "type"=>"String", "value"=>"#{kid[:transcriptaddrzip]}"}
222
+ end
223
+ if kid[:transcriptaddrstate]
224
+ db_extensions["_field"] << {"name"=>"transcriptaddrstate", "type"=>"String", "value"=>"#{kid[:transcriptaddrstate]}"}
225
+ end
226
+ if kid[:transcriptaddrcountry]
227
+ db_extensions["_field"] << {"name"=>"transcriptaddrcountry", "type"=>"String", "value"=>"#{kid[:transcriptaddrcountry]}"}
228
+ end
229
+ attribs["_table_extension"] << db_extensions
230
+ # { "recordFound"=>false,
231
+ # "name"=>"u_studentsuserfields",
232
+ # "_field"=> [
233
+ # {"name"=>"transcriptaddrzip", "type"=>"String", "value"=>75230},
234
+ # {"name"=>"transcriptaddrcountry", "type"=>"String", "value"=>"United States"},
235
+ # {"name"=>"transcriptaddrcity", "type"=>"String", "value"=>"dallas"},
236
+ # {"name"=>"transcriptaddrstate", "type"=>"String", "value"=>"Texas"},
237
+ # {"name"=>"transcriptaddrline1", "type"=>"String", "value"=>"6138 meadow rd"}
238
+ # ]
239
+ # }
240
+ end
241
+ pp attribs
242
+ attribs
243
+ end
244
+ # to inject into _extension_data
245
+ # { "_table_extension"=> [
246
+ # { "recordFound"=>false,
247
+ # "name"=>"u_students_extension",
248
+ # "_field"=> [
249
+ # {"name"=>"preferredname", "type"=>"String", "value"=>"Jimmy"},
250
+ # {"name"=>"student_email", "type"=>"String", "value"=>"bbaaccdd@las.ch"}
251
+ # ]
252
+ # },
253
+ # { "recordFound"=>false,
254
+ # "name"=>"u_studentsuserfields",
255
+ # "_field"=> [
256
+ # {"name"=>"transcriptaddrzip", "type"=>"String", "value"=>8154},
257
+ # {"name"=>"transcriptaddrcountry", "type"=>"String", "value"=>"Switzerland"},
258
+ # {"name"=>"transcriptaddrcity", "type"=>"String", "value"=>"Leysin"},
259
+ # {"name"=>"transcriptaddrstate", "type"=>"String", "value"=>"Vaud"},
260
+ # {"name"=>"transcriptaddrline1", "type"=>"String", "value"=>"6789 linden st"}
261
+ # ]
262
+ # }
263
+ # ]
264
+ # }
265
+
5
266
  end
6
267
 
7
268
  end
@@ -1,5 +1,5 @@
1
1
  module PsUtilities
2
2
  module Version
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ps_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Weisbecker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-06-22 00:00:00.000000000 Z
12
+ date: 2018-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty