Class: App42::Upload::UploadResponseBuilder

Inherits:
App42ResponseBuilder show all
Defined in:
lib/upload/UploadResponseBuilder.rb

Overview

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

Instance Method Summary collapse

Methods inherited from App42ResponseBuilder

#buildObjectFromJSONTree, #getNames, #getServiceJSONObject, #getTotalRecords, #isResponseSuccess

Instance Method Details

#buildResponse(json) ⇒ Object

Converts the response in JSON format to the value object i.e Upload

Parameters:

  • json
    • response in JSON format

Returns:

  • Upload object filled with json data



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/upload/UploadResponseBuilder.rb', line 29

def buildResponse(json)
  puts "testing #{json}"
  uploadObj = Upload.new()

  fileList = Array.new
  uploadObj.fileList=fileList

  uploadObj.strResponse=json
  uploadObj.isResponseSuccess = isResponseSuccess(json)
  jsonObjUpload = getServiceJSONObject("upload", json)
  jsonObjFiles = jsonObjUpload.fetch("files");

  if jsonObjFiles.fetch("file").instance_of?(Hash)
    jsonObjFile = jsonObjFiles.fetch("file")
    fileObj = App42::Upload::File.new(uploadObj)
    buildObjectFromJSONTree(fileObj, jsonObjFile);
  else
    jsonObjFileArray = jsonObjFiles["file"]

    jsonObjFileArray.length.times do |i|
      fileObj =  App42::Upload::File.new(uploadObj)
      jsonObjFile = jsonObjFileArray[i]
      buildObjectFromJSONTree(fileObj, jsonObjFile);
    end
  end
  return uploadObj
end