Search in sources :

Example 1 with UshahidiApiVersion

use of com.ushahidi.android.app.json.UshahidiApiVersion in project Ushahidi_Android by ushahidi.

the class ApiUtils method updateDomain.

/**
	 * Check if an ushahidi deployment has changed it's HTTP protocol to HTTPS
	 * or not. Then update if it has.
	 * 
	 * @param context
	 *            - the calling activity.
	 */
public static void updateDomain(Context context) {
    UshahidiHttpClient client = new UshahidiHttpClient();
    Preferences.loadSettings(context);
    StringBuilder uriBuilder = new StringBuilder(Preferences.domain);
    uriBuilder.append("/api?task=version");
    uriBuilder.append("&resp=json");
    try {
        if (client != null) {
            String jsonString = client.sendGetRequest(uriBuilder.toString());
            UshahidiApiVersion ver = BaseTask.fromString(jsonString, UshahidiApiVersion.class);
            String domain = ver.getDomain();
            new Util().log(String.format("%s %s ", "Update domain", domain));
            Preferences.domain = domain;
            String ogsVer = client.sendGetRequest(Preferences.domain + "/opengeosms/version");
            Preferences.ogsPluginVersion = ogsVer == null ? "" : trimVersion(ogsVer);
            String sms = ver.getSms();
            Preferences.phonenumber = sms != null ? sms : "";
            // save changes
            Preferences.saveSettings(context);
        }
    } catch (UshahidiException e) {
        new Util().log(CLASS_TAG, e);
    } catch (JsonSyntaxException e) {
        e.getMessage();
    }
}
Also used : UshahidiHttpClient(com.ushahidi.java.sdk.net.UshahidiHttpClient) JsonSyntaxException(com.google.gson.JsonSyntaxException) UshahidiApiVersion(com.ushahidi.android.app.json.UshahidiApiVersion) UshahidiException(com.ushahidi.java.sdk.UshahidiException)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 UshahidiApiVersion (com.ushahidi.android.app.json.UshahidiApiVersion)1 UshahidiException (com.ushahidi.java.sdk.UshahidiException)1 UshahidiHttpClient (com.ushahidi.java.sdk.net.UshahidiHttpClient)1