public void TestGetHighlights() { ReadmillClient client = new ReadmillClient(this.clientId); SortedList<decimal, Highlight> highlights = new SortedList<decimal, Highlight>(); //Get a book BookMatchOptions options = new BookMatchOptions(); options.AuthorValue = "Chad Fowler";//"Edward Rutherfurd"; options.TitleValue = "The Passionate Programmer";//"New York: The Novel"; Book book = client.Books.GetBestMatchAsync(options).Result; ReadingsQueryOptions readingOptions = new ReadingsQueryOptions(); //Get all readings List<Reading> readings = client.Books.GetBookReadingsAsync(book.Id, readingOptions).Result; foreach (Reading reading in readings) { //Foreach reading, Get all (100 latest) Highlights RangeQueryOptions highlightOptions = new RangeQueryOptions() { CountValue = 100 }; foreach (Highlight h in client.Readings.GetReadingHighlightsAsync(reading.Id, highlightOptions).Result) { if(!highlights.ContainsKey(h.Locators.Position)) highlights.Add(h.Locators.Position, h); } } //Now do something with the sorted list of highlights. E.g. Print a summary of the book }
public void TestGetBestMatch() { ReadmillClient client = new ReadmillClient(this.clientId); BookMatchOptions options = new BookMatchOptions(); options.TitleValue = "Zen and the Art of Motorcycle Maintenance"; options.AuthorValue = "Robert M. Pirsig"; Book book = client.Books.GetBestMatchAsync(options).Result; if (!book.Title.Equals(options.TitleValue) && !book.Author.Equals(options.AuthorValue)) throw new InternalTestFailureException("Returned bad match"); }
public Task<Book> GetBestMatchAsync(BookMatchOptions options, CancellationToken cancellationToken = default(CancellationToken)) { IDictionary<string, string> parameters = GetInitializedParameterCollection(); //if (options != null) //{ parameters.Add(BookMatchOptions.ISBN, options.ISBNValue); parameters.Add(BookMatchOptions.Title, options.TitleValue); parameters.Add(BookMatchOptions.Author, options.AuthorValue); //} //Remove extraneous parameters because Readmill doesn't like empty pairs IDictionary<string, string> tmpParams = new Dictionary<string, string>(); foreach (string key in parameters.Keys) { if (!string.IsNullOrEmpty(parameters[key])) tmpParams.Add(key, parameters[key]); } parameters = tmpParams; var booksUrl = booksUriTemplates[BooksUriTemplateType.BooksMatch].BindByName(this.readmillBaseUri, parameters); return GetAsync<Book>(booksUrl, cancellationToken); }
public void TestReadingActions() { ReadmillClient client = new ReadmillClient(this.clientId); BookMatchOptions options = new BookMatchOptions(); options.TitleValue = "Zen and the Art of Motorcycle Maintenance"; options.AuthorValue = "Robert M. Pirsig"; Book book = client.Books.GetBestMatchAsync(options).Result; //Create a new reading and retrieve it using the permalink string permalink = client.Books.PostBookReadingAsync(this.accessToken, book.Id, Reading.ReadingState.Open).Result; Reading r = client.Readings.GetFromPermalinkAsync<Reading>(permalink).Result; try { //Create a new Reading Session ReadingSession session = client.Readings.GetReadingSession(this.accessToken, r.Id); session.PingAsync(0.1, 52.53826, 13.41268).Wait(); Thread.Sleep(5000); session.PingAsync(0.12, 52.53826, 13.41268).Wait(); Highlight testHighlight = new Highlight() { Content = "When one person suffers from a delusion, it is called insanity. When many people suffer from a delusion it is called a Religion." }; session.PostHighlightAsync(testHighlight).Wait(); string content = @"It’s a fascinating tale of a journey, both physically and metaphysically, into the world of quality and values"; session.PostReadingCommentAsync(content).Wait(); session.Close(); } finally { //Comment this line or set a breakpoint here if you want to check the Reading on Readmill client.Readings.DeleteReadingAsync(this.accessToken, r.Id); } }