コード例 #1
0
ファイル: UtConsole.cs プロジェクト: vtbassmatt/UntappdSharp
        public static void Main(string[] args)
        {
            string command = "", line;
            string[] tokens = null;

            string apiKey = LoadSecret("apikey"),
                   username = LoadSecret("username"),
                   password = LoadSecret("password");

            ICommand[] commandobjs = LocateCommands();
            Console.WriteLine("Found {0} commands...", commandobjs.Length);
            CommandSet = new Dictionary<string, ICommand>(commandobjs.Length);
            foreach(var commandobj in commandobjs)
            {
                CommandSet.Add(commandobj.Verb(), commandobj);
                Usage += string.Format("{0}\n", commandobj.Usage());
            }
            Console.WriteLine("...loaded {0} commands.", CommandSet.Count);

            u = new Untappd(apiKey);
            u.SetCredentials(username, password);

            Console.WriteLine("Welcome to UtConsole.");

            Prompt();
            while(!command.Equals("exit"))
            {
                line = Console.ReadLine();
                tokens  = line.Split(' ');
                if(tokens.Length > 0)
                {
                    command = tokens[0];
                } else {
                   command = "";
                }

                switch(command)
                {
                    case "exit":
                        continue;
                    case "help":
                        Console.WriteLine(string.Format("Available commands are:\n{0}",Usage));
                        Console.WriteLine(@"Additional commands are:
            help
            exit");
                        break;
                    default:
                        if(CommandSet.ContainsKey(command))
                        {
                            CommandSet[command].Run(u, tokens);
                        } else {
                            Err("Command not recognized, try 'help' for help");
                        }
                        break;
                }
                Prompt();
            }
            Console.WriteLine("Thank you for flying UtConsole, we hope to see you on a future journey.");
        }
コード例 #2
0
ファイル: UtConsole.cs プロジェクト: vtbassmatt/UntappdSharp
        private static void OldMain(string[] args)
        {
            Console.WriteLine ("Hello World!");

            string apiKey = LoadSecret("apikey"),
                   username = LoadSecret("username"),
                   password = LoadSecret("password");

            Untappd u = new Untappd(apiKey);
            u.SetCredentials(username, password);

            //UtUser vtbassmatt = u.User("vtbassmatt");
            //Console.WriteLine(vtbassmatt.Uid + " : " + vtbassmatt.UserName);

            //UtUser suewho = u.User("suewho");
            //Console.WriteLine(suewho.Uid + " : " + suewho.UserName);

            UtUser me = u.User();
            Console.WriteLine("I am " + me.UserName);

            //UtUser blah = u.User("1");
            //Console.WriteLine(blah.FirstName);

            //UtUserFeed feed = u.UserFeed();
            //Console.WriteLine("checkin " + feed.Feed[0].CheckinId + " by " + feed.Feed[0].User.Uid);

            //UtBeer beer = u.BeerInfo(1);
            //Console.WriteLine(beer.Name);

            //UtBrewery brewery = u.BreweryInfo(1);
            //Console.WriteLine(brewery.Name);
            //foreach(var tBeer in brewery.TopBeers)
            //{
            //    Console.WriteLine("\t" + tBeer.BeerName);
            //}

            //UtFriends friends = u.Friends("suewho");
            //Console.WriteLine("suewho has " + friends.ReturnedResults + " friends");

            //CheckinOptions opt = new CheckinOptions()
            //{
            //    Timezone = TimeZoneInfo.Local,
            //    BeerId = 1,
            //};
            //UtCheckin checkin = u.CheckinTest(opt);
            //Console.WriteLine(checkin.CheckinTotal.Beer);
            //Console.WriteLine(checkin.Recommendations[0].Name);

            // *******************************
            // REAL CHECKIN - EXERCISE CAUTION
            // *******************************
            //CheckinOptions opt = new CheckinOptions()
            //{
            //    Timezone = TimeZoneInfo.Local,
            //    BeerId = 32691,
            //};
            //UtCheckin checkin = u.Checkin(opt);
            //Console.WriteLine(checkin.CheckinTotal.Beer);
            //Console.WriteLine(checkin.Recommendations[0].Name);

            UtBeerSearch search = u.BeerSearch("sam adams");
            foreach(var sBeer in search.Results)
            {
                Console.WriteLine(sBeer.BeerName);
            }

            Console.Read();
        }