Esempio n. 1
0
        internal static async Task <Models.API.Stream.FollowedStreamsResponse> GetFollowedStreams(Enums.StreamType streamType = Enums.StreamType.Live, int limit = 25, int offset = 0, string accessToken = null)
        {
            if (limit > 100 || limit < 0)
            {
                throw new Exceptions.API.BadParameterException("Limit must be larger than 0 and equal to or smaller than 100");
            }

            string args = $"?limit={limit}&offset={offset}";

            switch (streamType)
            {
            case Enums.StreamType.Live:
                args += "&stream_type=live";
                break;

            case Enums.StreamType.Playlist:
                args += "&stream_type=playlist";
                break;

            case Enums.StreamType.All:
                args += "&stream_type=all";
                break;
            }

            string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/streams/followed{args}", accessToken, 5);

            return(new Models.API.Stream.FollowedStreamsResponse(JObject.Parse(resp)));
        }
Esempio n. 2
0
        internal static async Task <List <Models.API.Stream.Stream> > SearchStreams(string query, int limit = 25, int offset = 0, bool?hls = null)
        {
            var returnedStreams = new List <Models.API.Stream.Stream>();
            var hlsStr          = "";

            if (hls == true)
            {
                hlsStr = "&hls=true";
            }
            if (hls == false)
            {
                hlsStr = "&hls=false";
            }
            var args = $"?query={query}&limit={limit}&offset={offset}{hlsStr}";
            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/search/streams{args}");

            var json = JObject.Parse(resp);

            if (json.SelectToken("_total").ToString() == "0")
            {
                return(returnedStreams);
            }
            returnedStreams.AddRange(
                json.SelectToken("streams").Select(streamToken => new Models.API.Stream.Stream((JObject)streamToken)));
            return(returnedStreams);
        }
Esempio n. 3
0
        internal static async Task <Models.API.Follow.FollowedUsersResponse> GetFollowedUsers(string channel, int limit = 25, int offset = 0, Enums.SortKey sortKey = Enums.SortKey.CreatedAt)
        {
            string args = "";

            args += "?limit=" + limit;
            args += "&offset=" + offset;
            switch (sortKey)
            {
            case Enums.SortKey.CreatedAt:
                args += "&sortby=created_at";
                break;

            case Enums.SortKey.LastBroadcaster:
                args += "&sortby=last_broadcast";
                break;

            case Enums.SortKey.Login:
                args += "&sortby=login";
                break;
            }

            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/users/{channel}/follows/channels{args}");

            return(new Models.API.Follow.FollowedUsersResponse(resp));
        }
