/// <summary>
        /// Retrieve user timeline data with specific parser.
        /// </summary>
        /// <typeparam name="TSchema">Strong type for results.</typeparam>
        /// <param name="screenName">User screen name.</param>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific results parser.</param>
        /// <returns>Returns strongly typed list of results.</returns>
        public async Task <IEnumerable <TSchema> > GetUserTimeLineAsync <TSchema>(string screenName, int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            string rawResult = null;

            try
            {
                var uri = new Uri($"{BaseUrl}/statuses/user_timeline.json?screen_name={OAuthEncoder.UrlEncode(screenName)}&count={maxRecords}");

                WeiboOAuthRequest request = new WeiboOAuthRequest();
                rawResult = await request.ExecuteGetAsync(uri, _tokens);

                var result = parser.Parse(rawResult);
                return(result
                       .Take(maxRecords)
                       .ToList());
            }
            catch (UserNotFoundException)
            {
                throw new UserNotFoundException(screenName);
            }
            catch
            {
                if (!string.IsNullOrEmpty(rawResult))
                {
                    var errors = JsonConvert.DeserializeObject <WeiboError>(rawResult);

                    throw new WeiboException {
                              Error = errors
                    };
                }

                throw;
            }
        }
        /// <summary>
        /// Get home time line data.
        /// </summary>
        /// <typeparam name="TSchema">Strong typed result.</typeparam>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific result parser.</param>
        /// <returns>Return strong typed list of results.</returns>
        private async Task <IEnumerable <TSchema> > GetHomeTimeLineAsync <TSchema>(int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            var uri = new Uri($"{BaseUrl}/statuses/home_timeline.json?count={maxRecords}");

            WeiboOAuthRequest request = new WeiboOAuthRequest();
            var rawResult             = await request.ExecuteGetAsync(uri, _tokens);

            return(parser.Parse(rawResult));
        }
Esempio n. 3
0
        /// <summary>
        /// Get home time line data.
        /// </summary>
        /// <typeparam name="TSchema">Strong typed result.</typeparam>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific result parser.</param>
        /// <returns>Return strong typed list of results.</returns>
        private async Task <IEnumerable <TSchema> > GetHomeTimeLineAsync <TSchema>(int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            var uri = new Uri($"{BaseUrl}/statuses/home_timeline.json?count={maxRecords}&tweet_mode=extended");

            TwitterOAuthRequest request = new TwitterOAuthRequest();
            var rawResult = await request.ExecuteGetAsync(uri, _tokens, _signatureManager);

            return(parser.Parse(rawResult));
        }
Esempio n. 4
0
        private async Task <IEnumerable <TSchema> > GetCustomSearch <TSchema>(string query, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            var uri = new Uri($"{BaseUrl}/{query}");

            TwitterOAuthRequest request = new TwitterOAuthRequest();

            var rawResult = await request.ExecuteGetAsync(uri, _tokens, _signatureManager);

            return(parser.Parse(rawResult));
        }
Esempio n. 5
0
        /// <summary>
        /// Search for specific hash tag with specific parser.
        /// </summary>
        /// <typeparam name="TSchema">Strong type for results.</typeparam>
        /// <param name="hashTag">Hash tag.</param>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific results parser.</param>
        /// <returns>Returns strongly typed list of results.</returns>
        public async Task <IEnumerable <TSchema> > SearchAsync <TSchema>(string hashTag, int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            var uri = new Uri($"{BaseUrl}/search/tweets.json?q={Uri.EscapeDataString(hashTag)}&count={maxRecords}&tweet_mode=extended");
            TwitterOAuthRequest request = new TwitterOAuthRequest();
            var rawResult = await request.ExecuteGetAsync(uri, _tokens, _signatureManager);

            var result = parser.Parse(rawResult);

            return(result
                   .Take(maxRecords)
                   .ToList());
        }
Esempio n. 6
0
        /// <summary>
        /// Wrapper around REST API for making data request.
        /// </summary>
        /// <typeparam name="TSchema">Schema to use</typeparam>
        /// <param name="config">Query configuration.</param>
        /// <param name="maxRecords">Upper limit for records returned.</param>
        /// <param name="pageIndex">The zero-based index of the page that corresponds to the items to retrieve.</param>
        /// <param name="parser">IParser implementation for interpreting results.</param>
        /// <returns>Strongly typed list of results.</returns>
        protected override async Task <IEnumerable <TSchema> > GetDataAsync <TSchema>(TwitterDataConfig config, int maxRecords, int pageIndex, Toolkit.Parsers.IParser <TSchema> parser)
        {
            IEnumerable <TSchema> items;

            switch (config.QueryType)
            {
            case TwitterQueryType.User:
                items = await GetUserTimeLineAsync(config.Query, maxRecords, parser);

                break;

            case TwitterQueryType.Search:
                items = await SearchAsync(config.Query, maxRecords, parser);

                break;

            case TwitterQueryType.Custom:
                items = await GetCustomSearch(config.Query, parser);

                break;

            case TwitterQueryType.Home:
            default:
                items = await GetHomeTimeLineAsync(maxRecords, parser);

                break;
            }

            return(items);
        }
