MOBILE-477 Add support for the Connection API

We also fix an issue of checking an undefined variable

More info here https://tracker.moodle.org/browse/MOBILE-477