Created
December 28, 2017 02:29
-
-
Save martinshaw/6db71d7ddb55b253d764677af5698cf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
}; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be finished!