# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42ResponseBuilder.rb' require 'user/User.rb' module App42 module User # # # UserResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e User # # class UserResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e User # # @param json # - response in JSON format # # @return User object filled with json data # def buildResponse(json) usersJSONObj = getServiceJSONObject("users", json) userJSOnObj = usersJSONObj["user"] user = buildUserObject(userJSOnObj); user.strResponse=json user.isResponseSuccess = isResponseSuccess(json) return user end # # Converts the User JSON object to the value object i.e User # # @param userJSONObj # - user data as JSONObject # # @return User object filled with json data # # def buildUserObject(userJSONObj) user = User.new buildObjectFromJSONTree(user,userJSONObj) if userJSONObj.key?('profile') profileJSONObj = userJSONObj["profile"] profile = App42::User::Profile.new(user) buildObjectFromJSONTree(profile, profileJSONObj); end if userJSONObj.key?("role") roleList = Array.new if userJSONObj.fetch("role").instance_of?(Array) roleArr = userJSONObj.fetch("role"); roleArr.length.times do |i| roleList.push(roleArr.fetch(i)) end else roleList.push(userJSONObj.fetch("role")); end user.roleList = roleList end return user; end # # Converts the response in JSON format to the list of value objects i.e User # # @param json # - response in JSON format # # @return List of User object filled with json data # def buildArrayResponse(json) usersJSONObj = getServiceJSONObject("users", json); userList = Array.new if usersJSONObj["user"].instance_of?(Array) userJSONArray = usersJSONObj["user"] userJSONArray.length.times do |i| userJSONObject = userJSONArray[i] user = buildUserObject(userJSONObject); user.strResponse=json user.isResponseSuccess = isResponseSuccess(json) userList.push(user) end else userJSONObject = usersJSONObj["user"] user = buildUserObject(userJSONObject); user.strResponse=json user.isResponseSuccess = isResponseSuccess(json) userList.push(user) end return userList end end end end