ps_utilities 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ps_utilities/connection.rb +2 -0
- data/lib/ps_utilities/pre_built_post.rb +20 -9
- data/lib/ps_utilities/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 691b905deebc1f4513478a0b2a9a1b85f15f079795056803f50bee45335c4862
|
4
|
+
data.tar.gz: c95a79e6f8391ad8bb37eca452cc74ca2d57f24cbdc318d7dcddb4a361f33624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d38a7ae66fc5ed211ab95383ff411177efc06edbc99006ac28af64f34eb6bc8e8c303e1b1e3244675b4467da49960f04a8b6c9ee87f9e7fa58ef3398f1582cd
|
7
|
+
data.tar.gz: 5fd41b3b3d7af19a1836852dfe2fc1b88e0740df0fd62eddf7f4015db2fa4bb417aedbf20bb9c51cea19ca78d09e10619dfe47f67c7b05309752d3530d972064
|
@@ -51,6 +51,8 @@ module PsUtilities
|
|
51
51
|
def update_students(params)
|
52
52
|
action = "UPDATE"
|
53
53
|
kids_api_array = build_kids_api_array(action, params)
|
54
|
+
return kids_api_array if kids_api_array.empty?
|
55
|
+
|
54
56
|
options = { body: { students: { student: kids_api_array } }.to_json }
|
55
57
|
answer = api(:post, "/ws/v1/student", options)
|
56
58
|
return answer.parsed_response if answer.code.to_s.eql? "200"
|
@@ -93,18 +95,20 @@ module PsUtilities
|
|
93
95
|
#]
|
94
96
|
# @note this is then sent to the API call with a body tag
|
95
97
|
def build_kids_api_array(action, params)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
# ugly protection against bad data feeds - but it works
|
99
|
+
# TODO: refactor with an elegant assertion?
|
100
|
+
if params.nil? or not params.is_a?(Hash) or params[:students].nil? or not params[:students].is_a?(Array) or params[:students].empty? or not params[:students][0].is_a?(Hash)
|
101
|
+
raise ArgumentError, "PARAMS format is: {students: [{kid_data1}, {kid_data2}]} - NOT OK: #{params}"
|
102
|
+
end
|
103
|
+
if action.nil? or not action.is_a?(String) or action.empty? or not %[INSERT UPDATE].include?(action)
|
104
|
+
raise ArgumentError, "ACTION must be: 'INSERT' or 'UPDATE' - NOT OK: #{action}"
|
102
105
|
end
|
106
|
+
api_array = []
|
107
|
+
students = params.dig(:students)
|
103
108
|
students.each do |kid|
|
104
|
-
# kid[:las_extensions] = true if params[:las_extensions]
|
105
109
|
api_array << build_kid_attributes(action, kid)
|
106
110
|
end
|
107
|
-
|
111
|
+
api_array
|
108
112
|
end
|
109
113
|
|
110
114
|
# prepare data to update student database extensions
|
@@ -180,6 +184,12 @@ module PsUtilities
|
|
180
184
|
# ]
|
181
185
|
# }
|
182
186
|
def build_kid_attributes(action, kid)
|
187
|
+
if kid.nil? or not kid.is_a?(Hash) or kid.empty?
|
188
|
+
raise ArgumentError, "STUDENT format is: {students: [{kid_data1}, {kid_data2}]} - NOT OK: #{kid}"
|
189
|
+
end
|
190
|
+
if action.nil? or not action.is_a?(String) or action.empty? or not %[INSERT UPDATE].include?(action)
|
191
|
+
raise ArgumentError, "ACTION must be: 'INSERT' or 'UPDATE' - NOT OK: #{action}"
|
192
|
+
end
|
183
193
|
# ALWAYS NEEDED INFO
|
184
194
|
attribs = {action: action}
|
185
195
|
attribs[:client_uid] = kid[:student_id].to_s
|
@@ -190,7 +200,8 @@ module PsUtilities
|
|
190
200
|
case action
|
191
201
|
when 'INSERT'
|
192
202
|
# must be set on creation (INSERT)
|
193
|
-
attribs[:local_id]
|
203
|
+
attribs[:local_id] = kid[:local_id].to_i if kid[:local_id]
|
204
|
+
attribs[:local_id] = kid[:student_id].to_i if kid[:student_id]
|
194
205
|
# to create an account both first and last name must be present
|
195
206
|
attribs[:name][:last_name] = kid[:last_name] if kid[:last_name] or kid[:first_name]
|
196
207
|
attribs[:name][:first_name] = kid[:first_name] if kid[:last_name] or kid[:first_name]
|
data/lib/ps_utilities/version.rb
CHANGED