예제 #1
0
        public void GetListRepository_ApiIsInitialized_CreatesListRepository()
        {
            Rtm.Init("test", "test");
            var actual = Rtm.GetListRepository(new AuthenticationToken());

            Assert.IsInstanceOf <ListRepository>(actual);
        }
        private static async Task AuthenticateNewDesktopUser()
        {
            // Get an authentication URL for the user.  This example will request authorization for READ permissions.
            try
            {
                var desktopAuthenticator = Rtm.GetAuthFactory().CreateDesktopAuthenticator();
                var authUrl = await desktopAuthenticator.GetAuthenticationUrlAsync(PermissionLevel.Read).ConfigureAwait(false);

                // Instruct the user to navigate to the URL and authorize your application.  They can continue using
                // your application after authentication in the web browser is complete.
                Console.WriteLine($"Step 1:  Please navigate to the following URL using a web browser: {authUrl}");
                Console.WriteLine("Step 2:  Follow the instructions from Remember the Milk to authorize this application to access your RTM account.");
                Console.WriteLine("Step 3: Press [Enter] when finished");
                Console.ReadLine();

                var rtmUser = await desktopAuthenticator.GetAutheticatedUserAsync().ConfigureAwait(false);

                // Save the user data to a file or database.
                var userJson = rtmUser.ToJson();
                File.WriteAllText("myRtmUser.json", userJson);
            }
            catch (RtmException ex)
            {
                // Read the exception details.  There may be an issue with your API Key or Shared Secret, or the user may not
                // have followed the instructions for authentication.
                Console.WriteLine($"RTM Error Code: {ex.ErrorCode} -- RTM Error Message: {ex.Message}");
            }
        }
예제 #3
0
        public void FinishedAuth()
        {
            rtmAuth = rtm.AuthGetToken(frob);
            if (rtmAuth != null)
            {
                Preferences prefs = Application.Preferences;
                prefs.Set(Preferences.AuthTokenKey, rtmAuth.Token);
                if (rtmAuth.User != null)
                {
                    prefs.Set(Preferences.UserNameKey, rtmAuth.User.Username);
                    prefs.Set(Preferences.UserIdKey, rtmAuth.User.UserId);
                }
            }

            string authToken =
                Application.Preferences.Get(Preferences.AuthTokenKey);

            if (authToken != null)
            {
                Logger.Debug("Found AuthToken, checking credentials...");
                try {
                    rtm      = new Rtm(apiKey, sharedSecret, authToken);
                    rtmAuth  = rtm.AuthCheckToken(authToken);
                    timeline = rtm.TimelineCreate();
                    Logger.Debug("RTM Auth Token is valid!");
                    Logger.Debug("Setting configured status to true");
                    configured = true;
                    Refresh();
                } catch (Exception e) {
                    rtm     = null;
                    rtmAuth = null;
                    Logger.Error("Exception authenticating, reverting" + e.Message);
                }
            }
        }
예제 #4
0
        public string GetAuthUrl()
        {
            frob = Rtm.AuthGetFrob();
            string url = Rtm.AuthCalcUrl(frob, RtmNet.AuthLevel.Delete);

            return(url);
        }
        private static async Task CheckAuthenticationToken()
        {
            // Load a user from JSON
            var userJson = File.ReadAllText("myRtmUser.json");
            var user     = Rtm.GetUserFactory().LoadFromJson(userJson);

            var tokenVerifier = Rtm.GetAuthFactory().CreateTokenVerifier();

            try
            {
                if (await tokenVerifier.VerifyAsync(user.Token).ConfigureAwait(false))
                {
                    Console.WriteLine("Token is still valid.");
                }
                else
                {
                    // Token is expired or otherwise invalid.  you'll need to create a new authorization URL
                    // and instruct the user to reauthorize your app.
                    Console.WriteLine("Token is expired or invalid.");
                }
            }
            catch (RtmException ex)
            {
                // Some other API error was returned.
                Console.WriteLine($"RTM Error Code: {ex.ErrorCode}");
                Console.WriteLine($"RTM Error Message: {ex.Message}");
            }
        }
