ps_utilities 1.0.1 → 1.0.2

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: 823ebc095fd0fe70b224f173aef9a951e1d1a9acd4bf14ad037895d0832f1ef6
4
- data.tar.gz: 23e29507f3fc51e63cc9a640377bd2e3c437fd624652f387c9931aa93b09c720
3
+ metadata.gz: 691b905deebc1f4513478a0b2a9a1b85f15f079795056803f50bee45335c4862
4
+ data.tar.gz: c95a79e6f8391ad8bb37eca452cc74ca2d57f24cbdc318d7dcddb4a361f33624
5
5
  SHA512:
6
- metadata.gz: 512c0c6e1b8c9d5da4426c7c5e15ee4a478c24fab18521d08371e4d1c71521a58873267a7b93f7808cacfced820914e658416cc58f1e0ba4ca91cf186709abc0
7
- data.tar.gz: 35875ad1cee3a496c645c76f8bcedd1a689428e51642ab7cbcab8da28cd97301026dbc9f2aa884a1073d841cfcd999163e2e42afc2ce210f2a4fb70512bfff13
6
+ metadata.gz: 7d38a7ae66fc5ed211ab95383ff411177efc06edbc99006ac28af64f34eb6bc8e8c303e1b1e3244675b4467da49960f04a8b6c9ee87f9e7fa58ef3398f1582cd
7
+ data.tar.gz: 5fd41b3b3d7af19a1836852dfe2fc1b88e0740df0fd62eddf7f4015db2fa4bb417aedbf20bb9c51cea19ca78d09e10619dfe47f67c7b05309752d3530d972064
@@ -72,6 +72,8 @@ module PsUtilities
72
72
  else
73
73
  send(command, params)
74
74
  end
75
+ rescue ArgumentError => error
76
+ return {"error_message" => error.message}
75
77
  end
76
78
 
77
79
  private
@@ -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
- students = []
97
- api_array = []
98
- # students = [params[:student]] if not params[:student].nil? && params[:student].is_a?(Hash)
99
- students = params[:students] #if not params[:students].nil? && params[:students].is_a?(Array)
100
- if students.empty?
101
- return {"errorMessage"=>{"message"=>"Bad student data - USE: {students: [{kid_data1}, {kid_data2}]}"}}
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
- return api_array
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] = kid[:oa_id].to_i
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]
@@ -1,5 +1,5 @@
1
1
  module PsUtilities
2
2
  module Version
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
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: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Weisbecker