Exemple #1
0
        public static RootInfo ParseJson(string jsonString)
        {
            Hyena.Json.Deserializer deserializer =
                new Hyena.Json.Deserializer(jsonString);
            object obj = deserializer.Deserialize();

            Hyena.Json.JsonObject jsonObj =
                obj as Hyena.Json.JsonObject;
            if (jsonObj == null)
            {
                throw new ArgumentException("jsonString does not contain a valid RootInfo representation");
            }

            // TODO: Checks
            RootInfo root = new RootInfo();

            root.ApiVersion = (string)jsonObj ["api-version"];

            object val;

            if (jsonObj.TryGetValue("user-ref", out val))
            {
                Hyena.Json.JsonObject userRefJsonObj = (Hyena.Json.JsonObject)val;

                root.User =
                    ResourceReference.ParseJson(userRefJsonObj);
            }

            root.AuthorizeUrl    = (string)jsonObj ["oauth_authorize_url"];
            root.AccessTokenUrl  = (string)jsonObj ["oauth_access_token_url"];
            root.RequestTokenUrl = (string)jsonObj ["oauth_request_token_url"];

            return(root);
        }
Exemple #2
0
		public static RootInfo ParseJson (string jsonString)
		{
			Hyena.Json.Deserializer deserializer =
				new Hyena.Json.Deserializer (jsonString);
			object obj = deserializer.Deserialize ();

			Hyena.Json.JsonObject jsonObj =
				obj as Hyena.Json.JsonObject;
			if (jsonObj == null)
				throw new ArgumentException ("jsonString does not contain a valid RootInfo representation");

			// TODO: Checks
			RootInfo root = new RootInfo ();
			root.ApiVersion = (string) jsonObj ["api-version"];

			object val;
			if (jsonObj.TryGetValue ("user-ref", out val)) {
				Hyena.Json.JsonObject userRefJsonObj = (Hyena.Json.JsonObject) val;

				root.User =
					ResourceReference.ParseJson (userRefJsonObj);
			}

			root.AuthorizeUrl =  (string) jsonObj ["oauth_authorize_url"];
			root.AccessTokenUrl = (string) jsonObj ["oauth_access_token_url"];
			root.RequestTokenUrl = (string) jsonObj ["oauth_request_token_url"];

			return root;
		}
Exemple #3
0
        public static RootInfo GetRoot(string rootUri, IWebConnection connection)
        {
            // TODO: Error-handling in GET and Deserialize
            string   jsonString = connection.Get(rootUri, null);
            RootInfo root       = ParseJson(jsonString);

            return(root);
        }
		public bool BeginSyncTransaction ()
		{
			// TODO: Check connection and auth (is getting root/user resources a sufficient check?)
			root = RootInfo.GetRoot (rootUri, connection);
			user = UserInfo.GetUser (root.User.ApiRef, connection);
			if (user.LatestSyncRevision.HasValue)
				LatestRevision = user.LatestSyncRevision.Value;
			else
				VerifyLatestSyncRevision (user.LatestSyncRevision);

			if (string.IsNullOrEmpty (user.CurrentSyncGuid))
				throw new TomboySyncException ("No sync GUID for user provided in server response");
			
			pendingCommits = new List<NoteInfo> ();
			return true;
		}
		public bool UpdatesAvailableSince (int revision)
		{
			root = RootInfo.GetRoot (rootUri, connection);
			user = UserInfo.GetUser (root.User.ApiRef, connection);
			return user.LatestSyncRevision.HasValue &&
				user.LatestSyncRevision.Value > revision;
		}