/// <summary>
        /// Returns the note with the given ID.
        /// </summary>
        /// <param name="noteID">the ID of the note</param>
        /// <returns>the note if found; otherwise a NotFoundExeption is thrown</returns>
        public static Note GetNote(string noteID)
        {
            if (noteID == null || noteID == "")
            {
                throw new ArgumentNullException();
            }

            try
            {
                string   jsonString = WebClient.DownloadString("notes/" + noteID);
                JsonNote jsonNote   = JsonConvert.DeserializeObject <JsonNote>(jsonString);
                return(new Note(jsonNote));
            }
            catch (WebException e)
            {
                switch (e.HResult)
                {
                // Note not found
                case -2146233079:
                    throw new NotFoundException("Note");

                // Unknown exception
                default:
                    throw;
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Constructs a Note from the provided Json object.
 /// </summary>
 /// <param name="jsonNote">Json object containing information related to a Note</param>
 public Note(JsonNote jsonNote)
 {
     ID         = jsonNote.ID;
     UserID     = jsonNote.UserID;
     NotebookID = jsonNote.NotebookID;
     Text       = jsonNote.Text;
     Created    = jsonNote.Created;
     Modified   = jsonNote.Modified;
 }
Beispiel #3
0
        static void Post(string Note)
        {
            JsonNote NoteObj = new JsonNote();

            NoteObj.NoteText      = Note;
            NoteObj.GameName      = Application.productName;
            NoteObj.CampaignName  = CampaignManager.campaign.cname;
            NoteObj.LevelName     = LevelManager.only.gameObject.scene.name;
            NoteObj.CharacterName = DefaultCharacterName;
            string        outstr  = JsonUtility.ToJson(NoteObj);
            HttpClient    client  = new HttpClient();
            StringContent content = new StringContent(outstr);

            client.Post(new System.Uri(Site), content, HttpCompletionOption.AllResponseContent, (r) => {
                Debug.Log(r.ReadAsString());
            });
        }
        /// <summary>
        /// Creates a note.
        /// </summary>
        /// <param name="userID">the ID of the user that the note belongs to</param>
        /// <param name="notebookID">the ID of the notebook that the note belongs to</param>
        /// <param name="noteText">the text of the note</param>
        /// <returns>the created note</returns>
        public static Note CreateNote(string userID, string notebookID, string noteText)
        {
            if (userID == null || notebookID == null || noteText == null || userID == "" || notebookID == "" || noteText == "")
            {
                throw new ArgumentNullException();
            }

            User     user     = GetUser(userID);
            Notebook notebook = GetNotebook(notebookID);

            string path   = "notes";
            string json   = GenerateCreateNoteJson(userID, notebookID, noteText);
            string result = WebClient.UploadString(path, json);

            JsonNote jsonNote = JsonConvert.DeserializeObject <JsonNote>(result);

            return(new Note(jsonNote));
        }