Ejemplo n.º 1
0
        public async Task<HttpResponseMessage> ListenAsync(string path, QueryBuilder queryBuilder)
        {
            HttpRequestMessage request;
            var client = PrepareEventStreamRequest(path, queryBuilder, out request);

            var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
            response.EnsureSuccessStatusCode();

            return response;
        }
Ejemplo n.º 2
0
        public Task<HttpResponseMessage> RequestApiAsync(HttpMethod method, string path, QueryBuilder queryBuilder, object payload = null)
        {
            try
            {
                var uri = PrepareApiUri(path, queryBuilder);
                var request = PrepareRequest(method, uri, payload);

                return GetClient().SendAsync(request, HttpCompletionOption.ResponseContentRead);
            }
            catch (Exception ex)
            {
                throw new FirebaseException(
                    $"An error occured while execute request. Path : {path} , Method : {method}", ex);
            }
        }
Ejemplo n.º 3
0
        public Task <HttpResponseMessage> RequestApiAsync(HttpMethod method, string path, QueryBuilder queryBuilder, object payload = null)
        {
            try
            {
                var uri     = PrepareApiUri(path, queryBuilder);
                var request = PrepareRequest(method, uri, payload);

                return(GetClient().SendAsync(request, HttpCompletionOption.ResponseContentRead));
            }
            catch (Exception ex)
            {
                throw new FirebaseException(
                          $"An error occured while execute request. Path : {path} , Method : {method}", ex);
            }
        }
Ejemplo n.º 4
0
        private Uri PrepareApiUri(string path, QueryBuilder queryBuilder)
        {
            string uriString = $"https://auth.firebase.com/v2/{_config.Host}/{path}?{queryBuilder.ToQueryString()}";

            return(new Uri(uriString));
        }
Ejemplo n.º 5
0
 private Uri PrepareApiUri(string path, QueryBuilder queryBuilder)
 {
     string uriString = $"https://auth.firebase.com/v2/{_config.Host}/{path}?{queryBuilder.ToQueryString()}";
     return new Uri(uriString);
 }
Ejemplo n.º 6
0
        private Uri PrepareUri(string path, QueryBuilder queryBuilder)
        {
            var authToken = !string.IsNullOrWhiteSpace(_config.AuthSecret)
                ? $"{path}.json?auth={_config.AuthSecret}"
                : $"{path}.json";

            var queryStr = string.Empty;
            if (queryBuilder != null)
            {
                queryStr = $"&{queryBuilder.ToQueryString()}";
            }

            var url = $"{_config.BasePath}{authToken}{queryStr}";

            return new Uri(url);
        }
Ejemplo n.º 7
0
        private HttpClient PrepareEventStreamRequest(string path, QueryBuilder queryBuilder, out HttpRequestMessage request)
        {
            var client = GetClient();
            var uri = PrepareUri(path, queryBuilder);

            request = new HttpRequestMessage(HttpMethod.Get, uri);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/event-stream"));

            return client;
        }