예제 #6
0
        public void GetAuthFactory_ApiIsInitialized_CreatesAuthFactory()
        {
            Rtm.Init("test", "test");
            var actual = Rtm.GetAuthFactory();

            Assert.IsInstanceOf <AuthFactory>(actual);
        }
예제 #7
0
        static RTM()
        {
            rtm           = new Rtm(ApiKey, SharedSecret);
            tasks         = new List <Item> ();
            lists         = new List <Item> ();
            tags          = new List <Item> ();
            locations     = new List <Item> ();
            priorities    = new List <Item> ();
            notes         = new List <Item> ();
            list_lock     = new object();
            task_lock     = new object();
            location_lock = new object();
            note_lock     = new object();

            ResetLastSync();
            ResetFilter();

            RTMPreferences.AccountChanged             += HandleAccountChanged;
            RTMPreferences.FilterChanged              += HandleFilterChanged;
            RTMPreferences.OverdueIntervalChanged     += HandleOverdueIntervalChanged;
            RTMPreferences.OverdueNotificationChanged += HandleOverdueNotificationChanged;

            Services.Core.UniverseInitialized += HandleInitialized;

            TryConnect();
        }
예제 #8
0
        private static ILocationRepository InitLocationRepository()
        {
            // Load a user from JSON
            var userJson = File.ReadAllText("myRtmUser.json");
            var user     = Rtm.GetUserFactory().LoadFromJson(userJson);

            return(Rtm.GetLocationRepository(user.Token));
        }
예제 #9
0
        private static ITaskRepository GetTaskRepository()
        {
            // Load a user from JSON
            var userJson = File.ReadAllText("myRtmUser.json");
            var user = Rtm.GetUserFactory().LoadFromJson(userJson);

            return Rtm.GetTaskRepository(user.Token);
        }
예제 #10
0
        private static async Task Run()
        {
            // Initialize the API with your personal API Key and Shared Secret issued by Remember the Milk.  Do this once per runtime session.
            var configs = LoadApiConfigs();

            Rtm.Init(configs.ApiKey, configs.SharedSecret);

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("---------------------------------------------------------");
                Console.WriteLine("Main Menu - Select an option:");
                Console.WriteLine();
                Console.WriteLine("   1) Authentication Examples");
                Console.WriteLine("   2) List Examples");
                Console.WriteLine("   3) Task Examples");
                Console.WriteLine("   4) Location Examples");
                Console.WriteLine();
                Console.WriteLine("   0) Exit");
                Console.WriteLine();
                Console.WriteLine("---------------------------------------------------------");
                Console.WriteLine();
                Console.Write("--> ");
                var input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    await AuthenticationExamples.Run().ConfigureAwait(false);

                    break;

                case "2":
                    await ListExamples.Run().ConfigureAwait(false);

                    break;

                case "3":
                    await TasksExamples.Run().ConfigureAwait(false);

                    break;

                case "4":
                    await LocationExamples.Run().ConfigureAwait(false);

                    break;

                case "0":
                    return;

                default:
                    Console.WriteLine("Invalid Entry");
                    break;
                }
            }
        }
예제 #11
0
        public void Init_ValidArgs_InitializesApi()
        {
            const string apiKey       = "My API Key";
            const string sharedSecret = "My Shared Secret";

            Rtm.Init(apiKey, sharedSecret);

            Assert.AreEqual(apiKey, Rtm.ApiKey);
            Assert.AreEqual(sharedSecret, Rtm.SharedSecret);
        }
