public void GetAccessToken(string username, string password, Action <string, string, bool> onCompletion) { var request = new RestRequest("oauth/access_token", Method.POST); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, username, password); _client.ExecuteAsync(request, (response => { if (response.StatusCode == HttpStatusCode.OK) { var results = response.Content.Split('&'); var tokenPair = results[0].Split('='); var tokenSecretPair = results[1].Split('='); _token = tokenPair[1]; _tokenSecret = tokenSecretPair[1]; if (onCompletion != null) { onCompletion(_token, _tokenSecret, true); } } else if (response.StatusCode == HttpStatusCode.Unauthorized) { if (onCompletion != null) { onCompletion(null, null, false); } } })); }
public void AddBookmark(string url, Action <Bookmark> onCompletion, string title = "", string description = "", int?folderId = null, bool resolveFinalUrl = true) { var request = new RestRequest("bookmarks/add", Method.POST); request.AddParameter("url", url); if (!string.IsNullOrEmpty(title)) { request.AddParameter("title", title); } if (!string.IsNullOrEmpty(description)) { request.AddParameter("description", description); } if (folderId.HasValue) { request.AddParameter("folder_id", folderId.Value); } if (!resolveFinalUrl) { request.AddParameter("resolve_final_url", 0); } _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { var results = response.Content; //JsonDeserializer deserializer = new JsonDeserializer(); //var parameterList = deserializer.Deserialize<List<string>>(response); //List<Bookmark> bookmarks = new List<Bookmark>(); //foreach (var item in parameterList) //{ // var items = deserializer.Deserialize<Dictionary<string, string>>(item); // if (items["type"].ToString() == "bookmark") // { // var bookmark = deserializer.Deserialize<Bookmark>(item); // if (showLoadingText) // { // bookmark.Description = "Downloading..."; // this should be in a resource // bookmark.IsDescriptionValid = false; // } // bookmarks.Add(bookmark); // } //} if (onCompletion != null) { onCompletion(null); } })); }
public void ListFolders(Action onCompletion) { var request = new RestRequest("folders/list", Method.POST); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { if (onCompletion != null) { onCompletion(); } })); }
public void DeleteBookmark(long bookmarkId, Action onCompletion) { var request = new RestRequest("bookmarks/delete", Method.POST); request.AddParameter("bookmark_id", bookmarkId); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { if (onCompletion != null) { onCompletion(); } })); }
public void StarBookmark(long bookmarkId, bool isStarred, Action onCompletion) { string url = isStarred ? "bookmarks/star" : "bookmarks/unstar"; var request = new RestRequest(url, Method.POST); request.AddParameter("bookmark_id", bookmarkId); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { if (onCompletion != null) { onCompletion(); } })); }
public void UpdateReadProgress(long bookmarkId, double progress, DateTime progressTimestamp, Action onCompletion) { var request = new RestRequest("bookmarks/update_read_progress", Method.POST); request.AddParameter("bookmark_id", bookmarkId); request.AddParameter("progress", progress); request.AddParameter("progress_timestamp", OAuthHelper.GetTimestamp(progressTimestamp)); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { if (onCompletion != null) { onCompletion(); } })); }
public string GetBookmarkTextSync(long bookmarkId) { var request = new RestRequest("bookmarks/get_text", Method.POST); request.AddParameter("bookmark_id", bookmarkId); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); IRestResponse asyncResponse = null; var executedCallBack = new AutoResetEvent(false); _client.ExecuteAsync(request, (response => { asyncResponse = response; executedCallBack.Set(); })); executedCallBack.WaitOne(); return(asyncResponse.Content); }
public void GetBookmarks(string folderId, List <Bookmark> existingBookmarks, bool showLoadingText, Action <List <Bookmark> > onCompletion) { var request = new RestRequest("bookmarks/list", Method.POST); if (!string.IsNullOrEmpty(folderId)) { request.AddParameter("folder_id", folderId); } _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { var results = response.Content; JsonDeserializer deserializer = new JsonDeserializer(); var parameterList = deserializer.Deserialize <List <string> >(response); List <Bookmark> bookmarks = new List <Bookmark>(); foreach (var item in parameterList) { var items = deserializer.Deserialize <Dictionary <string, string> >(item); if (items["type"].ToString() == "bookmark") { var bookmark = deserializer.Deserialize <Bookmark>(item); bookmark.IsDownloaded = false; bookmark.Folder = folderId; if (showLoadingText) { bookmark.ShortBodyText = "Downloading..."; // this should be in a resource } bookmarks.Add(bookmark); } } if (onCompletion != null) { onCompletion(bookmarks); } })); }
public void VerifyCredentials(Action <User> onCompletion) { var request = new RestRequest("account/verify_credentials", Method.POST); _client.Authenticator = XAuthAuthenticator.ForAccessToken(_consumerKey, _consumerSecret, _token, _tokenSecret, true); _client.ExecuteAsync(request, (response => { User user = null; if (response.StatusCode != HttpStatusCode.Forbidden) { var results = response.Content; JsonDeserializer deserializer = new JsonDeserializer(); user = deserializer.Deserialize <List <User> >(response)[0]; } if (onCompletion != null) { onCompletion(user); } })); }