Exemplo n.º 1
0
        public TwitterDevApiSettings GetTwitterDevApiSettings()
        {
            var expectedDevSettingPath = TwittootLocation.GetUserFilePath(DevSettingsFileName);

            if (File.Exists(expectedDevSettingPath))
            {
                var fileContent = File.ReadAllText(expectedDevSettingPath);
                var devSettings = JsonConvert.DeserializeObject <TwitterDevApiSettings>(fileContent);
                if (devSettings.ConsumerKey == _defaultDevSettings.ConsumerKey && devSettings.ConsumerSecret == _defaultDevSettings.ConsumerSecret)
                {
                    throw new Exception("Default Settings.Dev.json found, please provide correct info.");
                }
                return(devSettings);
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("Provide Twitter API Consumer Key");
                var consumerKey = Console.ReadLine();

                Console.WriteLine();
                Console.WriteLine("Provide Twitter API Consumer Secret");
                var consumerSecret = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(consumerKey) || string.IsNullOrWhiteSpace(consumerSecret))
                {
                    var json = JsonConvert.SerializeObject(_defaultDevSettings);
                    File.WriteAllText(expectedDevSettingPath, json);
                    throw new Exception("You didn't provide API info, we created for you a default Settings.Dev.json, please complete it accordingly.");
                }
                else
                {
                    var settings = new TwitterDevApiSettings
                    {
                        ConsumerKey    = consumerKey,
                        ConsumerSecret = consumerSecret
                    };
                    var json = JsonConvert.SerializeObject(settings);
                    File.WriteAllText(expectedDevSettingPath, json);
                    return(settings);
                }
            }
        }
Exemplo n.º 2
0
 public PinAuthenticator(TwitterDevApiSettings twitterDevApiSettings)
 {
     _twitterDevApiSettings = twitterDevApiSettings;
 }