class App42::Geo::GeoResponseBuilder
GeoResponseBuilder
class converts the JSON response retrieved from the server to the value object i.e Geo
Public Instance Methods
buildArrayResponse(json)
click to toggle source
Converts the response in JSON format to the list of value objects i.e Geo
@param json
- response in JSON format
@return List of Geo
Points object filled with json data
# File lib/geo/GeoResponseBuilder.rb, line 61 def buildArrayResponse(json) geoObjList = Array.new jsonObj = JSON.parse(json) jsonObjApp42 = jsonObj.fetch("app42") jsonObjResponse = jsonObjApp42.fetch("response") jsonObjGeoStorage = jsonObjResponse.fetch("geo") if jsonObjGeoStorage.fetch("storage").instance_of?(Hash) #Single Item jsonObjGeoStorage = jsonObjGeoStorage.fetch("storage"); geoObj = App42::Geo::Geo.new() pointList = Array.new geoObj.pointList=pointList geoObj.strResponse=json geoObj.isResponseSuccess = jsonObjResponse.fetch("success") buildObjectFromJSONTree(geoObj, jsonObjGeoStorage); geoObjList.push(geoObj) if jsonObjGeoStorage.key?("points") buildInternalObj(geoObj,jsonObjGeoStorage); end else jsonStorageArray = jsonObjGeoStorage.fetch("storage"); jsonStorageArray.length.times do |i| jsonObjStorage = jsonStorageArray[i] geoObj = App42::Geo::Geo.new() pointList = Array.new geoObj.pointList=pointList geoObj.strResponse=json geoObj.isResponseSuccess = jsonObjResponse.fetch("success") buildObjectFromJSONTree(geoObj, jsonObjStorage); geoObjList.push(geoObj) if jsonObjStorage.key?("points") buildInternalObj(geoObj,jsonObjStorage); end end end return geoObjList end
buildInternalObj(geoObj, jsonObjGeoStorage)
click to toggle source
Converts the Geo
JSON object to the value object i.e Geo
@param jsonObjGeoStorage
- geo data as JSONObject
@param geoObj
- new geo object
@return Geo
object filled with json data
# File lib/geo/GeoResponseBuilder.rb, line 119 def buildInternalObj(geoObj, jsonObjGeoStorage) jsonGeoPoints = jsonObjGeoStorage.fetch("points"); if jsonGeoPoints.key?("point") == false return geoObj end if jsonGeoPoints.fetch("point").instance_of?(Hash) #Only One attribute is there jsonObjPoint = jsonGeoPoints.fetch("point") pointsItem = App42::Geo::Point.new(geoObj) buildObjectFromJSONTree(pointsItem, jsonObjPoint); else #There is an Array of attribute jsonObjPointsArray = jsonGeoPoints.fetch("point"); jsonObjPointsArray.length.times do |i| jsonObjPoint = jsonObjPointsArray[i] pointsItem = App42::Geo::Point.new(geoObj) buildObjectFromJSONTree(pointsItem, jsonObjPoint); end end return geoObj; end
buildResponse(json)
click to toggle source
Converts the response in JSON format to the value object i.e Geo
@param json
- response in JSON format
@return Geo
object filled with json data
# File lib/geo/GeoResponseBuilder.rb, line 28 def buildResponse(json) puts "testing #{json}" geoObj = Geo.new() pointList = Array.new geoObj.pointList=(pointList) geoObj.strResponse=json jsonObj = JSON.parse(json) jsonObjApp42 = jsonObj.fetch("app42") jsonObjResponse = jsonObjApp42.fetch("response") geoObj.isResponseSuccess = jsonObjResponse.fetch("success") jsonObjGeoStorage = jsonObjResponse.fetch("geo").fetch("storage") buildObjectFromJSONTree(geoObj, jsonObjGeoStorage); if jsonObjGeoStorage.key?("points") == false return geoObj end buildInternalObj(geoObj, jsonObjGeoStorage); return geoObj; end