class App42::User::UserResponseBuilder

UserResponseBuilder class converts the JSON response retrieved from the server to the value object i.e User

Public Instance Methods

buildArrayResponse(json) click to toggle source

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

# File lib/user/UserResponseBuilder.rb, line 80
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
buildResponse(json) click to toggle source

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

# File lib/user/UserResponseBuilder.rb, line 27
def buildResponse(json)
  usersJSONObj = getServiceJSONObject("users", json)
  userJSOnObj = usersJSONObj["user"]
  user = buildUserObject(userJSOnObj);
  user.strResponse=json
  user.isResponseSuccess = isResponseSuccess(json)
  return user
end
buildUserObject(userJSONObj) click to toggle source

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

# File lib/user/UserResponseBuilder.rb, line 46
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