Hi,
I'm playing around with Zink reading the geo location of any IP-address. Evaluating the code below in a playground works fine. But what is the best way to read the entity data of the ZnResponse instance I get back. Have I to parse it, with an self written parser, or is there anything available. |client znResponse location| client := ZnClient new. client host: 'www.geoplugin.net'. client addPathSegment: 'php.gp'. client queryAt: 'ip' put: '188.194.228.195'. znResponse := client get; response. The code should anyhow look like this. AnyParser parse: (ReadStream on: znResponse contents). In PHP the example code is at http://www.geoplugin.com/webservices/php var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=188.194.228.195]))); I'm searching for the unserialize of the php, which delivers an array with key value pairs. The response entity contents looks somehow like the bottom string without the newlines. 'a:18:{ s:17:"geoplugin_request";s:15:"188.194.228.195"; s:16:"geoplugin_status";i:200; s:16:"geoplugin_credit";s:145:"Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\'http://www.maxmind.com\'>http://www.maxmind.com."; s:14:"geoplugin_city";s:6:"Passau"; s:16:"geoplugin_region";s:7:"Bavaria"; s:18:"geoplugin_areaCode";s:1:"0"; s:17:"geoplugin_dmaCode";s:1:"0"; s:21:"geoplugin_countryCode";s:2:"DE"; s:21:"geoplugin_countryName";s:7:"Germany"; s:23:"geoplugin_continentCode";s:2:"EU"; s:18:"geoplugin_latitude";s:7:"48.5833"; s:19:"geoplugin_longitude";s:7:"13.4833"; s:20:"geoplugin_regionCode";s:2:"02"; s:20:"geoplugin_regionName";s:7:"Bavaria"; s:22:"geoplugin_currencyCode";s:3:"EUR"; s:24:"geoplugin_currencySymbol";s:7:"€"; s:29:"geoplugin_currencySymbol_UTF8";s:3:"€"; s:27:"geoplugin_currencyConverter";s:6:"0.9348";}' Thanks for any help cjb |
Hi,
> On 14 Jun 2017, at 17:23, bachitoph <[hidden email]> wrote: > > Hi, > I'm playing around with Zink reading the geo location of any IP-address. > Evaluating the code below in a playground works fine. But what is the best > way to read the entity data of the ZnResponse instance I get back. Have I to > parse it, with an self written parser, or is there anything available. > > |client znResponse location| > client := ZnClient new. > client host: 'www.geoplugin.net'. > client addPathSegment: 'php.gp'. > client queryAt: 'ip' put: '188.194.228.195'. > znResponse := client get; response. > > The code should anyhow look like this. > AnyParser parse: (ReadStream on: znResponse contents). > > In PHP the example code is at http://www.geoplugin.com/webservices/php > var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=188.194.228.195]))); > I'm searching for the unserialize of the php, which delivers an array with > key value pairs. The result looks to be PHP's own serialisation format as described here: http://php.net/manual/en/function.serialize.php See the first comment which describes the format a bit. I don't know if anyone ever implemented a parser for that. You will most probably have to write it yourself. However, the service you are using can also return its results in JSON, which we can parse out of the box. |client znResponse location| client := ZnClient new. client host: 'www.geoplugin.net'. client addPathSegment: 'json.gp'. client queryAt: 'ip' put: '188.194.228.195'. client contentReader: [ :entity | STONJSON fromString: entity contents ]. znResponse := client get; contents. HTH, Sven PS: it is Zinc not Zink ;-) > The response entity contents looks somehow like the bottom string without > the newlines. > 'a:18:{ > s:17:"geoplugin_request";s:15:"188.194.228.195"; > s:16:"geoplugin_status";i:200; > s:16:"geoplugin_credit";s:145:"Some of the returned data includes GeoLite > data created by MaxMind, available from http://www.maxmind.com > <\'http://www.maxmind.com\'> ."; > s:14:"geoplugin_city";s:6:"Passau"; > s:16:"geoplugin_region";s:7:"Bavaria"; > s:18:"geoplugin_areaCode";s:1:"0"; > s:17:"geoplugin_dmaCode";s:1:"0"; > s:21:"geoplugin_countryCode";s:2:"DE"; > s:21:"geoplugin_countryName";s:7:"Germany"; > s:23:"geoplugin_continentCode";s:2:"EU"; > s:18:"geoplugin_latitude";s:7:"48.5833"; > s:19:"geoplugin_longitude";s:7:"13.4833"; > s:20:"geoplugin_regionCode";s:2:"02"; > s:20:"geoplugin_regionName";s:7:"Bavaria"; > s:22:"geoplugin_currencyCode";s:3:"EUR"; > s:24:"geoplugin_currencySymbol";s:7:"€"; > s:29:"geoplugin_currencySymbol_UTF8";s:3:"€"; > s:27:"geoplugin_currencyConverter";s:6:"0.9348";}' > > Thanks for any help > cjb > > > > > > -- > View this message in context: http://forum.world.st/Zink-geo-location-data-reading-tp4951446.html > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. > |
Free forum by Nabble | Edit this page |