/// <summary>
        /// Sends a JSON request.
        /// </summary>
        /// <typeparam name="T">Type of response.</typeparam>
        /// <param name="verb">HTTP verb.</param>
        /// <param name="url">Complete endpoint url.</param>
        /// <param name="payload">Object to send.</param>
        /// <returns></returns>
        private IAsyncToken <HttpResponse <T> > SendRequest <T>(
            HttpVerb verb,
            string url,
            object payload)
        {
            Log.Info(this,
                     "{0} {1}",
                     verb.ToString().ToUpperInvariant(),
                     url);

            var token = new AsyncToken <HttpResponse <T> >();

            byte[] bytes = null;
            if (null != payload)
            {
                _serializer.Serialize(payload, out bytes);
            }

            var request = new WWW(
                url,
                bytes,
                HeaderDictionary());

            _bootstrapper.BootstrapCoroutine(Wait(request, token));

            return(token);
        }
        /// <summary>
        /// Sends a JSON request.
        /// </summary>
        /// <typeparam name="T">Type of response.</typeparam>
        /// <param name="verb">HTTP verb.</param>
        /// <param name="url">Complete endpoint url.</param>
        /// <param name="payload">Object to send.</param>
        /// <returns></returns>
        private IAsyncToken <HttpResponse <T> > SendRequest <T>(
            HttpVerb verb,
            string url,
            object payload)
        {
            var data        = Services.ResolveServiceData(url);
            var service     = data.Item1;
            var resolvedUrl = data.Item2;
            var headers     = data.Item3;

            Log(verb.ToString(), resolvedUrl, service, payload);

            var token = new AsyncToken <HttpResponse <T> >();

            byte[] bytes = null;
            if (null != payload)
            {
                _serializer.Serialize(payload, out bytes);
            }

            var request = new WWW(
                resolvedUrl,
                bytes,
                HeaderDictionary(headers));

            _bootstrapper.BootstrapCoroutine(Wait(request, token));

            return(token);
        }
        /// <inheritdoc cref="IHttpService"/>
        public IAsyncToken <HttpResponse <byte[]> > Download(string url)
        {
            var token = new AsyncToken <HttpResponse <byte[]> >();

            var request = UnityWebRequest.Get(url);

            _requestsOut.Add(request);

            ApplyHeaders(Headers, request);

            _bootstrapper.BootstrapCoroutine(Wait(
                                                 request,
                                                 token,
                                                 SerializationType.Raw));

            return(token);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public IAsyncToken <HttpResponse <byte[]> > Download(string url)
        {
            var token = new AsyncToken <HttpResponse <byte[]> >();

            var request = UnityWebRequest.Get(url);

            _requestsOut.Add(request);

            var service = Services.Process(request);

            // Log after Processing
            Log("GET", url, service);

            _bootstrapper.BootstrapCoroutine(Wait(
                                                 request,
                                                 token,
                                                 SerializationType.Raw));

            return(token);
        }