/// <summary> /// Returns the notebook with the given ID. /// </summary> /// <param name="notebookID">the ID of the notebook</param> /// <returns>the notebook if found; otherwise a NotFoundExeption is thrown</returns> public static Notebook GetNotebook(string notebookID) { if (notebookID == null || notebookID == "") { throw new ArgumentNullException(); } try { string jsonString = WebClient.DownloadString("notebooks/" + notebookID); JsonNotebook jsonNotebook = JsonConvert.DeserializeObject <JsonNotebook>(jsonString); return(new Notebook(jsonNotebook)); } catch (WebException e) { switch (e.HResult) { // Notebook not found case -2146233079: throw new NotFoundException("Notebook"); // Unknown exception default: throw; } } }
/// <summary> /// Creates a notebook using the given information. /// </summary> /// <param name="userID">the ID of the user that the notebook belongs to</param> /// <param name="title">the title of the notebook</param> /// <param name="author">the author of the notebook</param> /// <param name="isbn">the isbn of the notebook</param> /// <param name="publisher">the publisher of the notebook</param> /// <param name="publishDate">the date that the notebook was published</param> /// <param name="coverURL">a URL pointing to an image of the cover of the notebook</param> /// <returns>the created notebook</returns> public static Notebook CreateNotebook(string userID, string title, string author = "", string isbn = "", string publisher = "", string publishDate = "", string coverURL = "") { if (userID == null || title == null || userID == "" || title == "") { throw new ArgumentNullException(); } author = author ?? ""; publisher = publisher ?? ""; publishDate = publishDate ?? ""; coverURL = coverURL ?? ""; User user = GetUser(userID); if (user == null) { throw new NotFoundException("User"); } string path = "notebooks"; string json = GenerateCreateNotebookJson(userID, title, author, isbn, publisher, publishDate, coverURL); string result = WebClient.UploadString(path, json); JsonNotebook jsonNotebook = JsonConvert.DeserializeObject <JsonNotebook>(result); return(new Notebook(jsonNotebook)); }
/// <summary> /// Constructs a Notebook from the provided Json object. /// </summary> /// <param name="jsonNotebook">Json object containing information related to a Notebook</param> public Notebook(JsonNotebook jsonNotebook) { ID = jsonNotebook.ID; Title = jsonNotebook.Title; Author = jsonNotebook.Author; Isbn = jsonNotebook.ISBN; Publisher = jsonNotebook.Publisher; PublishDate = jsonNotebook.PublishDate; CoverURL = jsonNotebook.CoverURL; UserID = jsonNotebook.UserID; Modified = jsonNotebook.Modified; Created = jsonNotebook.Created; Notes = new List <Note>(); }