Sha256: 64676e6a8af9c627a732032f05d8e7763cc32c212927bc27358297fffbbe8c09

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

# -----------------------------------------------------------------------
#  Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
# -----------------------------------------------------------------------

require 'json/pure'
require 'App42_Ruby_API/App42ResponseBuilder'
require 'upload/Upload'

module App42
  module Upload

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

      #
      # Converts the response in JSON format to the value object i.e Upload
      #
      # @param json
      #      - response in JSON format
      #
      # @return Upload object filled with json data
      #
      #
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
App42_Ruby_API-0.8.4 lib/upload/UploadResponseBuilder.rb