Merge: app: portable services to do requests over HTTP asynchronously
authorJean Privat <jean@pryen.org>
Mon, 9 Nov 2015 15:39:20 +0000 (10:39 -0500)
committerJean Privat <jean@pryen.org>
Mon, 9 Nov 2015 15:39:20 +0000 (10:39 -0500)
This PR introduces a series of portable services to execute HTTP request asynchronously from graphical programs. These services should be independent and may be reorganized as needed by client programs.

The HTTP request services are very simple by design, it is not an attempt to define a true API to build the request. It is currently limited to GET calls to a simple URI, for example a simple use may look like:

~~~
print "http://xymus.net/rest/list?query=asdf".http_get.value
~~~

## The services

* `Text::http_get` makes an HTTP request and blocks until the response is received. It returns `HttpRequestResult`, a subclass of `MaybeError`, with a possible error, status code and response body content. This service is implemented independently on each platform, using GDK + Curl on GNU/Linux and Apache HTTP client services in Java on Android.

* `App::run_on_ui_thread` sends an instance of `Task` to be executed on the main UI thread when possible. This method may be moved "up" to `app::ui` as needed.

* `AsyncHttpRequest` combines the two previous features to execute an HTTP request asynchronously, deserialize the result from JSON (if needed) and execute custom behaviors on the main UI thread. Users of this service should subclass `AsyncHttpRequest` and implement as needed `before`, `on_load`, `on_error` and `after`. By default, all user code is executed on the main UI thread and as such users do not have to worry about threading logic.

Pull-Request: #1823
Reviewed-by: Jean Privat <jean@pryen.org>


No differences found