using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Nop.Core;
using Nop.Services.Configuration;
//----------------------
//
// Generated using the NSwag toolchain v13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
//
//----------------------
#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended."
#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword."
#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?'
#pragma warning disable 612 // Disable "CS0612 '...' is obsolete"
#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ...
#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..."
#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'"
#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant"
#pragma warning disable 8603 // Disable "CS8603 Possible null reference return"
#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter"
namespace Nop.Plugin.Misc.BillingoInvoicing.Services
{
using System = global::System;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
//public class CamelCaseStringEnumConverter : JsonConverter
//{
// private readonly JsonNamingPolicy _namingPolicy = JsonNamingPolicy.CamelCase;
// public override Enum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
// {
// // Use the base behavior to read as string
// string enumString = reader.GetString();
// // Parse the string back to the enum type
// if (Enum.TryParse(typeToConvert, enumString, ignoreCase: true, out var enumValue))
// {
// return (Enum)enumValue;
// }
// throw new JsonException($"Unable to parse \"{enumString}\" as enum of type {typeToConvert.Name}.");
// }
// public override void Write(Utf8JsonWriter writer, Enum value, JsonSerializerOptions options)
// {
// string original = value.ToString();
// string converted = _namingPolicy.ConvertName(original);
// writer.WriteStringValue(converted);
// }
//}
[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class BillingoClientService
{
private string _baseUrl = "https://api.billingo.hu/v3";
private System.Net.Http.HttpClient _httpClient;
private System.Lazy _settings;
private IStoreContext _storeContext;
private ISettingService _settingService;
public BillingoClientService(System.Net.Http.HttpClient httpClient,
IStoreContext storeContext,
ISettingService settingService)
{
_httpClient = httpClient;
_settings = new System.Lazy(CreateSerializerSettings, true);
_storeContext = storeContext;
_settingService = settingService;
}
private System.Text.Json.JsonSerializerOptions CreateSerializerSettings()
{
var settings = new System.Text.Json.JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters =
{
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
}
};
UpdateJsonSerializerSettings(settings);
return settings;
}
public string BaseUrl
{
get { return _baseUrl; }
set { _baseUrl = value; }
}
protected System.Text.Json.JsonSerializerOptions JsonSerializerSettings { get { return _settings.Value; } }
partial void UpdateJsonSerializerSettings(System.Text.Json.JsonSerializerOptions settings);
partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url);
partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder);
partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response);
///
/// List all bank account
///
///
/// Returns a list of your bank accounts. The bank accounts are returned sorted by creation date, with the most recent bank account appearing first.
///
/// Success response
/// A server side error occurred.
public virtual System.Threading.Tasks.Task ListBankAccountAsync(int? page, int? per_page)
{
return ListBankAccountAsync(page, per_page, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// List all bank account
///
///
/// Returns a list of your bank accounts. The bank accounts are returned sorted by creation date, with the most recent bank account appearing first.
///
/// Success response
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task ListBankAccountAsync(int? page, int? per_page, System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/bank-accounts?");
if (page != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("page") + "=").Append(System.Uri.EscapeDataString(ConvertToString(page, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (per_page != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("per_page") + "=").Append(System.Uri.EscapeDataString(ConvertToString(per_page, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
urlBuilder_.Length--;
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Create a bank account
///
///
/// Create a new bank account. Returns a bank account object if the create is succeded.
///
/// BankAccount object that you would like to store.
/// BankAccount created successfully.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task CreateBankAccountAsync(BankAccount body)
{
return CreateBankAccountAsync(body, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Create a bank account
///
///
/// Create a new bank account. Returns a bank account object if the create is succeded.
///
/// BankAccount object that you would like to store.
/// BankAccount created successfully.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task CreateBankAccountAsync(BankAccount body, System.Threading.CancellationToken cancellationToken)
{
if (body == null)
throw new System.ArgumentNullException("body");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/bank-accounts");
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = System.Text.Json.JsonSerializer.Serialize(body, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 201)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Retrieve a bank account
///
///
/// Retrieves the details of an existing bank account.
///
/// Success response
/// A server side error occurred.
public virtual System.Threading.Tasks.Task GetBankAccountAsync(int id)
{
return GetBankAccountAsync(id, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Retrieve a bank account
///
///
/// Retrieves the details of an existing bank account.
///
/// Success response
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task GetBankAccountAsync(int id, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/bank-accounts/{id}");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 404)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Non-existent resource is requested.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Update a bank account
///
///
/// Update an existing bank accounts. Returns a bank account object if the update is succeded.
///
/// Bank account object that you would like to update.
/// Bank account updated successfully.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task UpdateBankAccountAsync(int id, BankAccount body)
{
return UpdateBankAccountAsync(id, body, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Update a bank account
///
///
/// Update an existing bank accounts. Returns a bank account object if the update is succeded.
///
/// Bank account object that you would like to update.
/// Bank account updated successfully.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task UpdateBankAccountAsync(int id, BankAccount body, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
if (body == null)
throw new System.ArgumentNullException("body");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/bank-accounts/{id}");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = System.Text.Json.JsonSerializer.Serialize(body, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("PUT");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 404)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Non-existent resource is requested.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Delete a bank account
///
///
/// Delete an existing bank account.
///
/// Bank account deleted successfully.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task DeleteBankAccountAsync(int id)
{
return DeleteBankAccountAsync(id, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Delete a bank account
///
///
/// Delete an existing bank account.
///
/// Bank account deleted successfully.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task DeleteBankAccountAsync(int id, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/bank-accounts/{id}");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("DELETE");
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 204)
{
return;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 404)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Non-existent resource is requested.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Get currencies exchange rate.
///
///
/// Return with the exchange value of given currencies.
///
/// Currencies exchange rate returned.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task GetConversionRateAsync(Currency from, Currency to, System.DateTimeOffset? date)
{
return GetConversionRateAsync(from, to, date, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Get currencies exchange rate.
///
///
/// Return with the exchange value of given currencies.
///
/// Currencies exchange rate returned.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task GetConversionRateAsync(Currency from, Currency to, System.DateTimeOffset? date, System.Threading.CancellationToken cancellationToken)
{
if (from == null)
throw new System.ArgumentNullException("from");
if (to == null)
throw new System.ArgumentNullException("to");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/currencies?");
urlBuilder_.Append(System.Uri.EscapeDataString("from") + "=").Append(System.Uri.EscapeDataString(ConvertToString(from, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
urlBuilder_.Append(System.Uri.EscapeDataString("to") + "=").Append(System.Uri.EscapeDataString(ConvertToString(to, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
if (date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("date") + "=").Append(System.Uri.EscapeDataString(date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
urlBuilder_.Length--;
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// List all document blocks
///
///
/// Returns a list of your document blocks. The document blocks are returned sorted by creation date, with the most recent document blocks appearing first.
///
/// Filter document blocks by type
/// Success response
/// A server side error occurred.
public virtual System.Threading.Tasks.Task ListDocumentBlockAsync(int? page, int? per_page, DocumentBlockType? type)
{
return ListDocumentBlockAsync(page, per_page, type, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// List all document blocks
///
///
/// Returns a list of your document blocks. The document blocks are returned sorted by creation date, with the most recent document blocks appearing first.
///
/// Filter document blocks by type
/// Success response
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task ListDocumentBlockAsync(int? page, int? per_page, DocumentBlockType? type, System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/document-blocks?");
if (page != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("page") + "=").Append(System.Uri.EscapeDataString(ConvertToString(page, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (per_page != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("per_page") + "=").Append(System.Uri.EscapeDataString(ConvertToString(per_page, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (type != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("type") + "=").Append(System.Uri.EscapeDataString(ConvertToString(type, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
urlBuilder_.Length--;
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Create document export.
///
///
/// Return with the id of the export.
///
/// Create document export body.
/// Export job ID returned.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task CreateAsync(CreateDocumentExport body)
{
return CreateAsync(body, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Create document export.
///
///
/// Return with the id of the export.
///
/// Create document export body.
/// Export job ID returned.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task CreateAsync(CreateDocumentExport body, System.Threading.CancellationToken cancellationToken)
{
if (body == null)
throw new System.ArgumentNullException("body");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/document-export");
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = System.Text.Json.JsonSerializer.Serialize(body, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 201)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Return exported binary file.
///
///
/// Return the exported file.
///
/// The ID from create document export endpoint.
/// Document export file.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task DownloadAsync(string id)
{
return DownloadAsync(id, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Return exported binary file.
///
///
/// Return the exported file.
///
/// The ID from create document export endpoint.
/// Document export file.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task DownloadAsync(string id, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/document-export/{id}/download");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/*"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200 || status_ == 206)
{
var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false);
var fileResponse_ = new FileResponse(status_, headers_, responseStream_, null, response_);
disposeClient_ = false;
disposeResponse_ = false; // response and client are disposed by FileResponse
return fileResponse_;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 404)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Non-existent resource is requested.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Retrieve export state.
///
///
/// Return state of the given export.
///
/// The ID from create document export endpoint.
/// Export job status returned.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task PollAsync(string id)
{
return PollAsync(id, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Retrieve export state.
///
///
/// Return state of the given export.
///
/// The ID from create document export endpoint.
/// Export job status returned.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task PollAsync(string id, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/document-export/{id}/poll");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 404)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Non-existent resource is requested.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// List all documents
///
///
/// Returns a list of your documents. The documents are returned sorted by creation date, with the most recent documents appearing first.
///
/// Filter documents by the identifier of your DocumentBlock.
/// Filter documents by the identifier of your Partner.
/// Filter documents by PaymentMethod value.
/// Filter documents by PaymentStatus value.
/// Filter documents by their invoice date.
/// Filter documents by their invoice date.
/// Starting number of the document, should not contain year or any other formatting. Required if `start_year` given
/// Ending number of the document, should not contain year or any other formatting. Required if `end_year` given
/// Year for `start_number` parameter. Required if `start_number` given.
/// Year for `end_number` parameter. Required if `end_number` given.
/// Filter documents by type
/// Filter documents by the given text
/// Filter documents by their payment date.
/// Filter documents by their payment date.
/// Filter documents by their fulfillment date.
/// Filter documents by their fulfillment date.
/// Filter documents by their last modified date.
/// Success response
/// A server side error occurred.
public virtual System.Threading.Tasks.Task ListDocumentAsync(int? page, int? per_page, int? block_id, int? partner_id, PaymentMethod? payment_method, PaymentStatus? payment_status, System.DateTimeOffset? start_date, System.DateTimeOffset? end_date, int? start_number, int? end_number, int? start_year, int? end_year, DocumentType? type, string query, System.DateTimeOffset? paid_start_date, System.DateTimeOffset? paid_end_date, System.DateTimeOffset? fulfillment_start_date, System.DateTimeOffset? fulfillment_end_date, string last_modified_date)
{
return ListDocumentAsync(page, per_page, block_id, partner_id, payment_method, payment_status, start_date, end_date, start_number, end_number, start_year, end_year, type, query, paid_start_date, paid_end_date, fulfillment_start_date, fulfillment_end_date, last_modified_date, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// List all documents
///
///
/// Returns a list of your documents. The documents are returned sorted by creation date, with the most recent documents appearing first.
///
/// Filter documents by the identifier of your DocumentBlock.
/// Filter documents by the identifier of your Partner.
/// Filter documents by PaymentMethod value.
/// Filter documents by PaymentStatus value.
/// Filter documents by their invoice date.
/// Filter documents by their invoice date.
/// Starting number of the document, should not contain year or any other formatting. Required if `start_year` given
/// Ending number of the document, should not contain year or any other formatting. Required if `end_year` given
/// Year for `start_number` parameter. Required if `start_number` given.
/// Year for `end_number` parameter. Required if `end_number` given.
/// Filter documents by type
/// Filter documents by the given text
/// Filter documents by their payment date.
/// Filter documents by their payment date.
/// Filter documents by their fulfillment date.
/// Filter documents by their fulfillment date.
/// Filter documents by their last modified date.
/// Success response
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task ListDocumentAsync(int? page, int? per_page, int? block_id, int? partner_id, PaymentMethod? payment_method, PaymentStatus? payment_status, System.DateTimeOffset? start_date, System.DateTimeOffset? end_date, int? start_number, int? end_number, int? start_year, int? end_year, DocumentType? type, string query, System.DateTimeOffset? paid_start_date, System.DateTimeOffset? paid_end_date, System.DateTimeOffset? fulfillment_start_date, System.DateTimeOffset? fulfillment_end_date, string last_modified_date, System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/documents?");
if (page != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("page") + "=").Append(System.Uri.EscapeDataString(ConvertToString(page, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (per_page != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("per_page") + "=").Append(System.Uri.EscapeDataString(ConvertToString(per_page, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (block_id != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("block_id") + "=").Append(System.Uri.EscapeDataString(ConvertToString(block_id, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (partner_id != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("partner_id") + "=").Append(System.Uri.EscapeDataString(ConvertToString(partner_id, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (payment_method != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("payment_method") + "=").Append(System.Uri.EscapeDataString(ConvertToString(payment_method, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (payment_status != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("payment_status") + "=").Append(System.Uri.EscapeDataString(ConvertToString(payment_status, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (start_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("start_date") + "=").Append(System.Uri.EscapeDataString(start_date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (end_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("end_date") + "=").Append(System.Uri.EscapeDataString(end_date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (start_number != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("start_number") + "=").Append(System.Uri.EscapeDataString(ConvertToString(start_number, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (end_number != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("end_number") + "=").Append(System.Uri.EscapeDataString(ConvertToString(end_number, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (start_year != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("start_year") + "=").Append(System.Uri.EscapeDataString(ConvertToString(start_year, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (end_year != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("end_year") + "=").Append(System.Uri.EscapeDataString(ConvertToString(end_year, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (type != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("type") + "=").Append(System.Uri.EscapeDataString(ConvertToString(type, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (query != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("query") + "=").Append(System.Uri.EscapeDataString(ConvertToString(query, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (paid_start_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("paid_start_date") + "=").Append(System.Uri.EscapeDataString(paid_start_date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (paid_end_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("paid_end_date") + "=").Append(System.Uri.EscapeDataString(paid_end_date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (fulfillment_start_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("fulfillment_start_date") + "=").Append(System.Uri.EscapeDataString(fulfillment_start_date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (fulfillment_end_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("fulfillment_end_date") + "=").Append(System.Uri.EscapeDataString(fulfillment_end_date.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
if (last_modified_date != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("last_modified_date") + "=").Append(System.Uri.EscapeDataString(ConvertToString(last_modified_date, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}
urlBuilder_.Length--;
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Create a document
///
///
/// Create a new document. Returns a document object if the create is succeded.
///
/// DocumentInsert object that you would like to store.
/// Document created successfully.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task CreateDocumentAsync(DocumentInsert body)
{
return CreateDocumentAsync(body, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Create a document
///
///
/// Create a new document. Returns a document object if the create is succeded.
///
/// DocumentInsert object that you would like to store.
/// Document created successfully.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task CreateDocumentAsync(DocumentInsert body, System.Threading.CancellationToken cancellationToken)
{
if (body == null)
throw new System.ArgumentNullException("body");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/documents");
var client_ = _httpClient;
await AddApiKeyToHeader(client_);
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = System.Text.Json.JsonSerializer.Serialize(body, _settings.Value);
Console.WriteLine(json_);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
Console.WriteLine(response_);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 201)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
private async Task AddApiKeyToHeader(HttpClient client_)
{
var storeId = await _storeContext.GetActiveStoreScopeConfigurationAsync();
var settings = await _settingService.LoadSettingAsync(storeId);
client_.DefaultRequestHeaders.Where(s => s.Key == "X-API-KEY").ToList().ForEach(f => client_.DefaultRequestHeaders.Remove(f.Key));
client_.DefaultRequestHeaders.Add("X-API-KEY", settings.ApiKey);
}
///
/// Create a receipt
///
///
/// Create a new receipt. Returns a document object if the create is succeded.
///
/// ReceiptInsert object that you would like to store.
/// Receipt created successfully.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task CreateReceiptAsync(ReceiptInsert body)
{
return CreateReceiptAsync(body, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Create a receipt
///
///
/// Create a new receipt. Returns a document object if the create is succeded.
///
/// ReceiptInsert object that you would like to store.
/// Receipt created successfully.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task CreateReceiptAsync(ReceiptInsert body, System.Threading.CancellationToken cancellationToken)
{
if (body == null)
throw new System.ArgumentNullException("body");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/documents/receipt");
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = System.Text.Json.JsonSerializer.Serialize(body, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 201)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Converts a draft to a receipt.
///
///
/// Converts a draft to a receipt. Returns the receipt object if the convert is succeded.
///
/// ReceiptInsert object that you would like to store.
/// Draft converted successfully.
/// A server side error occurred.
public virtual System.Threading.Tasks.Task CreateReceiptFromDraftAsync(int id, ReceiptInsert body)
{
return CreateReceiptFromDraftAsync(id, body, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Converts a draft to a receipt.
///
///
/// Converts a draft to a receipt. Returns the receipt object if the convert is succeded.
///
/// ReceiptInsert object that you would like to store.
/// Draft converted successfully.
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task CreateReceiptFromDraftAsync(int id, ReceiptInsert body, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
if (body == null)
throw new System.ArgumentNullException("body");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/documents/receipt/{id}");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = System.Text.Json.JsonSerializer.Serialize(body, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("PUT");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 403)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have access to the resource.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 404)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Non-existent resource is requested.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Retrieve a document by vendor id
///
///
/// Retrieves the details of an existing document by vendor id.
///
/// Success response
/// A server side error occurred.
public virtual System.Threading.Tasks.Task GetDocumentByVendorIdAsync(string vendor_id)
{
return GetDocumentByVendorIdAsync(vendor_id, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Retrieve a document by vendor id
///
///
/// Retrieves the details of an existing document by vendor id.
///
/// Success response
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task GetDocumentByVendorIdAsync(string vendor_id, System.Threading.CancellationToken cancellationToken)
{
if (vendor_id == null)
throw new System.ArgumentNullException("vendor_id");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/documents/vendor/{vendor_id}");
urlBuilder_.Replace("{vendor_id}", System.Uri.EscapeDataString(ConvertToString(vendor_id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authorization information is missing or invalid.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 402)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Authenticated user doesn\'t have subscription.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Validation errors occured.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 429)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Too many requests", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 500)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("Internal server error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}
///
/// Retrieve a document
///
///
/// Retrieves the details of an existing document.
///
/// Success response
/// A server side error occurred.
public virtual System.Threading.Tasks.Task GetDocumentAsync(int id)
{
return GetDocumentAsync(id, System.Threading.CancellationToken.None);
}
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
///
/// Retrieve a document
///
///
/// Retrieves the details of an existing document.
///
/// Success response
/// A server side error occurred.
public virtual async System.Threading.Tasks.Task GetDocumentAsync(int id, System.Threading.CancellationToken cancellationToken)
{
if (id == null)
throw new System.ArgumentNullException("id");
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/documents/{id}");
urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}
ProcessResponse(client_, response_);
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 400)
{
var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException("The request is malformed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
if (status_ == 401)
{
var objectResponse_ = await ReadObjectResponseAsync