Пример #1
0
        public RequestData <StreamList> Streams(string username)
        {
            var requestUrl = "https://api.twitch.tv/kraken/streams/followed";

            var response = HttpWebRequestWrapper.ExecuteWebRequest(requestUrl, OAuthData.token);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                var responseError = HttpWebRequestWrapper.ParseResponse <RequestErrorMessage>(response.ResponseString);

                return(new RequestData <StreamList>(responseError));
            }


            var responseData = HttpWebRequestWrapper.ParseResponse <StreamList>(response.ResponseString);

            if (responseData != null && responseData.Total > 0)
            {
                var total   = responseData.Total;
                var current = responseData.Streams.Count;
                var nexturl = responseData.Links.Next;

                do
                {
                    var nextLinks = NextStreams(nexturl);
                    responseData.Streams.AddRange(nextLinks.Data.Streams);

                    nexturl  = nextLinks.Data.Links.Next;
                    current += nextLinks.Data.Streams.Count;
                } while (total > current);
            }

            return(new RequestData <StreamList>(responseData));
        }
Пример #2
0
        public RequestData <StreamList> NextStreams(string url)
        {
            var requestUrl = url;
            var response   = HttpWebRequestWrapper.ExecuteWebRequest(requestUrl, OAuthData.token);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                var responseError = HttpWebRequestWrapper.ParseResponse <RequestErrorMessage>(response.ResponseString);
                return(new RequestData <StreamList>(responseError));
            }

            var responseData = HttpWebRequestWrapper.ParseResponse <StreamList>(response.ResponseString);

            return(new RequestData <StreamList>(responseData));
        }
Пример #3
0
        public RequestData <FollowList> Follows(string username)
        {
            var requestUrl = "https://api.twitch.tv/kraken/users/" + username + "/follows/channels";
            var response   = HttpWebRequestWrapper.ExecuteWebRequest(requestUrl, OAuthData.token);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                var responseError = HttpWebRequestWrapper.ParseResponse <RequestErrorMessage>(response.ResponseString);
                return(new RequestData <FollowList>(responseError));
            }

            var responseData = HttpWebRequestWrapper.ParseResponse <FollowList>(response.ResponseString);

            return(new RequestData <FollowList>(responseData));
        }
Пример #4
0
        private RequestData <User> ValidateUsername(string username)
        {
            var response = HttpWebRequestWrapper.ExecuteWebRequest("https://api.twitch.tv/kraken/users/" + username);

            while (response.StatusCode == HttpStatusCode.Redirect || response.StatusCode == HttpStatusCode.RedirectKeepVerb)
            {
                response = HttpWebRequestWrapper.ExecuteWebRequest(response.RedirectUri.AbsolutePath);
            }

            if (response.StatusCode != HttpStatusCode.OK)
            {
                var responseError = HttpWebRequestWrapper.ParseResponse <User>(response.ResponseString);
                return(new RequestData <User>(responseError));
            }

            var responseData = HttpWebRequestWrapper.ParseResponse <User>(response.ResponseString);

            return(new RequestData <User>(responseData));
        }