예제 #1
0
        public async Task Menciones()
        {
            try
            {
                List <Sebagomez.TwitterLib.Entities.Status> result = await Mentions.GetMentions(new MentionsOptions { User = m_user });

                Assert.True(result.Count > 0, "Ningún tweet!");
            }
            catch (Exception ex)
            {
                Assert.True(false, Util.ExceptionMessage(ex));
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                //Debug.Assert(false, "Attach VS here!");

                Console.OutputEncoding = new UTF8Encoding();

                PrintHeader();

                BaseAPI.SetMessageAction(message => Console.WriteLine(message));

                if (args.Length == 0)
                {
                    PrintTwits(Timeline.GetTimeline().Result);
                    return;
                }


                if (args[0].StartsWith("/"))
                {
                    string flag = args[0].ToLower().Trim();
                    switch (flag)
                    {
                    case CLEAR:
                        AuthenticatedUser.ClearCredentials();
                        Console.WriteLine("User credentials cleared!");
                        return;

                    case HELP:
                        ShowUsage();
                        return;

                    case TIME_LINE:
                        PrintTwits(Timeline.GetTimeline().Result);
                        return;

                    case MENTIONS:
                        PrintTwits(Mentions.GetMentions().Result);
                        return;

                    case SEARCH:
                        SearchOptions options = new SearchOptions {
                            Query = string.Join(" ", args).Substring(2), User = AuthenticatedUser.LoadCredentials()
                        };
                        PrintTwits(Search.SearchTweets(options).Result);
                        return;

                    case LIKES:
                        PrintTwits(Likes.GetUserLikes(new LikesOptions()).Result);
                        return;

                    case USER:
                        if (args.Length != 2)
                        {
                            throw new ArgumentNullException("screenname", "The user' screen name must be provided");
                        }
                        UserTimelineOptions usrOptions = new UserTimelineOptions {
                            ScreenName = args[1]
                        };
                        PrintTwits(UserTimeline.GetUserTimeline(usrOptions).Result);
                        return;

                    case STREAMING:
                        if (args.Length != 2)
                        {
                            throw new ArgumentNullException("streaming", "The track must be provided");
                        }
                        StreammingFilterOptions streamingOptions = new StreammingFilterOptions {
                            Track = args[1]
                        };
                        Console.WriteLine("Starting live streaming, press ctrl+c to quit");
                        foreach (Status s in StreamingFilter.GetStreamingTimeline(streamingOptions))
                        {
                            PrintTwit(s);
                        }
                        return;

                    default:
                        Console.WriteLine($"Invalid flag: {flag}");
                        ShowUsage();
                        return;
                    }
                }

                if (args[0].StartsWith("\\") || args[0].Length == 1)
                {
                    Console.WriteLine("Really? do you really wanna twit that?. [T]wit, or [N]o sorry, I messed up...");
                    ConsoleKeyInfo input = Console.ReadKey();
                    while (input.Key != ConsoleKey.T && input.Key != ConsoleKey.N)
                    {
                        Console.WriteLine();
                        Console.WriteLine("[T]wit, or [N]o sorry, I messed up...");
                        input = Console.ReadKey();
                    }
                    Console.WriteLine();

                    if (input.Key == ConsoleKey.N)
                    {
                        Console.WriteLine("That's what I thought! ;)");
                        return;
                    }
                }

                string response = Update.UpdateStatus(string.Join(" ", args)).Result;

                if (response != "OK")
                {
                    Console.WriteLine($"Response was not OK: {response}");
                }
            }
            catch (WebException wex)
            {
                Console.WriteLine(wex.Message);

                HttpWebResponse res = (HttpWebResponse)wex.Response;
                if (res != null)
                {
                    UpdateError errors = ShelltwitLib.Helpers.Util.Deserialize <UpdateError>(res.GetResponseStream());
                    errors.errors.ForEach(e => Console.WriteLine(e.ToString()));
                }
            }
            catch (Exception ex)
            {
                PrintException(ex);
            }
            finally
            {
#if DEBUG
                if (Debugger.IsAttached)
                {
                    Console.WriteLine("Press <enter> to exit...");
                    Console.ReadLine();
                }
#endif
            }

            Environment.Exit(0);
        }