Exemplo n.º 1
0
 /// <summary>
 /// Build the MultiPart http request.
 /// </summary>
 /// <param name="_multiPartContent">A MultiPartContent param. (Instantiate)</param>
 /// <returns>ApiRequestBuilder</returns>
 public ApiRequestBuilder buildMultipartRequest(MultiPartContent _multiPartContent)
 {
     apiRequestBundle = new ApiRequestBundle();
     apiRequestBundle.setIsMultipart(true);
     apiRequestBundle.setMultiPartContent(_multiPartContent);
     return(this);
 }
Exemplo n.º 2
0
 internal HttpRequestMessage getHttpRequestMessage(ApiRequestBundle _apiRequestBundle)
 {
     if (_apiRequestBundle != null && _apiRequestBundle.isMultipart())
     {
         return(createMultipartRequest(_apiRequestBundle));
     }
     return(createHttpRequest(_apiRequestBundle));
 }
Exemplo n.º 3
0
        internal HttpRequestMessage createMultipartRequest(ApiRequestBundle _apiRequestBundle)
        {
            HttpRequestMessage requestMessage = createRequest(_apiRequestBundle);

            if (_apiRequestBundle.getMultiPartContent() != null)
            {
                requestMessage.Content = _apiRequestBundle.getMultiPartContent().getMultiPartFormDataContent();
            }
            return(requestMessage);
        }
Exemplo n.º 4
0
        private HttpRequestMessage createRequest(ApiRequestBundle _apiRequestBundle)
        {
            HttpRequestMessage            requestMessage = new HttpRequestMessage();
            MyDictionary <string, string> headers        = _apiRequestBundle.getHeaders();
            MyDictionary <string, string> parameters     = _apiRequestBundle.getParameters();
            string endpoint = _apiRequestBundle.getEndpoint();

            requestMessage.RequestUri = new Uri(getBaseURL() + endpoint);
            requestMessage.Method     = _apiRequestBundle.getHttpMethod();
            if (_apiRequestBundle.getHeaders().Count != 0)
            {
                foreach (KeyValuePair <string, string> aHeader in headers)
                {
                    requestMessage.Headers.Add(aHeader.Key, aHeader.Value);
                }
            }
            return(requestMessage);
        }
Exemplo n.º 5
0
        //sementara NEED REFACTOR
        internal HttpRequestMessage createHttpRequest(ApiRequestBundle _apiRequestBundle)
        {
            HttpRequestMessage requestMessage = createRequest(_apiRequestBundle);

            if (_apiRequestBundle.getParameters().Count != 0)
            {
                requestMessage.Content = new StringContent(_apiRequestBundle.getParameters().convertToJSON(), Encoding.UTF8,
                                                           "application/json");
            }
            if (!String.IsNullOrEmpty(_apiRequestBundle.getJSON()))
            {
                requestMessage.Content = new StringContent(_apiRequestBundle.getJSON(), Encoding.UTF8, "application/json");
            }
            if (_apiRequestBundle.getStringContent() != null)
            {
                requestMessage.Content = _apiRequestBundle.getStringContent();
            }

            return(requestMessage);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Send http request.
        /// </summary>
        /// <param name="_httpRequestBundle">An ApiRequestBundle param.</param>
        /// <returns>HttpResponseBundle</returns>
        public async Task <HttpResponseBundle> sendRequest(ApiRequestBundle _httpRequestBundle)
        {
            HttpRequestMessage httpRequestMessage = getHttpRequestMessage(_httpRequestBundle);

            if (token != null)
            {
                if (token.isAuthenticated())
                {
                    token.addAuthToken(httpRequestMessage);
                }
            }
            onStartRequest?.Invoke();
            var response = new HttpResponseBundle(await client.getClient().SendAsync(httpRequestMessage).ConfigureAwait(false));

            if (response.getHttpResponseMessage().IsSuccessStatusCode)
            {
                onSuccessRequest?.Invoke(response);
                Console.WriteLine(response.getHttpResponseMessage().Content.ReadAsStringAsync());
                return(response);
            }
            onFailedRequest?.Invoke(response);
            return(new HttpResponseBundle(new HttpResponseMessage(response.getHttpResponseMessage().StatusCode)));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Build the regular JSON http request.
 /// </summary>
 /// <returns>ApiRequestBuilder</returns>
 public ApiRequestBuilder buildHttpRequest()
 {
     apiRequestBundle = new ApiRequestBundle();
     apiRequestBundle.setIsMultipart(false);
     return(this);
 }