# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42ResponseBuilder.rb' require 'review/Review.rb' module App42 module Review # # # ReviewResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e Review # # class ReviewResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e Review # # @param json # - response in JSON format # # @return Review object filled with json data # def buildResponse(json) reviewsJSONObject = getServiceJSONObject("reviews", json) reviewJSONObject = reviewsJSONObject.fetch("review") review = Review.new review.strResponse=json review.isResponseSuccess = isResponseSuccess(json) buildObjectFromJSONTree(review, reviewJSONObject); return review end # # Converts the response in JSON format to the list of value objects i.e # Review # # @param json # - response in JSON format # # @return List of Review object filled with json data # # def buildArrayResponse(json) reviewList = Array.new reviewsJSONObject = getServiceJSONObject("reviews", json) if reviewsJSONObject.fetch("review").instance_of?(Hash) #Single Object reviewJSONObj = reviewsJSONObject.fetch("review") review = Review.new review.strResponse=json review.isResponseSuccess = isResponseSuccess(json) buildObjectFromJSONTree(review, reviewJSONObj); reviewList.push(review) else #Multiple Object reviewJSONArray = reviewsJSONObject.fetch("review") reviewJSONArray.length.times do |i| reviewJSONObj = reviewJSONArray[i] review = Review.new review.strResponse=json review.isResponseSuccess = isResponseSuccess(json) buildObjectFromJSONTree(review, reviewJSONObj); reviewList.push(review) end end return reviewList end end end end