class RocketChatVerifier {

    public static void checkServerVersion(OkHttpClient client, String baseUrl,
                                          final VersionVerifier versionVerifier,
                                          final SimpleCallback callback) {
        checkNotNull(client, "client == null");
        checkNotNull(baseUrl, "baseUrl == null");
        checkNotNull(versionVerifier, "versionVerifier == null");
        checkNotNull(callback, "callback == null");

        final Moshi moshi = new Moshi.Builder().add(CommonJsonAdapterFactory.create()).build();

        HttpUrl url = HttpUrl.parse(baseUrl).newBuilder()
                .addPathSegment("api")
                .addPathSegment("info")
                .build();

        Request request = new Request.Builder()
                .url(url)
                .get()
                .build();

        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                callback.onError(new RocketChatNetworkErrorException("network error", e));
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                try {
                    if (!response.isSuccessful()) {
                        JSONObject json = new JSONObject(response.body().string());
                        String message = json.optString("error");
                        String errorType = json.optString("errorType");
                        callback.onError(new RocketChatApiException(response.code(), message,
                                errorType));
                    }

                    JsonAdapter<ServerInfo> adapter = moshi.adapter(ServerInfo.class);
                    ServerInfo info = adapter.fromJson(response.body().string());

                    if (versionVerifier.isValidVersion(info.version())) {
                        callback.onSuccess();
                    } else {
                        callback.onError(new RocketChatException("Unsupported version: "
                                + info.version()));
                    }
                } catch (IOException | JSONException e) {
                    callback.onError(new RocketChatException(e.getMessage(), e));
                }
            }
        });
    }

}