# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42ResponseBuilder.rb' require 'recommend/Recommender.rb' require 'recommend/RecommenderSimilarity.rb' module App42 module Recommend # # # RecommenderResponseBuilder class converts the JSON response retrieved from # the server to the value object i.e Recommender # # class RecommenderResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e Recommender # # @param json # - response in JSON format # # @return Recommender object filled with json data # # def buildResponse(json) puts "testing #{json}" recommenderObj = Recommender.new recommendedItemList = Array.new() recommenderObj.recommendedItemList=recommendedItemList recommenderObj.strResponse=json jsonObj = JSON.parse(json) jsonObjApp42 = jsonObj["app42"] jsonObjResponse = jsonObjApp42["response"] recommenderObj.isResponseSuccess=(jsonObjResponse.fetch("success")); jsonObjRecommender = jsonObjResponse["recommender"] buildObjectFromJSONTree(recommenderObj, jsonObjRecommender); if jsonObjRecommender.key?("recommended") == false return recommenderObj end if jsonObjRecommender.fetch("recommended").instance_of?(Hash) # Only One attribute is there jsonObjRecommended = jsonObjRecommender.fetch("recommended"); recomItem = App42::Recommend::RecommendedItem.new(recommenderObj) buildObjectFromJSONTree(recomItem, jsonObjRecommended); else jsonObjRecommenderArray = jsonObjRecommender.fetch("recommended"); jsonObjRecommenderArray.length.times do |i| # Get Individual Attribute Node and set it into Object jsonObjRecommended = jsonObjRecommenderArray[i] recomItem = App42::Recommend::RecommendedItem.new(recommenderObj) buildObjectFromJSONTree(recomItem, jsonObjRecommended); end end return recommenderObj end end end end