class App42::Storage::StorageResponseBuilder

StorageResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Storage

Public Instance Methods

buildJsonDocument(document,jsonObjDoc) click to toggle source

Builds the Json Document for the storage w.r.t their docId

@param document

- document for storage

@param jsonObjDoc

- jsonDoc object for storage
# File lib/storage/StorageResponseBuilder.rb, line 75
def buildJsonDocument(document,jsonObjDoc)
  if jsonObjDoc.fetch("_id").instance_of?(Hash)
    idObj = jsonObjDoc.fetch("_id");
    oIdObj = idObj.fetch("$oid")
    document.docId = oIdObj
    jsonObjDoc.delete("_id")
    document.jsonDoc = jsonObjDoc.to_s
  end
end
buildResponse(json) click to toggle source

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

@param json

- response in JSON format

@return Storage object filled with json data

# File lib/storage/StorageResponseBuilder.rb, line 29
def buildResponse(json)
  storageObj = Storage.new
  jsonDocList = Array.new
  storageObj.jsonDocList = (jsonDocList)
  storageObj.strResponse = (json)
  jsonObj = JSON.parse(json)
  jsonObjApp42 = jsonObj["app42"]
  jsonObjResponse = jsonObjApp42["response"]
  storageObj.isResponseSuccess=(jsonObjResponse.fetch("success"))
  jsonObjStorage = jsonObjResponse.fetch("storage");
  buildObjectFromJSONTree(storageObj, jsonObjStorage);

  if jsonObjStorage.key?("jsonDoc") == false
    return storageObj;
  end

  if jsonObjStorage.fetch("jsonDoc").instance_of?(Hash)
    # Only One attribute is there

    jsonObjDoc = jsonObjStorage.fetch("jsonDoc");
    document = App42::Storage::JSONDocument.new(storageObj)

    buildJsonDocument(document, jsonObjDoc);
  else
    # There is an Array of attribute

    jsonObjDocArray = jsonObjStorage.fetch("jsonDoc")
    jsonObjDocArray.length.times do |i|
      # Get Individual Attribute Node and set it into Object
      jsonObjDoc = jsonObjDocArray[i]
      document = App42::Storage::JSONDocument.new(storageObj)
      buildJsonDocument(document, jsonObjDoc);
    end
  end
  return storageObj
end