public override Document Save(Document document) { try { if (string.IsNullOrEmpty(document.Id)) { HttpContent httpContent = BuildHttpBody(document); HttpContent httpResponse = ApiClient.Post(_documentsPath, httpContent); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <Document>(response)); } else { string json = MifielUtils.ConvertObjectToJson(document); HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); HttpContent httpResponse = ApiClient.Put(_documentsPath, httpContent); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <Document>(response)); } } catch (Exception ex) { throw new MifielException(ex.Message, ex); } }
public override List <Document> FindAll() { HttpContent httpResponse = ApiClient.Get(_documentsPath); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <List <Document> >(response)); }
public override Document Find(string id) { HttpContent httpResponse = ApiClient.Get(_documentsPath + "/" + id); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <Document>(response)); }
private void SaveFile(string id, string localPath, SaveFileEndPointEnum saveFileEndPoint) { String uri = _documentsPath + "/" + id + "/" + saveFileEndPoint.ToString().ToLower(); HttpContent httpResponse = ApiClient.Get(uri); MifielUtils.SaveHttpResponseToFile(httpResponse, localPath); }
public override Certificate Find(string id) { HttpContent httpResponse = ApiClient.Get(_certificatesPath + "/" + id); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <Certificate>(response)); }
private HttpContent BuildHttpBody(Document document) { List <Signature> signatures = document.Signatures; List <Viewer> viewers = document.Viewers; string filePath = document.File; string fileName = document.FileName; string originalHash = document.OriginalHash; Dictionary <string, string> parameters = new Dictionary <string, string>(); MifielUtils.AppendTextParamToContent(parameters, "callback_url", document.CallbackUrl); MifielUtils.AppendTextParamToContent(parameters, "manual_close", document.ManualClose.ToString().ToLower()); MifielUtils.AppendTextParamToContent(parameters, "send_mail", document.SendMail.ToString().ToLower()); MifielUtils.AppendTextParamToContent(parameters, "send_invites", document.SendInvites.ToString().ToLower()); for (int i = 0; i < signatures.Count; i++) { MifielUtils.AppendTextParamToContent(parameters, "signatories[" + i + "][name]", signatures[i].SignerName); MifielUtils.AppendTextParamToContent(parameters, "signatories[" + i + "][email]", signatures[i].Email); MifielUtils.AppendTextParamToContent(parameters, "signatories[" + i + "][tax_id]", signatures[i].TaxId); } for (int i = 0; i < viewers.Count; i++) { MifielUtils.AppendTextParamToContent(parameters, "viewers[" + i + "][name]", viewers[i].Name); MifielUtils.AppendTextParamToContent(parameters, "viewers[" + i + "][email]", viewers[i].Email); } if (!string.IsNullOrEmpty(filePath)) { MultipartFormDataContent multipartContent = new MultipartFormDataContent(); ByteArrayContent pdfContent = new ByteArrayContent(File.ReadAllBytes(filePath)); pdfContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf"); multipartContent.Add(pdfContent, "file", Path.GetFileName(filePath)); foreach (var keyValuePair in parameters) { multipartContent.Add(new StringContent(keyValuePair.Value), string.Format("\"{0}\"", keyValuePair.Key)); } return(multipartContent); } if (!string.IsNullOrEmpty(originalHash) && !string.IsNullOrEmpty(fileName)) { MifielUtils.AppendTextParamToContent(parameters, "original_hash", originalHash); MifielUtils.AppendTextParamToContent(parameters, "name", fileName); return(new FormUrlEncodedContent(parameters)); } throw new MifielException("You must provide file or original hash and file name"); }
private string GetSignature(Rest.HttpMethod httpMethod, string path, string contentMd5, string date, string contentType) { string canonicalString = string.Format("{0},{1},{2},{3},{4}", httpMethod.ToString(), contentType, contentMd5, _apiVersion + path, date); return(MifielUtils.CalculateHMAC(AppSecret, canonicalString)); }
public SignatureResponse RequestSignature(string id, string email, string cc) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("email", email); parameters.Add("cc", cc); FormUrlEncodedContent httpContent = new FormUrlEncodedContent(parameters); HttpContent httpResponse = ApiClient.Post(_documentsPath + "/" + id + "/request_signature", httpContent); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <SignatureResponse>(response)); }
public CloseDocument Close(string id) { var stringBuilder = new StringBuilder(_documentsPath); stringBuilder.Append("/"); stringBuilder.Append(id); stringBuilder.Append("/close"); HttpContent httpResponse = ApiClient.Post(stringBuilder.ToString()); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <CloseDocument>(response)); }
private HttpContent BuildHttpBody(Document document) { List <Signature> signatures = document.Signatures; string filePath = document.File; string fileName = document.FileName; string originalHash = document.OriginalHash; if (!string.IsNullOrEmpty(filePath)) { MultipartFormDataContent multipartContent = new MultipartFormDataContent(); ByteArrayContent pdfContent = new ByteArrayContent(File.ReadAllBytes(filePath)); pdfContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf"); multipartContent.Add(pdfContent, "file", Path.GetFileName(filePath)); return(multipartContent); } else if (!string.IsNullOrEmpty(originalHash) && !string.IsNullOrEmpty(fileName)) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("original_hash", originalHash); parameters.Add("name", fileName); MifielUtils.AppendTextParamToContent(parameters, "callback_url", document.CallbackUrl); if (signatures != null) { for (int i = 0; i < signatures.Count; i++) { MifielUtils.AppendTextParamToContent(parameters, "signatories[" + i + "][name]", signatures[i].SignatureStr); MifielUtils.AppendTextParamToContent(parameters, "signatories[" + i + "][email]", signatures[i].Email); MifielUtils.AppendTextParamToContent(parameters, "signatories[" + i + "][tax_id]", signatures[i].TaxId); } } return(new FormUrlEncodedContent(parameters)); } else { throw new MifielException("You must provide file or original hash and file name"); } }
public override Certificate Save(Certificate certificate) { if (string.IsNullOrEmpty(certificate.Id)) { HttpContent httpContent = BuildHttpBody(certificate); HttpContent httpResponse = ApiClient.Post(_certificatesPath, httpContent); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <Certificate>(response)); } else { string json = MifielUtils.ConvertObjectToJson(certificate); HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); HttpContent httpResponse = ApiClient.Put(_certificatesPath, httpContent); string response = httpResponse.ReadAsStringAsync().Result; return(MifielUtils.ConvertJsonToObject <Certificate>(response)); } }
public void SaveXml(string id, string localPath) { HttpContent httpResponse = ApiClient.Get(_documentsPath + "/" + id + "/xml"); MifielUtils.SaveHttpResponseToFile(httpResponse, localPath); }