示例#1
0
 public async Task<CurrentGameInfoLive> RetrieveCurrentGameInfo()
 {
     Url url = new Url(UrlConstants.GetBaseUrl(region)).AppendPathSegments(UrlConstants.observerModeRestpart,
         "/consumer/getSpectatorGameInfo/", UrlConstants.GetPlatformId(region), id.ToString());
     url.SetQueryParams(new
     {
         api_key = CreepScore.apiKey
     });
     Uri uri = new Uri(url.ToString());
     await CreepScore.GetPermission(region);
     string responseString = await CreepScore.GetWebData(uri);
     if (CreepScore.GoodStatusCode(responseString))
     {
         return HelperMethods.LoadCurrentGameInfo(JObject.Parse(responseString));
     }
     else
     {
         if (responseString == "404")
         {
             // might want to do something different if 404
             return null;
         }
         else
         {
             return null;
         }
     }
 }
示例#2
0
        /// <summary>
        /// Gets a Total object containing a list of videos for a specified channel
        /// </summary>
        /// <param name="channel">The name of the channel</param>
        /// <param name="offset">Object offset for pagination. Default is 0.</param>
        /// <param name="limit">How many videos to get at one time. Default is 10. Maximum is 100.</param>
        /// <param name="broadcasts">Returns only broadcasts when true. Otherwise only highlights are returned. Default is false.</param>
        /// <param name="hls">Returns only HLS VoDs when true. Otherwise only non-HLS VoDs are returned. Default is false.</param>
        /// <param name="version">Twitch API version</param>
        /// <returns>A Total object containing list of videos</returns>
        public async Task<Total<List<Video>>> RetrieveVideos(string channel = null,
            int offset = 0, int limit = 25,
            bool broadcasts = false,
            bool? hls = null,
            APIVersion version = APIVersion.None)
        {
            if (version == APIVersion.None)
            {
                version = DefaultVersion;
            }
            Url url = new Url(TwitchConstants.baseUrl).AppendPathSegments("channels", channel, "videos");
            if (limit <= 100)
            {
                url.SetQueryParam("limit", limit);
            }
            else
            {
                url.SetQueryParam("limit", 100);
            }
            url.SetQueryParams(new
            {
                broadcasts = broadcasts,
                offset = offset
            });
            if (version == APIVersion.v3)
            {
                if (hls == null)
                {
                    hls = false;
                }
                url.SetQueryParam("hls", hls);
            }

            Uri uri = new Uri(url.ToString());
            string responseString;
            try
            {
                responseString = await GetWebData(uri, version);
            }
            catch (TwitchException ex)
            {
                throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex);
            }
            JObject responseObject = JObject.Parse(responseString);
            List<Video> videos = HelperMethods.LoadVideos(responseObject, version);
            return HelperMethods.LoadTotal(responseObject, videos, version);
        }
示例#3
0
 /// <summary>
 /// Gets a Total object containing a list of Follow objects of type Channel this user is following
 /// </summary>
 /// <param name="offset">Object offset for pagination. Default is 0.</param>
 /// <param name="limit">How many channels to get at one time. Default is 25. Maximum is 100</param>
 /// <param name="direction">Sorting direction. Default is Decending.</param>
 /// <param name="sortBy">Sort by. Default is CreatedAt.</param>
 /// <returns>A Total object containing a list of Follow objects of type Channel</returns>
 public async Task<Total<List<Follow<Channel>>>> RetrieveFollowing(int offset = 0, int limit = 25,
     TwitchConstants.Direction direction = TwitchConstants.Direction.Decending,
     TwitchConstants.SortBy sortBy = TwitchConstants.SortBy.CreatedAt)
 {
     Url url = new Url(TwitchConstants.baseUrl).AppendPathSegments("users", name, "follows", "channels");
     if (limit <= 100)
     {
         url.SetQueryParam("limit", limit);
     }
     else
     {
         url.SetQueryParam("limit", 100);
     }
     url.SetQueryParams(new
     {
         offset = offset,
         direction = TwitchConstants.DirectionToString(direction),
         sortby = TwitchConstants.SortByToString(sortBy)
     });
     Uri uri = new Uri(url.ToString());
     string responseString;
     try
     {
         responseString = await Twixel.GetWebData(uri, version);
     }
     catch (TwitchException ex)
     {
         throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex);
     }
     JObject responseObject = JObject.Parse(responseString);
     List<Follow<Channel>> channels = HelperMethods.LoadChannelFollows(responseObject, version);
     return HelperMethods.LoadTotal(responseObject, channels, version);
 }
示例#4
0
 public async Task<FeaturedGamesLive> RetrieveFeaturedGames(CreepScore.Region region)
 {
     Url url = new Url(UrlConstants.GetBaseUrl(region)).AppendPathSegments(UrlConstants.observerModeRestpart,
         "/featured");
     url.SetQueryParams(new
     {
         api_key = apiKey
     });
     Uri uri = new Uri(url.ToString());
     await CreepScore.GetPermission(region);
     string responseString = await CreepScore.GetWebData(uri);
     if (CreepScore.GoodStatusCode(responseString))
     {
         return LoadFeaturedGames(JObject.Parse(responseString));
     }
     else
     {
         return null;
     }
 }
示例#5
0
 /// <summary>
 /// Get a Total object containing a list of Subscription of type User
 /// Requires authorization.
 /// Requires Twitch partnership.
 /// Requires channel_subscriptions.
 /// </summary>
 /// <param name="offset">Object offset for pagination. Default is 0.</param>
 /// <param name="limit">How many subscriptions to get at one time. Default is 25. Maximum is 100</param>
 /// <param name="direction">Creation date sorting direction. Default is Ascending.</param>
 /// <returns>A Total object containing a list of Subscription objects of type User</returns>
 public async Task<Total<List<Subscription<User>>>> RetriveSubscribers(int offset = 0, int limit = 25,
     TwitchConstants.Direction direction = TwitchConstants.Direction.Ascending)
 {
     TwitchConstants.Scope relevantScope = TwitchConstants.Scope.ChannelSubscriptions;
     if (authorized && authorizedScopes.Contains(relevantScope) && partnered)
     {
         Url url = new Url(TwitchConstants.baseUrl).AppendPathSegments("channels", name, "subscriptions");
         if (limit <= 100)
         {
             url.SetQueryParam("limit", limit);
         }
         else
         {
             url.SetQueryParam("limit", 100);
         }
         url.SetQueryParams(new
         {
             offset = offset,
             direction = TwitchConstants.DirectionToString(direction)
         });
         Uri uri = new Uri(url.ToString());
         string responseString;
         try
         {
             responseString = await Twixel.GetWebData(uri, accessToken, version);
         }
         catch (TwitchException ex)
         {
             throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex);
         }
         JObject responseObject = JObject.Parse(responseString);
         List<Subscription<User>> subs = HelperMethods.LoadUserSubscriptions(JObject.Parse(responseString), version);
         return HelperMethods.LoadTotal(responseObject, subs, version);
     }
     else
     {
         if (!authorized)
         {
             throw new TwixelException(NotAuthedError());
         }
         else if (!authorizedScopes.Contains(relevantScope))
         {
             throw new TwixelException(MissingPermissionError(relevantScope));
         }
         else if (!partnered)
         {
             throw new TwixelException(NotPartneredError());
         }
         else
         {
             throw new TwixelException(TwitchConstants.unknownErrorString);
         }
     }
 }