Skip to content

Instantly share code, notes, and snippets.

@martinshaw
Created December 28, 2017 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinshaw/6db71d7ddb55b253d764677af5698cf0 to your computer and use it in GitHub Desktop.
Save martinshaw/6db71d7ddb55b253d764677af5698cf0 to your computer and use it in GitHub Desktop.
import Network;
import JSON;
+ GeolocationProvider inherits \Objects\MappableAdopter<Float, Float>{
public f constructor <> {
\Network\Fetch({
Method: 'GET',
URL: \Network\Path <String "http://iplocation.net/api/" +toString<\Network\ClientIPAddress> >,
isSuccessful: <\Network\FetchResponse response> {
yield new \JSON\JsonObject {
status: 'ok',
location_data: response.json().get("location_data")
};
},
isFailure: <\Error error> {
yield new \JSON\JsonObject {
status: 'bad',
error_msg: toString<error>,
error_line: toInt<error.getLinePosition>
};
}
}
}
}
@martinshaw
Copy link
Author

To be finished!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment