Update swagger, add csx (SignatureAPI) (#3298)
This commit is contained in:
Родитель
552aca8477
Коммит
04f29441d8
|
@ -85,24 +85,24 @@
|
|||
"type": "string",
|
||||
"x-ms-summary": "Name",
|
||||
"description": "The name of the sender.",
|
||||
"x-ms-visibility": "important"
|
||||
"x-ms-visibility": "advanced"
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"x-ms-summary": "Email",
|
||||
"description": "The email address of the sender.",
|
||||
"x-ms-visibility": "important"
|
||||
"x-ms-visibility": "advanced"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"email"
|
||||
]
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"type": "boolean",
|
||||
"x-ms-summary": "Test Envelope",
|
||||
"description": "Set to true for test envelopes. Test envelopes are not legally binding.",
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"live",
|
||||
"test"
|
||||
],
|
||||
"x-ms-summary": "Envelope Mode",
|
||||
"description": "Test mode envelopes are non-binding and not billed.",
|
||||
"x-ms-visibility": "advanced"
|
||||
}
|
||||
},
|
||||
|
@ -431,10 +431,14 @@
|
|||
"canceled"
|
||||
]
|
||||
},
|
||||
"EnvelopeTest": {
|
||||
"type": "boolean",
|
||||
"x-ms-summary": "Test Envelope",
|
||||
"description": "Indicates whether this is a test envelope. Test envelopes are not legally binding."
|
||||
"EnvelopeMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"live",
|
||||
"test"
|
||||
],
|
||||
"x-ms-summary": "Envelope Mode",
|
||||
"description": "Test mode envelopes are non-binding and not billed."
|
||||
},
|
||||
"EnvelopeDeliverable": {
|
||||
"type": "object",
|
||||
|
@ -468,8 +472,8 @@
|
|||
"sender": {
|
||||
"$ref": "#/definitions/EnvelopeSender"
|
||||
},
|
||||
"test": {
|
||||
"$ref": "#/definitions/EnvelopeTest"
|
||||
"mode": {
|
||||
"$ref": "#/definitions/EnvelopeMode"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -508,8 +512,8 @@
|
|||
"completed_at": {
|
||||
"$ref": "#/definitions/EnvelopeCompletedAt"
|
||||
},
|
||||
"test": {
|
||||
"$ref": "#/definitions/EnvelopeTest"
|
||||
"mode": {
|
||||
"$ref": "#/definitions/EnvelopeMode"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
},
|
||||
"description": "The API Key for your Signature API account.",
|
||||
"displayName": "API Key",
|
||||
"tooltip": "Generate both test and live API keys at https://dashboard.signatureapi.com."
|
||||
"tooltip": "Get your API key in https://dashboard.signatureapi.com."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -22,6 +22,6 @@
|
|||
"scriptOperations": [
|
||||
"AddDocument",
|
||||
"GetDeliverable"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
using System.Net;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
public class Script : ScriptBase
|
||||
{
|
||||
public override async Task<HttpResponseMessage> ExecuteAsync()
|
||||
{
|
||||
if ("AddDocument".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var contentAsString = await this.Context.Request.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
var contentAsJson = JObject.Parse(contentAsString);
|
||||
|
||||
var fileContentBase64 = (string)contentAsJson["file_content"];
|
||||
|
||||
var fileContent = Convert.FromBase64String(fileContentBase64);
|
||||
|
||||
Uri baseUri = BaseUri(Context.Request.RequestUri);
|
||||
string apiKey = Context.Request.Headers.GetValues("X-Api-Key").FirstOrDefault();
|
||||
|
||||
HttpRequestMessage createFileRequest = new HttpRequestMessage();
|
||||
|
||||
createFileRequest.Method = HttpMethod.Post;
|
||||
createFileRequest.RequestUri = new Uri(baseUri, "/v1/files");
|
||||
createFileRequest.Headers.Add("X-Api-Key", apiKey);
|
||||
|
||||
var createFileResponse = await Context.SendAsync(createFileRequest, this.CancellationToken);
|
||||
|
||||
if(!createFileResponse.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception($"Could not create temporary file. Status code: {createFileResponse.StatusCode}");
|
||||
}
|
||||
|
||||
Uri locationUrl = createFileResponse.Headers.Location;
|
||||
|
||||
string createFileResponseString = await createFileResponse.Content.ReadAsStringAsync();
|
||||
|
||||
JObject createFileResponseJson = JObject.Parse(createFileResponseString);
|
||||
|
||||
string putUrl = (string)createFileResponseJson["put_url"];
|
||||
|
||||
HttpRequestMessage uploadFileRequest = new HttpRequestMessage();
|
||||
|
||||
uploadFileRequest.Method = HttpMethod.Put;
|
||||
uploadFileRequest.RequestUri = new Uri(putUrl);
|
||||
uploadFileRequest.Content = new ByteArrayContent(fileContent);
|
||||
|
||||
var uploadFileResponse = await Context.SendAsync(uploadFileRequest, this.CancellationToken);
|
||||
|
||||
if(!uploadFileResponse.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception($"Could not upload temporary file. Status code: {createFileResponse.StatusCode}");
|
||||
}
|
||||
|
||||
contentAsJson["file_content"] = null;
|
||||
contentAsJson["url"] = locationUrl.ToString();
|
||||
string outboundContentAsString = contentAsJson.ToString();
|
||||
|
||||
Context.Request.Content = CreateJsonContent(outboundContentAsString);
|
||||
|
||||
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
if("GetDeliverable".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);
|
||||
var resultJson = JObject.Parse(responseString);
|
||||
var deliverableUrl = (string)resultJson["url"];
|
||||
|
||||
if(deliverableUrl != null)
|
||||
{
|
||||
HttpRequestMessage downloadRequest = new HttpRequestMessage();
|
||||
downloadRequest.Method = HttpMethod.Get;
|
||||
downloadRequest.RequestUri = new Uri(deliverableUrl);
|
||||
|
||||
var downloadResponse = await Context.SendAsync(downloadRequest, this.CancellationToken);
|
||||
var downloadBytes = await downloadResponse.Content.ReadAsByteArrayAsync().ConfigureAwait(continueOnCapturedContext: false);
|
||||
string downloadBase64 = Convert.ToBase64String(downloadBytes);
|
||||
|
||||
resultJson["file_content"] = downloadBase64;
|
||||
|
||||
response.Content = CreateJsonContent(resultJson.ToString());
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private Uri BaseUri(Uri uri)
|
||||
{
|
||||
string baseUri = $"{uri.Scheme}://{uri.Host}";
|
||||
if(!uri.IsDefaultPort)
|
||||
{
|
||||
baseUri += $":{uri.Port}";
|
||||
}
|
||||
return new Uri(baseUri);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче