15. Challenge 3 - Solution

Two little challenges:

15.0.1. Hints:

  • Have a look at ZnEasy or ZnClient.
  • To get the contents of an HTML request, send it the message contents.
  • To parse and convert a string representing JSON into Pharo collection, use the STON class (check the class side).
  • To pass a binding to a request, use the message queryAt:put:.
  • Using the inspector is a good idea to explore objects and query results.

The Poster of Terminator in a Pharo Inspector.

15.0.2. Solutions Getting the Capitals
((STON fromString: (
        get: 'http://api.geonames.org/countryInfoJSON'
        username: 'demo'
        password: '') contents) at: #geonames) collect: [ : d | d at: #capital ] Get poster of The Terminator movie
(ZnEasy getJpeg: ((STON fromString:
    (ZnClient new
        url: 'http://www.omdbapi.com/';
        queryAt: 't' put: 'The Terminator';
        contents)) at: #Poster)) inspect