public void Register(string email) { Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(email), "Invalid email address, cannot be null or empty."); var client = new RestClient(Host.Url); try { client.AddParameter("user[email]", email); client.AddParameter("module[InstallType]", EnabledFeatures.InstallType()); client.AddParameter("module[ProfCompareModule]", EnabledFeatures.CompareEnabled.ToString()); client.AddParameter("module[ProfReviewModule]", EnabledFeatures.ReviewEnabled.ToString()); client.AddParameter("module[ProfProtectModule]", EnabledFeatures.SecurityEnabled.ToString()); client.AddParameter("module[ProfSecureFileTransferModule]", EnabledFeatures.SecureFileTransferEnabled.ToString()); client.AddParameter("module[ProfHummingbirdModule]", EnabledFeatures.HummingbirdEnabled.ToString()); client.AddParameter("module[ProfInterwovenModule]", EnabledFeatures.InterwovenEnabled.ToString()); client.AddParameter("module[ProfSharePointModule]", EnabledFeatures.SharePointEnabled.ToString()); client.AddParameter("module[ProfNetDocumentsModule]", EnabledFeatures.NetDocumentsEnabled.ToString()); client.Post("/api/v1.3/sign_ups/create_by_email.json"); } catch (Exception) { if (client.Json != null) { if (client.Json.Contains("resource_validation_error")) throw new SecurityException("Password is too short (must be at least 4 characters)"); } throw; } }
public void SetPermissions(IPlatformPermissions attributes) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("permission[can_access_anonymously]", attributes.CanAccessAnonymously.ToString().ToLower()); client.AddParameter("permission[can_invite_with_link]", attributes.CanInvite.ToString().ToLower()); client.AddParameter("permission[can_download_original]", attributes.CanDownload.ToString().ToLower()); client.AddParameter("permission[can_upload_changes]", attributes.CanUploadChanges.ToString().ToLower()); client.AddParameter("permission[can_manipulate]", attributes.CanManipulate.ToString().ToLower()); client.AddParameter("permission[inherits_from_parent]", attributes.InheritsFromParent.ToString().ToLower()); client.Put(string.Format("/api/v1.2/folders/{0}/permission.json", Id)); var client2 = new RestClient(Host.Url, Session.Cookies); client2.AddParameter("folder[notify_owner]", attributes.NotifyOwner.ToString().ToLower()); if (attributes.ExpiryDate.HasValue && attributes.ExpiryDate.Value.Year < 9999 && attributes.ExpiryDate.Value.Year > 1) { // Also add this expiry date. var expiry = attributes.ExpiryDate.Value.ToString("yyyy-MM-dd HH:mm:ss UTC"); client2.AddParameter("folder[expires_at]", expiry); } else { client2.AddParameter("folder[expires_at]", ""); } client2.Put(string.Format("/api/v1.2/folders/{0}.json", Id)); }
public string Invite(string fileToken, string groupUuid) { var client = new RestClient(Host.Url, Session.Cookies); client.EncodeParametersAsJson = true; client.AddParameter("fileToken", fileToken); client.AddParameter("groupUuid", groupUuid); var response = client.Post("/groups-api/api/v1.0/invite.json"); return response.Headers.Location.ToString(); }
public IPlatformGroup Create(string name) { var client = new RestClient(Host.Url, Session.Cookies); client.EncodeParametersAsJson = true; client.AddParameter("name", name); client.AddParameter("audience", "PRIVATE"); client.Post("/groups-api/api/v1.0/groups.json"); return Get().Find(x => x.Name == name); }
private IPlatformComment Add(string body, int fileId, int fileVersion, long replyToId) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("comment[body]", body); client.AddParameter("comment[file_id]", fileId); client.AddParameter("comment[file_version]", fileVersion); client.AddParameter("comment[slide_number]", 1); if (replyToId > 0) client.AddParameter("comment[reply_to_id]", replyToId); client.Post("/api/v1.2/comments.json"); return new PlatformComment(Session, User, client.Content); }
public List<IPlatformGroup> Get() { var groups = new List<IPlatformGroup>(); var page = 1; var more = false; do { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("page", page.ToString()); client.Get("/groups-api/api/v1.0/groups.json"); var jsonGroups = client.Content.SelectToken("groups"); foreach (var jsonGroup in jsonGroups) { groups.Add(new PlatformGroup(jsonGroup)); } var pagination = client.Content.SelectToken("pagination"); more = pagination.SelectToken("current_page").Value<int>() < pagination.SelectToken("total_pages").Value<int>(); page++; } while (more); return groups; }
public void Rename(string newName) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("folder[name]", newName); client.Put(string.Format("/api/v1.2/folders/{0}.json", Id)); this.Name = newName; }
public IEnumerable<IPlatformNotification> GetForFile(int fileId, bool unread) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("file_id", fileId); if (unread) { client.AddParameter("unread", "true"); } client.Get("api/v1.2/notifications.json"); var activitiesToken = client.Content.SelectToken("activities"); var res = new List<IPlatformNotification>(); foreach (var avtivityToken in activitiesToken) { res.Add(new PlatformNotification(Session, User, avtivityToken)); } return res; }
public IEnumerable<IPlatformComment> GetByFile(int fileId, int version) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("file_id", fileId); if (version > 0) { client.AddParameter("file_version", version); } client.Get("/api/v1.2/comments.json"); var comments = new List<IPlatformComment>(); var jsonFolders = client.Content; foreach (var jsonComment in jsonFolders) { comments.Add(new PlatformComment(Session, User, jsonComment)); } return comments; }
public Bitmap GetAvatar() { var avatarFile = Path.Combine(_cache, User.Uuid); if (!File.Exists(avatarFile)) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("token", User.Uuid); var response = client.Get("/api/v1.2/users/find_by_token.json"); response.EnsureSuccessStatusCode(); var url = client.Content.First.SelectToken("avatar").Value<string>(); var webClient = new WebClient(); webClient.DownloadFile(url, avatarFile); } return new Bitmap(avatarFile); }
public List<IPlatformFolder> Get() { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("with_files", 0); client.Get("/api/v1.2/folders.json"); var jsonFolders = client.Content.SelectToken("folders"); var folders = new List<IPlatformFolder>(); foreach (var jsonFolder in jsonFolders) { folders.Add(new PlatformFolder(Session, User, null, jsonFolder)); } return folders; }
public IPlatformUser Authenticate(string email, string password) { using (var handler = new HttpClientHandler()) using (var client = new HttpClient(handler) { BaseAddress = new Uri(Host.Url) }) { var parameters = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("user_session[email]", email), new KeyValuePair<string, string>("user_session[password]", password), new KeyValuePair<string, string>("device[app_uid]", "WorkshareProtect") }); var response = client.PostAsync("/api/v1.3/user_sessions.json", parameters).Result; if ((int)response.StatusCode == 422) throw new UnauthorizedAccessException("Invalid user name or password."); response.EnsureSuccessStatusCode(); Session.Cookies = handler.CookieContainer; var content = response.Content.ReadAsStringAsync().Result; var parsedContent = JObject.Parse(content); User.DeviceToken = parsedContent.SelectToken("device_auth_token").Value<string>(); var client2 = new RestClient(Host.Url, handler.CookieContainer); client2.AddParameter("with_files", 0); client2.Get("/api/v1.2/folders.json"); var jsonFolders = client2.Content.SelectToken("folders"); foreach (var jsonFolder in jsonFolders) { var parentId = jsonFolder.SelectToken("parent_id").Value<long?>(); if (!parentId.HasValue) { User.Uuid = jsonFolder.SelectToken("owner").SelectToken("uuid").Value<string>(); User.Id = jsonFolder.SelectToken("owner").SelectToken("id").Value<string>(); User.Email = jsonFolder.SelectToken("owner").SelectToken("email").Value<string>(); return User; } } return User; } }
public IPlatformFolder GetMyFilesFolder() { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("with_files", 0); client.Get("/api/v1.2/folders.json"); var jsonFolders = client.Content.SelectToken("folders"); foreach (var jsonFolder in jsonFolders) { var parentId = jsonFolder.SelectToken("parent_id").Value<long?>(); if (!parentId.HasValue) { return new PlatformFolder(Session, User, null, jsonFolder); } } throw new InvalidOperationException("My files folder does not exist."); }
public IPlatformFolder Create(string name, string parentId, IPlatformPermissions attributes) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("folder[name]", name); client.AddParameter("folder[description]", ""); client.AddParameter("folder[notify_owner]", attributes.NotifyOwner.ToString()); client.AddParameter("folder[parent_id]", parentId); client.AddParameter("rewrite_folder_ids", "false"); if (attributes.ExpiryDate.HasValue && attributes.ExpiryDate.Value.Year < 9999 && attributes.ExpiryDate.Value.Year > 1) { client.AddParameter("folder[expires_at]", attributes.ExpiryDate.Value.ToString("yyyy-MM-dd HH:mm:ss UTC")); } client.Post("/api/v1.2/folders.json"); return new PlatformFolder(Session, User, null, client.Content); }
public IPlatformComment Edit(string body, long commentid) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("comment[body]", body); client.Put(string.Format("/api/v1.2/comments/{0}.json", commentid)); return new PlatformComment(Session, User, client.Content); }
public void SendValidationEmail(string email) { var client = new RestClient(Host.Url); client.AddParameter("user[email]", email); client.Post("/api/v1.3/validations.json"); //var client = new RestClient(Host.Url); //var request = new RestRequest("/api/v1.3/validations.xml", Method.POST); //request.AddParameter("user[email]", email); //var response = client.Execute(request); //ResponsePolicy.Validate(response); //return response.StatusCode == HttpStatusCode.Created; }
public void Register(string email, string password) { var client = new RestClient(Host.Url); client.AddParameter("start_trial", "false"); client.AddParameter("user[email]", email); client.AddParameter("user[password]", password); client.AddParameter("user[password_confirmation]", password); client.AddParameter("user[first_name]", email); client.AddParameter("user[last_name]", string.Empty); client.AddParameter("module[InstallType]", EnabledFeatures.InstallType()); client.AddParameter("module[ProfCompareModule]", EnabledFeatures.CompareEnabled.ToString()); client.AddParameter("module[ProfReviewModule]", EnabledFeatures.ReviewEnabled.ToString()); client.AddParameter("module[ProfProtectModule]", EnabledFeatures.SecurityEnabled.ToString()); client.AddParameter("module[ProfSecureFileTransferModule]", EnabledFeatures.SecureFileTransferEnabled.ToString()); client.AddParameter("module[ProfHummingbirdModule]", EnabledFeatures.HummingbirdEnabled.ToString()); client.AddParameter("module[ProfInterwovenModule]", EnabledFeatures.InterwovenEnabled.ToString()); client.AddParameter("module[ProfSharePointModule]", EnabledFeatures.SharePointEnabled.ToString()); client.AddParameter("module[ProfNetDocumentsModule]", EnabledFeatures.NetDocumentsEnabled.ToString()); client.Post("/api/v1.3/sign_ups.json"); }
public IEnumerable<IPlatformUser> GetUsers(List<string> tokens) { var res = new List<IPlatformUser>(); if (!tokens.Any()) return res; var client = new RestClient(Host.Url); client.AddParameter("token", string.Join(",", tokens)); client.Get("/api/v1.2/users/find_by_token.json"); foreach (var platformUser in client.Content) { res.Add(new PlatformUser(Session, platformUser)); } return res; }
public void AddMember(string email) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("member[user_email]", email); client.Post(string.Format("/api/v1.2/folders/{0}/members.json", Id)); }
private IPlatformUser AuthenticateWithDeviceToken() { if (!string.IsNullOrEmpty(User.DeviceToken)) { try { var client = new RestClient(Host.Url); client.AddCookie(new Cookie("device_credentials", User.DeviceToken)); client.AddParameter("includes", "a.profile"); var response = client.Get("/api/v1.3/current_user.json"); if (response.IsSuccessStatusCode) { Session.Cookies = client.CookieContainer; User.IsDeactivated = client.Content.SelectToken("is_deactivated").Value<bool>(); User.AccountId = client.Content.SelectToken("account").SelectToken("id").Value<string>(); User.Uuid = client.Content.SelectToken("uuid").Value<string>(); User.Email = client.Content.SelectToken("email").Value<string>(); User.Account = new PlatformAccount(Session, client.Content.SelectToken("account")); if (User.IsDeactivated) throw new UnauthorizedAccessException("The account has been deactivated."); return User; } } catch (Exception e) { Logger.LogError(e); } } return null; }
public void VisitFile(int fileId) { var client = new RestClient(Host.Url, Session.Cookies); client.AddParameter("visit[file_id]",fileId); client.Post(string.Format("/api/v1.2/visits.json")); }
public IPlatformUser GetUser(string email) { var client = new RestClient(Host.Url); client.AddParameter("email", email); client.Get("/api/open-v1.3/users/user_exists.json"); var userContent = client.Content.First; if (userContent.SelectToken("present").Value<bool>()) { var user = new PlatformUser(Session) { Email = userContent.SelectToken("email").Value<string>().ToLower(), Plan = userContent.SelectToken("plan_name").Value<string>(), IsProfessionalEnabled = userContent.SelectToken("professional8").Value<bool>(), IsDeactivated = userContent.SelectToken("is_deactivated").Value<bool>() }; return user; } return null; }