Beispiel #1
0
        public static void APIRequest <K>(Action <K> callback, Tuple <string, string>[] getParameters, Tuple <string, string>[] postParameters)
            where K : Response
        {
            RequestPath path = RequestPath.GetRequestPath <K>();
            //TODO: Custom paths? Appropriate subdomain paths? Not sure.
            //Maybe store custom path in the requestpath.path itself?

            string parameters = getParameters
                                .Select(new Func <Tuple <string, string>, string>(a => string.Format("{0}={1}", Uri.UnescapeDataString(a.Item1), Uri.UnescapeDataString(a.Item2))))
                                .Aggregate((a, b) =>
            {
                if (string.IsNullOrEmpty(a))
                {
                    return(b);
                }
                else
                {
                    return(string.Format("{0}&{1}", a, b));
                }
            });

            Uri requestUri = new Uri(string.Format("{0}?{1}", Path.Combine(APIBaseLocation, path.Path), parameters));

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);

            //This will handle all of the processing.
            RequestState <K> state = new RequestState <K>(request, postParameters, callback);

            state.Begin();
        }
Beispiel #2
0
        public Task <K> APIRequestAsync <K>(Tuple <string, string>[] getParameters, Tuple <string, string>[] postParameters)
            where K : Response
        {
            RequestPath path = RequestPath.GetRequestPath <K>();
            //TODO: Custom paths? Appropriate subdomain paths? Not sure.
            //Maybe store custom path in the requestpath.path itself?

            Uri            requestUri = GetSlackUri(Path.Combine(APIBaseLocation, path.Path), getParameters);
            HttpWebRequest request    = CreateWebRequest(requestUri);

            //This will handle all of the processing.
            var state = new RequestStateForTask <K>(request, postParameters);

            return(state.Execute());
        }
Beispiel #3
0
        protected void APIRequest <K>(Action <K> callback, Tuple <string, string>[] getParameters, Tuple <string, string>[] postParameters)
            where K : Response
        {
            RequestPath path = RequestPath.GetRequestPath <K>();
            //TODO: Custom paths? Appropriate subdomain paths? Not sure.
            //Maybe store custom path in the requestpath.path itself?

            Uri            requestUri = GetSlackUri(Path.Combine(APIBaseLocation, path.Path), getParameters);
            HttpWebRequest request    = CreateWebRequest(requestUri);

            //This will handle all of the processing.
            RequestState <K> state = new RequestState <K>(request, postParameters, callback);

            state.Begin();
        }