Ejemplo n.º 1
0
        /// <summary>
        /// Returns the friend update feed for the logged in user
        /// </summary>
        /// <param name="type"></param>
        /// <param name="filter"></param>
        /// <param name="maxUpdates"></param>
        public async Task <Updates> GetFriendUpdates(string type, string filter, string maxUpdates)
        {
            var response = await ApiClient.Instance.ExecuteForProtectedResourceAsync(Urls.FriendUpdates, Method.GET, MyShelfSettings.Instance.ConsumerKey, MyShelfSettings.Instance.ConsumerSecret, MyShelfSettings.Instance.OAuthAccessToken, MyShelfSettings.Instance.OAuthAccessTokenSecret, null, CacheMode.UpdateAsyncIfExpired, TimeSpan.FromMinutes(10));

            GoodreadsResponse result = GoodReadsSerializer.DeserializeResponse(response.Content);

            return(result.Updates);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a user's friends
        /// </summary>
        /// <param name="page"></param>
        /// <param name="sort"></param>
        /// <returns></returns>
        public async Task <Friends> GetFriends(string page = null, string sort = null)
        {
            var response = await ApiClient.Instance.ExecuteForProtectedResourceAsync(string.Format(Urls.FriendList, MyShelfSettings.Instance.GoodreadsUserID), Method.GET, MyShelfSettings.Instance.ConsumerKey, MyShelfSettings.Instance.ConsumerSecret, MyShelfSettings.Instance.OAuthAccessToken, MyShelfSettings.Instance.OAuthAccessTokenSecret, null, CacheMode.UpdateAsyncIfExpired, TimeSpan.FromDays(1));

            GoodreadsResponse result = GoodReadsSerializer.DeserializeResponse(response.Content);

            return(result.Friends);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the friend update feed for the logged in user
        /// </summary>
        /// <param name="type"></param>
        /// <param name="filter"></param>
        /// <param name="maxUpdates"></param>
        public async Task <Updates> GetFriendUpdates(string type, string filter, string maxUpdates)
        {
            string url = Urls.UpdatesFriends;// BASEURL + UPDATES + FRIENDS;// +type + filter + "&max_updates=" + maxUpdates + "&access_token=" + OAuthAccessToken;

            client.Authenticator = OAuth1Authenticator.ForProtectedResource(API_KEY, OAUTH_SECRET, UserSettings.Settings.OAuthAccessToken, UserSettings.Settings.OAuthAccessTokenSecret);

            await apiSemaphore.WaitAsync();

            var request  = new RestRequest("updates/friends.xml", Method.GET);
            var response = await client.ExecuteAsync(request);

            ApiCooldown();

            GoodreadsResponse result = DeserializeResponse(response.Content.ToString());

            return(result.Updates);
        }
Ejemplo n.º 4
0
            public static async Task <GoodreadsResponse> GetBookInfo(string title)
            {
                string uri = $"https://www.goodreads.com/search.xml?key=uQuCCD5GPNdmfPp7bdXroA&q={title}";
                var    GoodreadsResponse = new GoodreadsResponse();

                HttpWebRequest request  = WebRequest.Create(uri) as HttpWebRequest;
                XmlSerializer  s        = new XmlSerializer(typeof(GoodreadsResponse), new XmlRootAttribute("GoodreadsResponse"));
                WebResponse    response = request.GetResponse();

                using (var reader = new StringReader(uri))
                {
                    GoodreadsResponse = (GoodreadsResponse)s.Deserialize(response.GetResponseStream());
                }

                GoodreadsResponse.search.results[0].best_book.title = GoodreadsResponse.search.results[0].best_book.title ?? "FAIL";

                return(GoodreadsResponse);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Deserializes a GoodReads response XML
        /// </summary>
        /// <param name="xml">xml data</param>
        /// <returns>GoodreadsResponse object</returns>
        internal static GoodreadsResponse DeserializeResponse(string xml)
        {
            GoodreadsResponse response = null;

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                try
                {
                    var serializer = new XmlSerializer(typeof(GoodreadsResponse));

                    response = (GoodreadsResponse)serializer.Deserialize(stream);
                }
                catch (Exception)
                {
                }
            }
            return(response);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deserializes the response XML
        /// </summary>
        /// <param name="results"></param>
        /// <returns>GoodreadsResponse object</returns>
        private static GoodreadsResponse DeserializeResponse(string results)
        {
            GoodreadsResponse response = null;

            using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(results)))
            {
                try
                {
                    var serializer = new XmlSerializer(typeof(GoodreadsResponse));

                    response = (GoodreadsResponse)serializer.Deserialize(stream);
                }
                catch (Exception)
                {
                }
            }
            return(response);
        }
Ejemplo n.º 7
0
        private void GetSearchResults(string query)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(GoodreadsResponse));

            using (WebClient webClient = new WebClient())
            {
                string xml = Encoding.Default.GetString(webClient.DownloadData($"https://www.goodreads.com/search/index.xml?q={query}&key={Constants.GOODREADS_KEY}"));
                using (Stream reader = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
                {
                    GoodreadsResponse response = serializer.Deserialize(reader) as GoodreadsResponse;

                    Books.Clear();
                    foreach (var book in response.Search.Results.Work)
                    {
                        book.Best_book.Author_Name = book.Best_book.Author.Name;
                        Books.Add(book.Best_book);
                    }
                }
            }
        }
        public async Task <Book> GetBook(int id)
        {
            GoodreadsResponse result = await GetResourceAsync($"book/show/{id}");

            return(result.Book);
        }
        public async Task <Author> GetAuthor(int id)
        {
            GoodreadsResponse result = await GetResourceAsync($"author/show/{id}");

            return(result.Author);
        }