Esempio n. 7
0
        /// <summary>
        /// Retrieve user timeline data with specific parser.
        /// </summary>
        /// <typeparam name="TSchema">Strong type for results.</typeparam>
        /// <param name="screenName">User screen name.</param>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific results parser.</param>
        /// <returns>Returns strongly typed list of results.</returns>
        public async Task <IEnumerable <TSchema> > GetUserTimeLineAsync <TSchema>(string screenName, int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            string rawResult = null;

            try
            {
                var uri = new Uri($"{BaseUrl}/statuses/user_timeline.json?screen_name={screenName}&count={maxRecords}&include_rts=1&tweet_mode=extended");

                TwitterOAuthRequest request = new TwitterOAuthRequest();
                rawResult = await request.ExecuteGetAsync(uri, _tokens, _signatureManager);

                var result = parser.Parse(rawResult);
                return(result
                       .Take(maxRecords)
                       .ToList());
            }
            catch (UserNotFoundException)
            {
                throw new UserNotFoundException(screenName);
            }
            catch
            {
                if (!string.IsNullOrEmpty(rawResult))
                {
                    var errors = JsonSerializer.Deserialize <TwitterErrors>(rawResult);

                    throw new TwitterException {
                              Errors = errors
                    };
                }

                throw;
            }
        }
Esempio n. 8
0
        private async Task <IEnumerable <TSchema> > GetCustomSearch <TSchema>(string query, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            try
            {
                var uri = new Uri($"{BaseUrl}/{query}");

                TwitterOAuthRequest request = new TwitterOAuthRequest();
                var rawResult = await request.ExecuteGetAsync(uri, _tokens);

                return(parser.Parse(rawResult));
            }
            catch (WebException wex)
            {
                HttpWebResponse response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    if ((int)response.StatusCode == 429)
                    {
                        throw new TooManyRequestsException();
                    }

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        throw new OAuthKeysRevokedException();
                    }
                }

                throw;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Get home time line data.
        /// </summary>
        /// <typeparam name="TSchema">Strong typed result.</typeparam>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific result parser.</param>
        /// <returns>Return strong typed list of results.</returns>
        private async Task <IEnumerable <TSchema> > GetHomeTimeLineAsync <TSchema>(int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            try
            {
                var uri = new Uri($"{BaseUrl}/statuses/home_timeline.json?count={maxRecords}");

                TwitterOAuthRequest request = new TwitterOAuthRequest();
                var rawResult = await request.ExecuteGetAsync(uri, _tokens);

                return(parser.Parse(rawResult));
            }
            catch (WebException wex)
            {
                HttpWebResponse response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    if ((int)response.StatusCode == 429)
                    {
                        throw new TooManyRequestsException();
                    }

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        throw new OAuthKeysRevokedException();
                    }
                }

                throw;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Search for specific hash tag with specific parser.
        /// </summary>
        /// <typeparam name="TSchema">Strong type for results.</typeparam>
        /// <param name="hashTag">Hash tag.</param>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific results parser.</param>
        /// <returns>Returns strongly typed list of results.</returns>
        public async Task <IEnumerable <TSchema> > SearchAsync <TSchema>(string hashTag, int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            try
            {
                var uri = new Uri($"{BaseUrl}/search/tweets.json?q={Uri.EscapeDataString(hashTag)}&count={maxRecords}");
                TwitterOAuthRequest request = new TwitterOAuthRequest();
                var rawResult = await request.ExecuteGetAsync(uri, _tokens);

                var result = parser.Parse(rawResult);
                return(result
                       .Take(maxRecords)
                       .ToList());
            }
            catch (WebException wex)
            {
                HttpWebResponse response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    if ((int)response.StatusCode == 429)
                    {
                        throw new TooManyRequestsException();
                    }

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        throw new OAuthKeysRevokedException();
                    }
                }

                throw;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Retrieve user timeline data with specific parser.
        /// </summary>
        /// <typeparam name="TSchema">Strong type for results.</typeparam>
        /// <param name="screenName">User screen name.</param>
        /// <param name="maxRecords">Upper record limit.</param>
        /// <param name="parser">Specific results parser.</param>
        /// <returns>Returns strongly typed list of results.</returns>
        public async Task <IEnumerable <TSchema> > GetUserTimeLineAsync <TSchema>(string screenName, int maxRecords, Toolkit.Parsers.IParser <TSchema> parser)
            where TSchema : Toolkit.Parsers.SchemaBase
        {
            string rawResult = null;

            try
            {
                var uri = new Uri($"{BaseUrl}/statuses/user_timeline.json?screen_name={screenName}&count={maxRecords}&include_rts=1");

                TwitterOAuthRequest request = new TwitterOAuthRequest();
                rawResult = await request.ExecuteGetAsync(uri, _tokens);

                var result = parser.Parse(rawResult);
                return(result
                       .Take(maxRecords)
                       .ToList());
            }
            catch (WebException wex)
            {
                HttpWebResponse response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        throw new UserNotFoundException(screenName);
                    }

                    if ((int)response.StatusCode == 429)
                    {
                        throw new TooManyRequestsException();
                    }

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        throw new OAuthKeysRevokedException();
                    }
                }

                throw;
            }
            catch
            {
                if (!string.IsNullOrEmpty(rawResult))
                {
                    var errors = JsonConvert.DeserializeObject <TwitterErrors>(rawResult);

                    throw new TwitterException {
                              Errors = errors
                    };
                }

                throw;
            }
        }