public function call($function, array $params = [], $method = 'GET') {

        if (strpos($function, 'flickr.') !== 0) {
            $function = 'flickr.'.$function;
        }

        $params['method'] = $function;
        $params['format'] = 'json';
        $params['nojsoncallback'] = 1;

        $rawresponse = $this->request($method, self::REST_ROOT, $params);
        $response = json_decode($rawresponse);

        if (!is_object($response) || !isset($response->stat)) {
            throw new moodle_exception('flickr_api_call_failed', 'core_error', '', $rawresponse);
        }

        if ($response->stat === 'ok') {
            return $response;

        } else if ($response->stat === 'fail' && $response->code == 98) {
            // Authentication failure, give the caller a chance to re-authenticate.
            return false;

        } else {
            throw new moodle_exception('flickr_api_call_failed', 'core_error', '', $response);
        }

        return $response;
    }