I
could do something
like this :
getImages
������ | json numbers
json2�� |
������ json :=
NeoJSONReader
������ ������
fromString:
������ ������ ������
(ZnEasy
������ ������ ������ ������
get:
������ ������ ������ ������
������
'
https://www.rijksmuseum.nl/api/nl/collection?key=14OGzuak&format=json&type=schilderij&toppieces=True')
������ ������ ������ ������
contents.
������ numbers :=
self class
fromJSON: json
������ numbers do:
[each |�� json :=��
.........
������������������������������������������������������������������������������������ imageData = self class ???
I'm not sure what
"numbers" refers to.
It seems a quite
non-domain related
identifier.
and collapsing
objects I see the
structure is...
{����
��
��"elapsedMilliseconds":0,
�� ��"count":4782,
��
��"countFacets":{����
�� �� ��
"hasimage":4359,
�� �� ��
"ondisplay":748
�� ��},
��
��"artObjects":[��
+ ] ,
�� ��"facets":[��+ ]
}
where artObjects is
an array with each art
object like this==>
�� �� �� {����
�� �� �� ��
��"links":{����
�� �� �� �� ��},
�� �� �� ��
��"id":"nl-SK-A-3580",
�� �� �� ��
��"objectNumber":"SK-A-3580",
�� �� �� ��
��"title":"De
Singelbrug bij de
Paleisstraat in
Amsterdam",
�� �� �� ��
��"hasImage":true,
�� �� �� ��
��"principalOrFirstMaker":"George
Hendrik Breitner",
�� �� �� ��
��"longTitle":"De
Singelbrug bij de
Paleisstraat in
Amsterdam, George
Hendrik Breitner,
1898",
�� �� �� ��
��"showImage":true,
�� �� �� ��
��"permitDownload":true,
�� �� �� ��
��"webImage":{����
�� �� �� �� �� ��
"guid":"cd15e2fa-b1f6-41f4-9e9e-c2ca87abcca3",
�� �� �� �� �� ��
"offsetPercentageX":0,
�� �� �� �� �� ��
"offsetPercentageY":0,
�� �� �� �� �� ��
"width":2880,
�� �� �� �� �� ��
"height":1897,
�� �� �� �� ��},
�� �� �� ��
��"headerImage":{����
�� �� �� �� �� ��
"guid":"fef39f74-9783-44c9-acae-69eac3a76b01",
�� �� �� �� �� ��
"offsetPercentageX":0,
�� �� �� �� �� ��
"offsetPercentageY":0,
�� �� �� �� �� ��
"width":1920,
�� �� �� �� �� ��
"height":460,
�� �� �� �� ��},
�� �� �� ��
��"productionPlaces":[����
�� �� �� �� �� ��
"Amsterdam"
�� �� �� �� ��]
�� �� �� }
So evaluating the
following in
Playground...��
�� ��
collectionJson :=
NeoJSONReader
fromString: (ZnEasy
get: collectionUrl)
contents.
�� �� paintings :=
Paintings
fromJSON:��collectionJson.
�� �� paintings
inspect.
then cleaning the
DNU errors as i went,��
starting with your
original code (which
was good btw)...
�� �� Paintings class
>>�� fromJSON:
json
�� ������ �� | instance
artObjects |
�� ������ ����instance :=
self new.
�� ������ ����artObjects
:= json at:
#artObjects.
�� ������ ����artObjects
�� �� �� ������ ����do:
�� �� �� �� �� ������ ����[
:eachArtObject |
instance addPainting:
(Painting fromJSON:
eachArtObject) ].
�� ������ ����^ instance
�� �� Painting class
>> fromJSON:
json
�� ������ ����| instance
|
�� ������ ����instance :=
self new.
�� ������ ����instance
�� �� �� ������ ����title:
(json at: #title);
�� �� �� ������
����painter: (json at:
#principalOrFirstMaker);
�� �� �� ������
����imageUrl: ((json at:
#webImage) at: #url).
�� ������ ����^ instance
I added (roughly in
order that each DNU
occurred)...
�� �� Painting
>> title:
aString��
title
:= aString
�� �� Painting
>> painter:
aString��
painter
:= aString
�� �� Painting
>> imageUrl:
aString��
imageUrl
:= aString
�� �� Paintings
>>
addPainting:
aPainting��
paintings
:= paintings ifNil:
[ OrderedCollection
new ].
paintings
add: aPainting.
I get an
inspector on a list
of paintings and can
drill down to a
painting and see
each has the
expected data,
and just to round
things off...
�� �� Painting
>> title
^
title
�� �� Painting
>> printOn:
aStream
super
printOn: aStream.
aStream
<< ' ('
<< self
title << ')'
helps distinguish
each item in the
Inspector.
Now to extend the
Playground code to
download and display
a painting, in
Playground I
evaluated...
�� �� painting
:= paintings
first.
�� ��
imageResponse :=
ZnEasy get:
painting
imageUrl.
�� �� image :=
ImageReadWriter
formFromStream:
imageResponse
entity
readStream.
�� �� image
inspect.
�� �� Paintings
>> first
^
paintings first
�� �� Painting
>> imageUrl
^
imageUrl
and an inspector on
the `image` variable
displays the painting
on the Morph tab.
Now to mold the IDE
to your domain...��
using Spotter to
browser gtInspector*
methods, a promising
find is...
AbstractFileReference>>gitInspectorJpegIn:
from which I
produced...
�� ��
Painting����>>��
gtInspectorJpegIn:
composite
<gtInspectorPresentationOrder:
0>
composite
morph
title:
'Painting';
display:
[ ImageReadWriter
formFromStream: self
imageEntity readStream
]��
Then inspecting the
`paintings` variable
and drilling down to a
painting��
pops up a DNU
#imageEntity, which
can be resolved by...
�� �� Painting
>> imageEntity
^
imageEntity ifNil: [
imageEntity := (ZnEasy
get: self imageUrl)
entity ].
and you get to see
the painting shown in
the Inspector.
Now if I understand
your question... "Do I
need to make some more
object to get this
working..."
I'd say... No. You
only want one object
for each
painting.��Once you
have a painting
object, it should
handle all getting all
further data it needs
for itself.
You don't want
duplicate objects each
having half of the
data.
can
I for example name
the function
fromJson2 or
fromJSONFromLink2��
?
By naming
convention #fromJson:
implies it sits on the
class side.
To get further data
for an existing
object��you want an
instance-side method,
maybe named
#getLink2Json.��
HTH,��
cheers -ben