예제 #12
0
        public void Initialize()
        {
            // *************************************
            // AUTHENTICATION to Remember The Milk
            // *************************************
            string authToken =
                Application.Preferences.Get(Preferences.AuthTokenKey);

            if (authToken != null)
            {
                Logger.Debug("Found AuthToken, checking credentials...");
                try {
                    rtm      = new Rtm(apiKey, sharedSecret, authToken);
                    rtmAuth  = rtm.AuthCheckToken(authToken);
                    timeline = rtm.TimelineCreate();
                    Logger.Debug("RTM Auth Token is valid!");
                    Logger.Debug("Setting configured status to true");
                    configured = true;
                } catch (RtmNet.RtmApiException e) {
                    Application.Preferences.Set(Preferences.AuthTokenKey, null);
                    Application.Preferences.Set(Preferences.UserIdKey, null);
                    Application.Preferences.Set(Preferences.UserNameKey, null);
                    rtm     = null;
                    rtmAuth = null;
                    Logger.Error("Exception authenticating, reverting" + e.Message);
                }
                catch (RtmNet.RtmWebException e) {
                    rtm     = null;
                    rtmAuth = null;
                    Logger.Error("Not connected to RTM, maybe proxy: #{0}", e.Message);
                }
                catch (System.Net.WebException e) {
                    rtm     = null;
                    rtmAuth = null;
                    Logger.Error("Problem connecting to internet: #{0}", e.Message);
                }
            }

            if (rtm == null)
            {
                rtm = new Rtm(apiKey, sharedSecret);
            }

            StartThread();
        }
예제 #13
0
        public IEnumerable <ITaskListCore> GetAll()
        {
            yield return(allList);

            var lists = Rtm.ListsGetList();

            foreach (var list in lists.listCollection)
            {
                ITaskListCore taskList;
                if (list.Smart == 1)
                {
                    taskList = Factory.CreateSmartTaskList(list.ID,
                                                           list.Name);
                }
                else
                {
                    taskList = Factory.CreateTaskList(list.ID, list.Name);
                }
                yield return(taskList);
            }
        }
예제 #14
0
        public void FinishedAuth()
        {
            rtmAuth = Rtm.AuthGetToken(frob);
            if (rtmAuth != null)
            {
                preferences.Set(PreferencesKeys.AuthTokenKey, rtmAuth.Token);
                if (rtmAuth.User != null)
                {
                    preferences.Set(PreferencesKeys.UserNameKey,
                                    rtmAuth.User.Username);
                    preferences.Set(PreferencesKeys.UserIdKey,
                                    rtmAuth.User.UserId);
                }
            }

            var authToken = preferences.Get(PreferencesKeys.AuthTokenKey);

            if (authToken != null)
            {
                Logger.Debug("Found AuthToken, checking credentials...");
                try {
                    Rtm      = new RtmNet.Rtm(ApiKey, SharedSecret, authToken);
                    rtmAuth  = Rtm.AuthCheckToken(authToken);
                    Timeline = Rtm.TimelineCreate();
                    Logger.Debug("RTM Auth Token is valid!");
                    Logger.Debug("Setting configured status to true");
                    IsConfigured = true;
                    FinishInitialization();
                } catch (Exception e) {
                    Rtm     = null;
                    rtmAuth = null;
                    Logger.Error("Exception authenticating, reverting"
                                 + e.Message);
                }
            }
        }
예제 #15
0
 public void GetAuthFactory_ApiNotInitialized_ThrowsInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(() => Rtm.GetAuthFactory());
 }
예제 #16
0
 public abstract void Execute(Rtm rtm);
예제 #17
0
 public RequestManager(Rtm rtm)
 {
     mRtm = rtm;
 }
예제 #18
0
 public void GetListRepostiory_ApiNotInitialized_ThrowsInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(() => Rtm.GetListRepository(new AuthenticationToken()));
 }
예제 #19
0
 public void GetListRepository_NullToken_ThrowsArgumentNullException()
 {
     Rtm.Init("test", "test");
     Assert.Throws <ArgumentNullException>(() => Rtm.GetListRepository(null));
 }
예제 #20
0
 public void Init_NullValues_ThrowsArgumentNullException(string apiKey, string sharedSecret)
 {
     Assert.Throws <ArgumentNullException>(() => Rtm.Init(apiKey, sharedSecret));
 }
예제 #21
0
        public void GetUserFactory_CreatesUserFactory()
        {
            var actual = Rtm.GetUserFactory();

            Assert.IsInstanceOf <UserFactory>(actual);
        }