Esempio n. 4
0
        internal static async Task <List <Models.API.Stream.FeaturedStream> > GetFeaturedStreams(int limit = 25, int offset = 0)
        {
            var json = JObject.Parse(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/streams/featured?limit={limit}&offset={offset}"));
            List <Models.API.Stream.FeaturedStream> streams = new List <Models.API.Stream.FeaturedStream>();

            streams.AddRange(json.SelectToken("featured").Select(stream => new Models.API.Stream.FeaturedStream(stream)));
            return(streams);
        }
Esempio n. 5
0
        internal static async Task <List <Models.API.Stream.Stream> > GetStreams(List <string> channels)
        {
            var json = JObject.Parse(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/streams?channel={string.Join(",", channels)}"));
            List <Models.API.Stream.Stream> streams = new List <Models.API.Stream.Stream>();

            streams.AddRange(json.SelectToken("streams").Select(stream => new Models.API.Stream.Stream(stream)));
            return(streams);
        }
Esempio n. 6
0
        internal static async Task <Models.API.Subscriber.SubscribersResponse> GetSubscribers(string channel, int limit = 25, int offset = 0, Enums.SortDirection direction = Enums.SortDirection.Ascending, string accessToken = null)
        {
            string args = $"?limit={limit}";

            args += $"&offset={offset}";
            args += $"&direction={(direction == Enums.SortDirection.Descending ? "desc" : "asc")}";

            return(new Models.API.Subscriber.SubscribersResponse(JObject.Parse(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/channels/{channel}/subscriptions{args}", accessToken))));
        }
Esempio n. 7
0
        internal static async Task <int> GetSubscriberCount(string channel, string accessToken = null)
        {
            var resp =
                await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/channels/{channel}/subscriptions", accessToken);

            var json = JObject.Parse(resp);

            return(int.Parse(json.SelectToken("_total").ToString()));
        }
Esempio n. 8
0
        internal static async Task <List <TeamMember> > GetTeamMembers(string teamName)
        {
            var json = JObject.Parse(await Requests.MakeGetRequest($"http://api.twitch.tv/api/team/{teamName}/all_channels.json"));

            return
                (json.SelectToken("channels")
                 .Select(member => new TeamMember(member.SelectToken("channel")))
                 .ToList());
        }
Esempio n. 9
0
        internal static async Task <List <string> > GetChannelHosts(string channel)
        {
            var  hosts = new List <string>();
            User user  = await GetUser(channel);

            var json = JObject.Parse(await Requests.MakeGetRequest($"http://tmi.twitch.tv/hosts?include_logins=1&target={user.Id}"));

            hosts.AddRange(json.SelectToken("hosts").Select(host => host.SelectToken("host_login").ToString()));
            return(hosts);
        }
Esempio n. 10
0
        internal static async Task <Models.API.Feed.FeedResponse> GetChannelFeed(string channel, int limit = 10, string cursor = null)
        {
            var args = $"?limit={limit}";

            if (cursor != null)
            {
                args += $"&cursor={cursor};";
            }
            return(new Models.API.Feed.FeedResponse(JObject.Parse(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/feed/{channel}/posts{args}"))));
        }
Esempio n. 11
0
        internal static async Task <List <Models.API.Video.Video> > GetChannelVideos(string channel, int limit = 10,
                                                                                     int offset = 0, bool onlyBroadcasts = false, bool onlyHls = false)
        {
            var args = $"?limit={limit}&offset={offset}&broadcasts={onlyBroadcasts.ToString().ToLower()}&hls={onlyHls.ToString().ToLower()}";
            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/channels/{channel}/videos{args}");

            var vids = JObject.Parse(resp).SelectToken("videos");

            return(vids.Select(vid => new Models.API.Video.Video(vid)).ToList());
        }
Esempio n. 12
0
        internal static async Task <List <User> > GetChannelEditors(string channel, string accessToken = null)
        {
            var         json    = JObject.Parse(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/channels/{channel}/editors", accessToken));
            List <User> editors = new List <User>();

            foreach (JToken editor in json.SelectToken("users"))
            {
                editors.Add(new User(editor.ToString()));
            }
            return(editors);
        }
Esempio n. 13
0
        internal static async Task <List <Models.API.Channel.Channel> > SearchChannels(string query, int limit = 25, int offset = 0)
        {
            var returnedChannels = new List <Models.API.Channel.Channel>();
            var json             = JObject.Parse(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/search/channels?query={query}&limit={limit}&offset={offset}"));

            if (json.SelectToken("_total").ToString() == "0")
            {
                return(returnedChannels);
            }
            returnedChannels.AddRange(json.SelectToken("channels").Select(channelToken => new Models.API.Channel.Channel((JObject)channelToken)));
            return(returnedChannels);
        }
Esempio n. 14
0
        internal static async Task <string> GetChannelFromSteamId(string steamId)
        {
            try
            {
                string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/api/steam/{steamId}");

                return(JObject.Parse(resp).SelectToken("name").ToString());
            } catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 15
0
        internal static async Task <Models.API.Follow.Follow> UserFollowsChannel(string username, string channel)
        {
            try
            {
                string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/users/{username}/follows/channels/{channel}");

                return(new Models.API.Follow.Follow(resp));
            }
            catch
            {
                return(new Models.API.Follow.Follow(null, false));
            }
        }
Esempio n. 16
0
        internal static async Task <List <Models.API.Game.GameByPopularityListing> > GetGamesByPopularity(int limit = 10, int offset = 0)
        {
            var returnedGames = new List <Models.API.Game.GameByPopularityListing>();

            var args = $"?limit={limit}&offset={offset}";
            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/games/top{args}");

            var json = JObject.Parse(resp);

            returnedGames.AddRange(
                json.SelectToken("top").Select(gameToken => new Models.API.Game.GameByPopularityListing((JObject)gameToken)));
            return(returnedGames);
        }
Esempio n. 17
0
        internal static async Task <List <Models.API.Game.Game> > SearchGames(string query, bool live = false)
        {
            var returnedGames = new List <Models.API.Game.Game>();

            var args = $"?query={query}&type=suggest&live=" + live.ToString();
            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/search/games{args}");

            var json = JObject.Parse(resp);

            returnedGames.AddRange(
                json.SelectToken("games").Select(gameToken => new Models.API.Game.Game((JObject)gameToken)));
            return(returnedGames);
        }
Esempio n. 18
0
        internal static async Task <Models.API.Follow.FollowersResponse> GetTwitchFollowers(string channel, int limit = 25,
                                                                                            string cursor             = "-1", Enums.SortDirection direction = Enums.SortDirection.Descending)
        {
            string args = "";

            args += "?limit=" + limit;
            args += cursor != "-1" ? $"&cursor={cursor}" : "";
            args += "&direction=" + (direction == Enums.SortDirection.Descending ? "desc" : "asc");

            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/channels/{channel}/follows{args}");

            return(new Models.API.Follow.FollowersResponse(resp));
        }
Esempio n. 19
0
        internal async static Task <List <Models.API.Community.CommunityModerator> > GetCommunityModerators(string communityId)
        {
            List <Models.API.Community.CommunityModerator> communityModerators = new List <Models.API.Community.CommunityModerator>();
            string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/communities/{communityId}/moderators", null, 5);

            JObject json = JObject.Parse(resp);

            foreach (JToken mod in json.SelectToken("moderators"))
            {
                communityModerators.Add(new Models.API.Community.CommunityModerator(mod));
            }
            return(communityModerators);
        }
Esempio n. 20
0
        internal static async Task <Models.API.Stream.Stream> GetStream(string channel)
        {
            var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/streams/{channel}");

            var json = JObject.Parse(resp);

            if (!Common.Helpers.JsonIsNullOrEmpty(json.SelectToken("error")))
            {
                throw new BadResourceException(json.SelectToken("error").ToString());
            }
            if (Common.Helpers.JsonIsNullOrEmpty(json.SelectToken("stream")))
            {
                throw new StreamOfflineException();
            }
            return(new Models.API.Stream.Stream(json.SelectToken("stream")));
        }
Esempio n. 21
0
        internal async static Task <Models.API.Community.Community> GetCommunityById(string id)
        {
            string  response = (await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/communities/{id}", null, 5));
            JObject json     = JObject.Parse(response);
            JToken  val;

            if (json.TryGetValue("error", out val))
            {
                if (val.ToString() == "Not Found")
                {
                    throw new BadResourceException(response);
                }
            }

            return(new Models.API.Community.Community(json));
        }
Esempio n. 22
0
        internal static async Task <bool> BroadcasterOnline(string channel)
        {
            try
            {
                var resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/streams/{channel}");

                return(resp.Contains("{\"stream\":{\"_id\":"));
            }
            catch (InvalidCredentialException badCredentials)
            {
                throw badCredentials;
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 23
0
        internal static async Task <List <Models.API.Block.Block> > GetBlockedList(string username, string accessToken = null, int limit = 25, int offset = 0)
        {
            string args = $"?limit={limit}&offset={offset}";
            string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/users/{username}/blocks{args}", accessToken);

            JObject json = JObject.Parse(resp);
            List <Models.API.Block.Block> blocks = new List <Models.API.Block.Block>();

            if (json.SelectToken("blocks") != null)
            {
                foreach (JToken block in json.SelectToken("blocks"))
                {
                    blocks.Add(new Models.API.Block.Block(block));
                }
            }
            return(blocks);
        }
Esempio n. 24
0
        internal async static Task <Models.API.Community.CommunityTimedOutUsersResponse> GetTimedOutCommunityUsers(string communityId, long?limit = null, string cursor = null, string accessToken = null)
        {
            if (limit != null && limit > 100)
            {
                throw new BadParameterException("Limit may not be larger than 100");
            }

            string args = (limit == null) ? "?limit=10" : $"?limit={limit}";

            if (cursor != null)
            {
                args += $"&cursor={cursor}";
            }

            string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/communities/{communityId}/timeouts{args}", accessToken, 5);

            return(new Models.API.Community.CommunityTimedOutUsersResponse(JObject.Parse(resp)));
        }
Esempio n. 25
0
        internal async static Task <Models.API.Community.StreamsInCommunityResponse> GetStreamsInCommunity(string communityId, long?limit = null, string cursor = null)
        {
            if (limit != null && limit > 100)
            {
                throw new BadParameterException("Limit may not be larger than 100");
            }

            string args = (limit == null) ? "?limit=10" : $"?limit={limit}";

            if (cursor != null)
            {
                args += $"&cursor={cursor}";
            }

            string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/streams?community_id={communityId}", null, 5);

            return(new Models.API.Community.StreamsInCommunityResponse(JObject.Parse(resp)));
        }
Esempio n. 26
0
        internal static async Task <bool> ValidClientId(string clientId, bool updateClientIdOnSuccess = true)
        {
            string oldClientId;

            if (!string.IsNullOrEmpty(ClientId))
            {
                oldClientId = ClientId;
            }
            var resp = await Requests.MakeGetRequest("https://api.twitch.tv/kraken");

            var json = JObject.Parse(resp);

            if (json.SelectToken("identified") != null && (bool)json.SelectToken("identified") == true)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 27
0
        internal static async Task <Models.API.Clip.ClipsResponse> GetTopClips(List <string> channels = null, List <string> games = null, int limit = 10, string cursor = null, Enums.Period period = Enums.Period.Day, bool trending = false)
        {
            string channelsStr = (channels != null) ? $"channel={string.Join(",", channels)}" : null;
            string gamesStr    = (games != null) ? $"game={string.Join(",", games)}" : null;
            string limitStr    = $"limit={limit}";
            string cursorStr   = (cursor != null) ? $"cursor={cursor}" : null;
            string periodStr   = "";

            switch (period)
            {
            case Enums.Period.All:
                periodStr = "period=all";
                break;

            case Enums.Period.Day:
                periodStr = "period=day";
                break;

            case Enums.Period.Month:
                periodStr = "period=month";
                break;

            case Enums.Period.Week:
                periodStr = "period=week";
                break;
            }
            string trendingStr = (trending) ? "trending=true" : "trending=false";
            string url         = $"https://api.twitch.tv/kraken/clips/top?{limitStr}&{periodStr}";

            if (channels != null)
            {
                url = $"{url}&{channelsStr}";
            }
            if (games != null)
            {
                url = $"{url}&{gamesStr}";
            }
            if (cursor != null)
            {
                url = $"{url}&{cursorStr}";
            }
            return(new Models.API.Clip.ClipsResponse(JObject.Parse(await Requests.MakeGetRequest(url, null, 4))));
        }
Esempio n. 28
0
        internal static async Task <List <Models.API.Chat.Chatter> > GetChatters(string channel)
        {
            var resp = await Requests.MakeGetRequest($"https://tmi.twitch.tv/group/user/{channel.ToLower()}/chatters");

            var chatters    = JObject.Parse(resp).SelectToken("chatters");
            var chatterList =
                chatters.SelectToken("moderators")
                .Select(user => new Models.API.Chat.Chatter(user.ToString(), Enums.UserType.Moderator))
                .ToList();

            chatterList.AddRange(
                chatters.SelectToken("staff").Select(user => new Models.API.Chat.Chatter(user.ToString(), Enums.UserType.Staff)));
            chatterList.AddRange(
                chatters.SelectToken("admins").Select(user => new Models.API.Chat.Chatter(user.ToString(), Enums.UserType.Admin)));
            chatterList.AddRange(
                chatters.SelectToken("global_mods")
                .Select(user => new Models.API.Chat.Chatter(user.ToString(), Enums.UserType.GlobalModerator)));
            chatterList.AddRange(
                chatters.SelectToken("viewers").Select(user => new Models.API.Chat.Chatter(user.ToString(), Enums.UserType.Viewer)));
            return(chatterList);
        }
Esempio n. 29
0
        internal async static Task <Models.API.Community.Community> GetChannelCommunity(string channelId)
        {
            string resp = await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/channels/{channelId}/community", null, 5);

            return(new Models.API.Community.Community(JObject.Parse(resp)));
        }
Esempio n. 30
0
 internal static async Task <User> GetUser(string username)
 {
     return(new User(await Requests.MakeGetRequest($"https://api.twitch.tv/kraken/users/{username}")));
 }