Class: App42::Geo::GeoResponseBuilder
- Inherits:
-
App42ResponseBuilder
- Object
- App42ResponseBuilder
- App42::Geo::GeoResponseBuilder
- Defined in:
- lib/geo/GeoResponseBuilder.rb
Overview
GeoResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Geo
Instance Method Summary collapse
-
#buildArrayResponse(json) ⇒ Object
Converts the response in JSON format to the list of value objects i.e Geo.
-
#buildInternalObj(geoObj, jsonObjGeoStorage) ⇒ Object
Converts the Geo JSON object to the value object i.e Geo.
-
#buildResponse(json) ⇒ Object
Converts the response in JSON format to the value object i.e Geo.
Methods inherited from App42ResponseBuilder
#buildObjectFromJSONTree, #getNames, #getServiceJSONObject, #getTotalRecords, #isResponseSuccess
Instance Method Details
#buildArrayResponse(json) ⇒ Object
Converts the response in JSON format to the list of value objects i.e Geo
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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) ⇒ Object
Converts the Geo JSON object to the value object i.e Geo
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# 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) ⇒ Object
Converts the response in JSON format to the value object i.e Geo
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 |