/// <summary> /// Returns the logged in User /// </summary> /// <returns>User</returns> public async Task <User> GetUserID(bool refresh = false) { if (_currentUser == null || refresh) { var response = await ApiClient.Instance.ExecuteForProtectedResourceAsync(Urls.AuthUser, Method.GET, MyShelfSettings.Instance.ConsumerKey, MyShelfSettings.Instance.ConsumerSecret, MyShelfSettings.Instance.OAuthAccessToken, MyShelfSettings.Instance.OAuthAccessTokenSecret, null, CacheMode.UpdateAsyncIfExpired, TimeSpan.FromDays(30)); var result = GoodReadsSerializer.DeserializeResponse(response.Content.ToString()); _currentUser = result.User; MyShelfSettings.Instance.GoodreadsUserID = result.User.Id; MyShelfSettings.Instance.GoodreadsUsername = result.User.UserName; MyShelfSettings.Instance.GoodreadsUserLink = result.User.Link; } return(_currentUser); }
/// <summary> /// Returns the books for the logged in user /// </summary> /// <param name="type"></param> /// <param name="filter"></param> /// <param name="maxUpdates"></param> public async Task <Reviews> GetBooks(string shelf = null, string sort = null, string query = null, string order = null, string page = null, string per_page = "200") { string url = Urls.ShelfBooks + MyShelfSettings.Instance.GoodreadsUserID + ".xml?key=" + MyShelfSettings.Instance.ConsumerKey + "&format=xml&v=2"; if (!String.IsNullOrEmpty(shelf)) { url += "&shelf=" + shelf; } if (!String.IsNullOrEmpty(per_page)) { url += "&per_page=" + per_page; } var response = await ApiClient.Instance.ExecuteForProtectedResourceAsync(url, RestSharp.Method.GET, MyShelfSettings.Instance.ConsumerKey, MyShelfSettings.Instance.ConsumerSecret, MyShelfSettings.Instance.OAuthAccessToken, MyShelfSettings.Instance.OAuthAccessTokenSecret, null, CacheMode.UpdateAsyncIfExpired, TimeSpan.FromHours(6) ); //if (shelf == null && justRefreshedReviews) //{ // Task.Run(async () => // { // client.Authenticator = OAuth1Authenticator.ForProtectedResource(API_KEY, OAUTH_SECRET, UserSettings.Settings.OAuthAccessToken, UserSettings.Settings.OAuthAccessTokenSecret); // string url = "review/list/" + UserSettings.Settings.GoodreadsUserID + ".xml?key=" + API_KEY + "&format=xml&v=2"; // //TODO: more params, probably enums // if (!String.IsNullOrEmpty(shelf)) // url += "&shelf=" + shelf; // if (!String.IsNullOrEmpty(per_page)) // url += "&per_page=" + per_page; // await apiSemaphore.WaitAsync(); // var request = new RestRequest(url, Method.GET); // var response = await client.ExecuteAsync(request); // ApiCooldown(); // var result = DeserializeResponse(response.Content.ToString()); // GoodreadsReviews = result.Reviews; // }); //} //else //{ //client.Authenticator = OAuth1Authenticator.ForProtectedResource(API_KEY, OAUTH_SECRET, UserSettings.Settings.OAuthAccessToken, UserSettings.Settings.OAuthAccessTokenSecret); //string url = Urls.ShelfBooks + MyShelfSettings.Instance.GoodreadsUserID + ".xml?key=" + MyShelfSettings.Instance.ConsumerKey + "&format=xml&v=2"; //TODO: more params, probably enums //if (!String.IsNullOrEmpty(shelf)) // url += "&shelf=" + shelf; //if (!String.IsNullOrEmpty(per_page)) // url += "&per_page=" + per_page; //var response = await ApiClient.Instance.ExecuteForProtectedResourceAsync(url, RestSharp.Method.GET, MyShelfSettings.Instance.ConsumerKey, MyShelfSettings.Instance.ConsumerSecret, MyShelfSettings.Instance.OAuthAccessToken, MyShelfSettings.Instance.OAuthAccessTokenSecret); //await apiSemaphore.WaitAsync(); //var request = new RestRequest(url, Method.GET); //var response = await client.ExecuteAsync(request); //ApiCooldown(); var result = GoodReadsSerializer.DeserializeResponse(response.Content); //GoodreadsReviews = result.Reviews; //} return(result.Reviews); }