IRestRequest IRequestBuilder.PostCreateUploadShare(ApiCreateUploadShareRequest uploadShareParams) { RestRequest request = new RestRequest(ApiConfig.ApiPostCreateUploadShare, Method.POST); SetGeneralRestValues(request, true, uploadShareParams); return(request); }
internal static ApiCreateUploadShareRequest ToApiCreateUploadShareRequest(CreateUploadShareRequest request) { ApiExpiration apiExpiration = null; if (request.Expiration.HasValue) { apiExpiration = new ApiExpiration { ExpireAt = request.Expiration, EnableExpiration = request.Expiration.Value.Ticks != 0 }; } ApiCreateUploadShareRequest apiCreateUploadShareRequest = new ApiCreateUploadShareRequest { NodeId = request.NodeId, Name = request.Name, AccessPassword = request.AccessPassword, Expiration = apiExpiration, UploadedFilesExpirationPeriod = request.UploadedFilesExpirationPeriod, Notes = request.Notes, NotifyCreator = request.NotifyCreator, ShowUploadedFiles = request.ShowUploadedFiles, MaxAllowedUploads = request.MaxAllowedUploads, MaxAllowedTotalSizeOverAllUploadedFiles = request.MaxAllowedTotalSizeOverAllUploadedFiles }; if (request.EmailRecipients != null) { // Check if the list is not empty is still in the previous validator done apiCreateUploadShareRequest.SendMail = true; apiCreateUploadShareRequest.MailRecipients = GenerateRecipientString(request.EmailRecipients); apiCreateUploadShareRequest.MailBody = request.EmailBody; apiCreateUploadShareRequest.MailSubject = request.EmailSubject; } else { apiCreateUploadShareRequest.SendMail = false; } if (request.SmsRecipients != null) { // Check if the list is not empty is still in the previous validator done apiCreateUploadShareRequest.SendSms = true; apiCreateUploadShareRequest.SmsRecipients = GenerateRecipientString(request.SmsRecipients); } else { apiCreateUploadShareRequest.SendSms = false; } return(apiCreateUploadShareRequest); }
public void ToApiCreateUploadShareRequest(string smsRecipients, string emailRecipients) { // ARRANGE ApiCreateUploadShareRequest expected = FactoryShare.ApiCreateUploadShareRequest; List <string> smsRecList = null; if (smsRecipients != null) { smsRecList = new List <string>(); smsRecList.AddRange(smsRecipients.Split(',')); expected.SmsRecipients = smsRecipients; expected.SendSms = true; } List <string> emailRecList = null; if (emailRecipients != null) { emailRecList = new List <string>(); emailRecList.AddRange(emailRecipients.Split(',')); expected.MailBody = "Some body"; expected.MailSubject = "You received a DRACOON share!"; expected.MailRecipients = emailRecipients; expected.SendMail = true; } CreateUploadShareRequest param = new CreateUploadShareRequest(expected.NodeId, expected.Name) { Notes = expected.Notes, Expiration = expected.Expiration.ExpireAt, ShowUploadedFiles = expected.ShowUploadedFiles, NotifyCreator = expected.NotifyCreator, MaxAllowedTotalSizeOverAllUploadedFiles = expected.MaxAllowedTotalSizeOverAllUploadedFiles, MaxAllowedUploads = expected.MaxAllowedUploads, AccessPassword = expected.AccessPassword, UploadedFilesExpirationPeriod = expected.UploadedFilesExpirationPeriod, EmailRecipients = emailRecList, EmailBody = expected.MailBody, EmailSubject = expected.MailSubject, SmsRecipients = smsRecList }; // ACT ApiCreateUploadShareRequest actual = ShareMapper.ToApiCreateUploadShareRequest(param); // ASSERT Assert.Equal(expected, actual, new ApiCreateUploadShareRequestComparer()); }
public UploadShare CreateUploadShare(CreateUploadShareRequest request) { _client.Executor.CheckApiServerVersion(); #region Parameter Validation request.MustNotNull(nameof(request)); request.NodeId.MustPositive(nameof(request.NodeId)); request.Name.MustNotNullOrEmptyOrWhitespace(nameof(request.Name)); request.MaxAllowedUploads.NullableMustPositive(nameof(request.MaxAllowedUploads)); request.MaxAllowedTotalSizeOverAllUploadedFiles.NullableMustPositive(nameof(request.MaxAllowedTotalSizeOverAllUploadedFiles)); request.UploadedFilesExpirationPeriod.NullableMustPositive(nameof(request.UploadedFilesExpirationPeriod)); if (request.EmailRecipients != null) { request.EmailRecipients.EnumerableMustNotNullOrEmpty(nameof(request.EmailRecipients)); request.EmailRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailRecipients) + " element")); request.EmailBody.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailBody)); request.EmailSubject.MustNotNullOrEmptyOrWhitespace(nameof(request.EmailSubject)); } if (request.SmsRecipients != null) { request.SmsRecipients.EnumerableMustNotNullOrEmpty(nameof(request.SmsRecipients)); request.SmsRecipients.ForEach(current => current.MustNotNullOrEmptyOrWhitespace(nameof(request.SmsRecipients) + " element")); if (string.IsNullOrEmpty(request.AccessPassword)) { throw new ArgumentException("If a SMS should be sent, a access password must be set."); } } #endregion ApiCreateUploadShareRequest apiRequest = ShareMapper.ToApiCreateUploadShareRequest(request); IRestRequest restRequest = _client.Builder.PostCreateUploadShare(apiRequest); ApiUploadShare resultShare = _client.Executor.DoSyncApiCall <ApiUploadShare>(restRequest, DracoonRequestExecutor.RequestType.PostCreateUploadShare); return(ShareMapper.FromApiUploadShare(resultShare)); }