Class: App42::Gallery::AlbumResponseBuilder
- Inherits:
-
App42ResponseBuilder
- Object
- App42ResponseBuilder
- App42::Gallery::AlbumResponseBuilder
- Defined in:
- lib/gallery/AlbumResponseBuilder.rb
Overview
AlbumResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Album
Instance Method Summary collapse
-
#buildAlbumObject(albumsJSONObj) ⇒ Object
Converts the Album JSON object to the value object i.e Album.
-
#buildArrayResponse(json) ⇒ Object
Converts the response in JSON format to the list of value objects i.e Album.
-
#buildResponse(json) ⇒ Object
Converts the response in JSON format to the value object i.e Album.
-
#setTagList(photoObj, photoJsonObj) ⇒ Object
set tags to the list.
Methods inherited from App42ResponseBuilder
#buildObjectFromJSONTree, #getNames, #getServiceJSONObject, #getTotalRecords, #isResponseSuccess
Instance Method Details
#buildAlbumObject(albumsJSONObj) ⇒ Object
Converts the Album JSON object to the value object i.e Album
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 |
# File 'lib/gallery/AlbumResponseBuilder.rb', line 75 def buildAlbumObject(albumsJSONObj) albumObj = App42::Gallery::Album.new buildObjectFromJSONTree(albumObj, albumsJSONObj); photoList = Array.new albumObj.photoList = photoList if albumsJSONObj.key?("photos") && albumsJSONObj.fetch("photos").key?("photo") if albumsJSONObj.fetch("photos").fetch("photo").instance_of?(Hash) photoJsonObj = albumsJSONObj.fetch("photos").fetch("photo"); # Single Entry photoObj = App42::Gallery::Photo.new(albumObj) buildObjectFromJSONTree(photoObj, albumsJSONObj.fetch("photos").fetch("photo")); photoObj = setTagList(photoObj, photoJsonObj); else # Multiple Entry photoJSONArray = albumsJSONObj.fetch("photos").fetch("photo") photoJSONArray.length.times do |j| photoJSONObj = photoJSONArray[j] photoObj = App42::Gallery::Photo.new(albumObj) buildObjectFromJSONTree(photoObj, photoJSONObj); photoObj = setTagList(photoObj, photoJSONObj); end end end return albumObj; end |
#buildArrayResponse(json) ⇒ Object
Converts the response in JSON format to the list of value objects i.e Album
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/gallery/AlbumResponseBuilder.rb', line 116 def buildArrayResponse(json) albumsJSONObj = getServiceJSONObject("albums", json) albumList = Array.new if albumsJSONObj.fetch("album").instance_of?(Array) albumJSONArray = albumsJSONObj.fetch("album"); albumJSONArray.length.times do |i| albumJSONObj = albumJSONArray[i] album = buildAlbumObject(albumJSONObj); album.strResponse=json album.isResponseSuccess= (isResponseSuccess(json)) albumList.push(album) end else albumJSONObject = albumsJSONObj.fetch("album"); album = buildAlbumObject(albumJSONObject); album.strResponse=json album.isResponseSuccess= (isResponseSuccess(json)) albumList.push(album) end return albumList end |
#buildResponse(json) ⇒ Object
Converts the response in JSON format to the value object i.e Album
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gallery/AlbumResponseBuilder.rb', line 27 def buildResponse(json) albumsJSONObj = getServiceJSONObject("albums", json) albumJSONObj = albumsJSONObj.fetch("album") albumObj = App42::Gallery::Album.new() photoList = Array.new albumObj.photoList = photoList albumObj.strResponse=json albumObj.isResponseSuccess= isResponseSuccess(json) buildObjectFromJSONTree(albumObj, albumJSONObj); if albumJSONObj.key?("photos") == false return albumObj end if albumJSONObj.fetch("photos").key?("photo") == false return albumObj end if albumJSONObj.fetch("photos").fetch("photo").instance_of?(Hash) #Single Entry photoObj = App42::Gallery::Photo.new(albumObj) buildObjectFromJSONTree(photoObj, albumJSONObj.fetch("photos").fetch("photo")); photoObj = setTagList(photoObj, albumJSONObj.fetch("photos").fetch("photo")); else # Multiple Entry photoJSONArray = albumJSONObj.fetch("photos").fetch("photo"); photoJSONArray.length.times do |i| photoJSONObj = photoJSONArray[i] photoObj = App42::Gallery::Photo.new(albumObj) buildObjectFromJSONTree(photoObj, photoJSONObj); photoObj = setTagList(photoObj, photoJSONObj); end end return albumObj end |
#setTagList(photoObj, photoJsonObj) ⇒ Object
set tags to the list
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gallery/AlbumResponseBuilder.rb', line 150 def setTagList(photoObj, photoJsonObj) if photoJsonObj.key?("tags") tagList = Array.new if photoJsonObj.fetch("tags").instance_of?(Array) tagArr = photoJsonObj.fetch("tags"); tagArr.length.times do |i| tagList.push(tagArr.fetch(i)); end else tagList.push(photoJsonObj.fetch("tags")); end photoObj.tagList = (tagList); end return photoObj; end |