On Sun, 10 Mar 2019 at 04:55, Roelof Wobben <r.wobben@home.nl> wrote:
Hello,
I try to make a app which displays images from a external api .
I was hoping I could do it with only 1 json parsing but to get the right size of images I need more then 1
Right now I have two classes with fromJson methods
Painting class >> fromJSON: json | instance | instance := self new. instance title: (json at: #title); painter: (json at: #principalOrFirstMaker); imageUrl: ((json at: #webImage) at: #url). ^ instance
Paintings class > fromJSON: json
fromJSON: json | instance artObjects | instance := self new. artObjects := json at: #artObjects. artObjects do: [ :eachArtObject | instance addPainting: (Painting fromJSON: eachArtObject) ]. ^ instance
but to get it working right , I have to do it like this :
Painting class >> fromJSON: json | instance | instance := self new. instance title: (json at: #objectNumber); ^ instance
but the problem is now I need a second call to this url :
https://www.rijksmuseum.nl/api/nl/collection/<<objectNumber>/tiles?key=[API_KEY]&format=json
and then need a new imageUrl out of it. and then have one object with objectNumber and the new url
Also I have to make a call to this url : https://www.rijksmuseum.nl/api/nl/collection/<<<objectNumber>>?key=[API_KEY]&format=json
and also get some data out of it so that a painting will be one object with the objectNumber, new imageurl and some data out of the last call
Do I need to make some more object to get this working or is there a way I can change the code I use now to get things working
Regards,
Roelof
Its hard to tell from your description. You say "the problem is now I need a second call" but you've not shown the code that does the calling, and you've not shown the first call, or where you are looping through multiple paintings (I'm guessing that is the requirement) You say "Do I need to make some more object", but are you referring to more Paintings objects or more Painting objects? So speaking only very generally, this might be implemented in two ways... A1. Request the json of paintings into a Paintings object A2 Loop that json requesting each individual painting json to fully initialized Painting object or... B1. Request the json of paintings into a Paintings object B2. Loop that json create empty Painting objects B3. Iterate those Painting objects with each one requesting its own json from the server, and can do multiple requests if necessary And btw, very very generally, if you see even a hint of one way to do it - do it that way first and see what insights arise from that to improve it. Particularly when exploring a new domain like an unfamiliar API, the usual approach is... 1. Make it work 2. Make it right 3. Make it fast Use whatever hackery you need to get step 1 done before moving to step 2, which you are inquiring about. And often you don't even need step 3. cheers -ben