Esempio n. 1
0
        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 BookDetailsViewModel(Book selectedBook)
        {
            this.client = new ReadmillClient(AppContext.ClientId);
            this.SelectedBook = selectedBook;

            //find out if a reading exists for this book
        }
Esempio n. 3
0
        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");
        }
Esempio n. 4
0
        public void TestGetBooks()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            BooksQueryOptions options = new BooksQueryOptions();
            options.CountValue = 50;

            List<Book> books = client.Books.GetBooksAsync(options).Result;

            foreach (Book book in books)
                Console.WriteLine(book.Title + " by " + book.Author);

            if (books.Count != 50)
                throw new InternalTestFailureException("Expected 5 Books. Got: " + books.Count);
        }
        public MyReadingsPage()
        {
            InitializeComponent();

            TaskScheduler uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            IDictionary<string, Book> readableBooks = new Dictionary<string, Book>();

            ReadmillClient client = new ReadmillClient(AppContext.ClientId);

            Task<User> task = client.Users.GetOwnerAsync(AppContext.AccessToken.Token);
            task.ContinueWith(getMe =>
                {
                    client.Users.GetUserReadings(getMe.Result.Id,
                                                    accessToken: AppContext.AccessToken.Token).ContinueWith(
                                                    getReadings =>
                                                    {
                                                        //myReadingsList.Items.RemoveAt(0);
                                                        //myReadingsList.ItemsSource = getReadings.Result;

                                                    }, uiTaskScheduler);

                });
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (viewModelsInvalidated)
            {
                client = new ReadmillClient(AppContext.ClientId);

                if (State.ContainsKey("CollectedHighlights"))
                    collectedHighlights = State["CollectedHighlights"] as List<Highlight>;
                else if (PhoneApplicationService.Current.State.ContainsKey("CollectedHighlights"))
                    collectedHighlights = PhoneApplicationService.Current.State["CollectedHighlights"] as List<Highlight>;

                if (collectedHighlights == null)
                    throw new InvalidOperationException(AppStrings.HighlightsCollectionNull);

                collectedHighlightsList.ItemsSource = collectedHighlights;

                viewModelsInvalidated = false;
            }

            cancel = new CancellationTokenSource();
        }
Esempio n. 7
0
        private AuthenticatedUser()
        {
            client = new ReadmillClient(AppContext.ClientId);

            //collectedHighlights = new Dictionary<string, Highlight>();
        }
 private void Initialize()
 {
     client = new ReadmillClient(AppContext.ClientId);
     readableBooks = new Dictionary<string, Book>();
     ListState = State.Unloaded;
 }
        private void Initialize()
        {
            client = new ReadmillClient(AppContext.ClientId);

            //CollectedBooks = new List<Book>();
            //CollectedHighlights = new List<Highlight>();

            //Is this the only place a refresh is needed? Use INotification
            BooksCollectionRefreshNeeded = true;
            HighlightsCollectionRefreshNeeded = true;
        }
 public BookHighlightsViewModel(Book selectedBook)
     : base(selectedBook)
 {
     client = new ReadmillClient(AppContext.ClientId);
 }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        public void TestRangeQuery()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            ReadingsQueryOptions options = new ReadingsQueryOptions()
                                           {
                                               FromValue = XmlConvert.ToString(new DateTime(2012, 7, 1)),
                                               ToValue = XmlConvert.ToString(new DateTime(2012, 7, 31)),
                                               OrderByValue = "created_at"
                                           };

            List<Reading> jul2012Readings = client.Readings.GetReadingsAsync(options).Result;
            foreach (Reading reading in jul2012Readings)
            {
                //There shouldn't be any reading not created in July 2012
                Assert.IsTrue(DateTime.Parse(reading.CreatedAt) < new DateTime(2012, 8, 7));
                Assert.IsTrue(DateTime.Parse(reading.CreatedAt) > new DateTime(2012, 6, 30));
            }
        }
Esempio n. 13
0
        public void TestGetUserReadings()
        {
            //Modify this variable according to your own data before running
            int expectedReadingCount = 6;

            ReadmillClient client = new ReadmillClient(this.clientId);

            User me = client.Users.GetOwnerAsync(this.accessToken).Result;

            client.Users.GetUserReadings(me.Id, accessToken:accessToken).ContinueWith(
                (getReadingsTask) =>
                {
                    //Validations
                    if (getReadingsTask.Result.Count != expectedReadingCount)
                        throw new InternalTestFailureException("Expected" + expectedReadingCount + "readings. Retrieved: " + getReadingsTask.Result.Count);

                    //Add more / stronger validations
                });
        }
Esempio n. 14
0
        public void TestGetReadings()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            ReadingsQueryOptions options = new ReadingsQueryOptions() { CountValue = 30 };

            List<Reading> readings = client.Readings.GetReadingsAsync(options).Result;

            foreach (Reading r in readings)
            {
                //Periods
                List<Period> sessions = client.Readings.GetReadingPeriodsAsync(r.Id).Result;
                Console.WriteLine("Reading {0} has {1} sessions.", r.Id, sessions.Count);

                //Locaions
                List<Location> locations = client.Readings.GetReadingLocationsAsync(r.Id).Result;
                Console.WriteLine("Reading {0} has {1} locations.", r.Id, locations.Count);
            }

            if (readings.Count != 30)
                throw new InternalTestFailureException("Expected 30 Readings. Got: " + readings.Count);
        }
Esempio n. 15
0
        public void TestGetOwner()
        {
            //Replace this with your Full Name
            string myFullName = "Tushar Malhotra";

            ReadmillClient client = new ReadmillClient(this.clientId);

            client.Users.GetOwnerAsync(this.accessToken).ContinueWith(
                (getUserTask) =>
                {
                    if (!(getUserTask.Result.FullName == myFullName))
                        throw new InternalTestFailureException("Expected fullName does not match Retrieved: " + getUserTask.Result.FullName);

                    //ToDo: Add more / stronger validations
                });
        }