class Projects::Parser::UserParser
-
Parse the JSON response into respective objects.
Public Instance Methods
getUsers(response)
click to toggle source
-
Parse the JSON response and make it into List of User object.
Parameters¶ ↑
- response
-
This JSON response contains the details of users.
-
Returns¶ ↑
-
List of User object.
# File lib/projects/parser/UserParser.rb, line 23 def getUsers(response) users_all_json = JSON.parse response users_all_array = users_all_json["users"] users_class_array = Array.new for i in 0...users_all_array.length users_class_array.push(jsonToUser(users_all_array[i])) end return users_class_array end
jsonToUser(jsonObject)
click to toggle source
-
Parse the JSONObject into User object.
Parameters¶ ↑
- response
-
JSONObject contains the details of a user.
-
Returns¶ ↑
-
User object.
# File lib/projects/parser/UserParser.rb, line 43 def jsonToUser(jsonObject) user = User.new if jsonObject.has_key?("id") user.setId(jsonObject["id"]) end if jsonObject.has_key?("name") user.setName(jsonObject["name"]) end if jsonObject.has_key?("email") user.setEmail(jsonObject["email"]) end if jsonObject.has_key?("role") user.setRole(jsonObject["role"]) end return user end