private HttpRequest BuildRequest(DownloadStationSettings settings, DiskStationApi api, Dictionary <string, object> arguments, HttpMethod method)
        {
            if (!Resources.ContainsKey(api))
            {
                GetApiVersion(settings, api);
            }

            var requestBuilder = new HttpRequestBuilder(settings.UseSsl, settings.Host, settings.Port).Resource($"webapi/{Resources[api]}");

            requestBuilder.Method             = method;
            requestBuilder.LogResponseContent = true;
            requestBuilder.SuppressHttpError  = true;
            requestBuilder.AllowAutoRedirect  = false;

            if (requestBuilder.Method == HttpMethod.POST)
            {
                if (api == DiskStationApi.DownloadStationTask && arguments.ContainsKey("file"))
                {
                    requestBuilder.Headers.ContentType = "multipart/form-data";

                    foreach (var arg in arguments)
                    {
                        if (arg.Key == "file")
                        {
                            Dictionary <string, object> file = (Dictionary <string, object>)arg.Value;
                            requestBuilder.AddFormUpload(arg.Key, file["name"].ToString(), (byte[])file["data"]);
                        }
                        else
                        {
                            requestBuilder.AddFormParameter(arg.Key, arg.Value);
                        }
                    }
                }
                else
                {
                    requestBuilder.Headers.ContentType = "application/json";
                }
            }
            else
            {
                foreach (var arg in arguments)
                {
                    requestBuilder.AddQueryParam(arg.Key, arg.Value);
                }
            }

            return(requestBuilder.Build());
        }