/// <summary> /// List the synchronizations by account and optionnally filter by a date window. /// </summary> /// <param name="customerAccountId">The customer account identifier.</param> /// <param name="startDate"> The start date filter.</param> /// <param name="endDate">The end date filter.</param> /// <returns></returns> public List <Synchronization> ListSynchronizationsByAccount(string customerAccountId, DateTime?startDate = null, DateTime?endDate = null) { if (string.IsNullOrEmpty(customerAccountId)) { throw new ApiClientHttpException((int)System.Net.HttpStatusCode.BadRequest, "CustomerAccountId missing."); } var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/{2}/synchronizations", _apiVersion, _path, customerAccountId)); string startDateString = null; string endDateString = null; if (startDate != null) { startDateString = Uri.EscapeDataString(startDate.Value.ToUniversalTime().ToString("u")); } if (endDate != null) { endDateString = Uri.EscapeDataString(endDate.Value.ToUniversalTime().ToString("u")); } requestUri = requestUri.AddQueryParameter("startDate", startDateString); requestUri = requestUri.AddQueryParameter("endDate", endDateString); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Synchronization> >()); }
/// <summary> /// Searches the synchronizations. /// </summary> /// <param name="customerAccountId">The customer account identifier.</param> /// <param name="customerUserId">The customer user identifier.</param> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <returns></returns> public List <Synchronization> SearchSynchronizations(string customerAccountId = null, string customerUserId = null, DateTime?startDate = null, DateTime?endDate = null) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/search", _apiVersion, _path)); string startDateString = null; string endDateString = null; if (startDate != null) { startDateString = Uri.EscapeDataString(startDate.Value.ToUniversalTime().ToString("u")); } if (endDate != null) { endDateString = Uri.EscapeDataString(endDate.Value.ToUniversalTime().ToString("u")); } requestUri = requestUri.AddQueryParameter("startDate", startDateString); requestUri = requestUri.AddQueryParameter("endDate", endDateString); requestUri = requestUri.AddQueryParameter("customerAccountId", customerAccountId); requestUri = requestUri.AddQueryParameter("customerUserId", customerUserId); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Synchronization> >()); }
/// <summary> /// Searches accounts by customer user identifier and/or by customer account identifier. /// </summary> /// <param name="customerAccountId">The identifier of the account to be able to filter by account.</param> /// <param name="customerUserId">The identifier of the user to be able to filter by user.</param> /// <returns></returns> public List <Account> SearchAccounts(string customerAccountId = null, string customerUserId = null) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/{2}/search", _apiVersion, _path, customerUserId)); requestUri = requestUri.AddQueryParameter("customerAccountId", customerAccountId); requestUri = requestUri.AddQueryParameter("customerUserId", customerUserId); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Account> >()); }
private Uri GetCustomersRequestUri(int page) { var request = new Uri($"{BaseApiUrl}customers"); request.AddQueryParameter("filter", "active"); request.AddQueryParameter("sortby", "customernumber"); request.AddQueryParameter("sortorder", "ascending"); request.AddQueryParameter("limit", PageSize.ToString()); request.AddQueryParameter("page", page.ToString()); return(request); }
/// <summary> /// Lists all available agents. /// </summary> /// <param name="culture">he culture of the returned information.</param> /// <param name="includeLogo">Specifies if the response should include the agents logo in base64 enconding.</param> /// <returns></returns> public List <Agent> ListAgents(string culture = null, bool includeLogo = false) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}", _apiVersion, _path)); requestUri = requestUri.AddQueryParameter("culture", culture); requestUri = requestUri.AddQueryParameter("includeLogo", includeLogo); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Agent> >()); }
/// <summary> /// Searches the documents. /// </summary> /// <param name="customerAccountId">The customer account identifier.</param> /// <param name="customerUserId">The customer user identifier.</param> /// <param name="pendingOnly">if set to <c>true</c> [pending only].</param> /// <param name="includeContent">if set to <c>true</c> [include content].</param> /// <returns></returns> public List <Document> SearchDocuments(string customerAccountId = null, string customerUserId = null, bool pendingOnly = false, bool includeContent = false) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/search", _apiVersion, _path)); requestUri = requestUri.AddQueryParameter("customerAccountId", customerAccountId); requestUri = requestUri.AddQueryParameter("customerUserId", customerUserId); requestUri = requestUri.AddQueryParameter("pendingOnly", pendingOnly); requestUri = requestUri.AddQueryParameter("includeContent", includeContent); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Document> >()); }
/// <summary> /// Lists accounts by bank. /// </summary> /// <param name="bankIdentifier">The bank identifier</param> /// <param name="skip">The number of accounts to skip (used for pagination).</param> /// <param name="take">The maximum number of accounts to be returned (used for pagination).</param> /// <returns></returns> public List <Account> ListAccountsByBank(string bankIdentifier, int skip = 0, int take = 0) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/banks/{1}/accounts", _apiVersion, bankIdentifier)); requestUri = requestUri.AddQueryParameter("skip", skip); if (take != 0) { requestUri = requestUri.AddQueryParameter("take", take); } var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Account> >()); }
/// <summary> /// Lists all accounts. /// </summary> /// <param name="agentId">The identifier of the agents to be able to filter by agent.</param> /// <param name="customerUserId">The customer user identifier to be able to filter accounts by user</param> /// <param name="skip">The number of accounts to skip (used for pagination).</param> /// <param name="take">The maximum number of accounts to be returned (used for pagination).</param> /// <returns></returns> public List <Account> ListAccounts(string agentId = null, string customerUserId = null, int skip = 0, int take = 0) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}", _apiVersion, _path)); requestUri = requestUri.AddQueryParameter("agentId", agentId); requestUri = requestUri.AddQueryParameter("customerUserId", customerUserId); requestUri = requestUri.AddQueryParameter("skip", skip); if (take != 0) { requestUri = requestUri.AddQueryParameter("take", take); } var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Account> >()); }
public Uri BindUrlQueryValue(Uri url, MethodInfo method, Expression[] arguments) { var key = (string)arguments[0].Resolve(); var value = (string)arguments[1].Resolve(); return(url.AddQueryParameter(key, value)); }
public void Change_Parameter() { Uri uri = new Uri("http://address.url/path/to/page.asp?query=value"); Uri uri2 = new Uri("http://address.url/path/to/page.asp?query=value2"); Assert.AreEqual(uri2, uri.AddQueryParameter("query", "value2")); }
/// <summary> /// Gets all documents for an account /// </summary> /// <param name="customerAccountId">The customer account identifier.</param> /// <param name="pendingOnly">Lists only the documents not delivered.</param> /// <param name="includeContent">Specifies if the response should include the document content in base64 enconding.</param> /// <returns>An array of Document objects</returns> public List <Document> ListDocumentsByAccount(string customerAccountId, bool pendingOnly = false, bool includeContent = false) { if (string.IsNullOrEmpty(customerAccountId)) { throw new ApiClientHttpException((int)System.Net.HttpStatusCode.BadRequest, "CustomerAccountId missing."); } var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/{2}/documents", _apiVersion, _path, customerAccountId)); requestUri = requestUri.AddQueryParameter("pendingOnly", pendingOnly); requestUri = requestUri.AddQueryParameter("includeContent", includeContent); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Document> >()); }
public static Uri AddQueryParameter <QueryType, TValue>(this Uri uri, Expression <Func <QueryType, TValue> > parameterExpr, IDictionary <string, string> values) { return(parameterExpr.PropertyName( (parameter) => { return values.Aggregate( new { src = uri, index = 0, }, (aggr, value) => { return new { src = uri .AddQueryParameter($"{parameter}[{aggr.index}].Key", value.Key) .AddQueryParameter($"{parameter}[{aggr.index}].Value", value.Value), index = aggr.index + 1, }; }, (aggr) => aggr.src); }, () => { throw new ArgumentException("Not a property expression", "parameterExpr"); })); }
/// <summary> /// Lists all available agents. /// </summary> /// <param name="countryCode">The desired agents country.</param> /// <param name="culture">The culture of the returned information.</param> /// <param name="includeLogo">Specifies if the response should include the agents logo encoded in base 64.</param> /// <param name="q">The query string that will filter agents starting with the defined prefix</param> /// <returns>A list of agents.</returns> public List <Agent> SearchAgent(AgentCountryCode?countryCode = null, string culture = null, bool includeLogo = false, string q = null) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/search", _apiVersion, _path)); if (countryCode != null) { requestUri = requestUri.AddQueryParameter("countryCode", ((int)countryCode).ToString()); } requestUri = requestUri.AddQueryParameter("culture", culture); requestUri = requestUri.AddQueryParameter("includeLogo", includeLogo); requestUri = requestUri.AddQueryParameter("culture", culture); requestUri = requestUri.AddQueryParameter("q", q); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Agent> >()); }
public static Uri AddQueryParameter <QueryType, TValue>(this Uri uri, Expression <Func <QueryType, TValue> > parameterExpr, string value) { return(parameterExpr.PropertyName( (parameter) => uri.AddQueryParameter(parameter, value), () => { throw new ArgumentException("Not a property expression", "parameterExpr"); })); }
private HttpRequestMessage GetInvoicesRequest(DateTime dateSinceUpserted, int page) { var requestUri = new Uri($"{BaseApiUrl}invoices"); requestUri.AddQueryParameter("sortby", "documentnumber"); requestUri.AddQueryParameter("sortorder", "ascending"); requestUri.AddQueryParameter("limit", PageSize.ToString()); requestUri.AddQueryParameter("page", page.ToString()); requestUri.AddQueryParameter("lastmodified", $"{dateSinceUpserted:yyyy-MM-dd HH:mm}"); var message = new HttpRequestMessage { RequestUri = requestUri, Method = HttpMethod.Get }; return(message); }
public static string CreateSwitchCompanyURL(string continueToPage, string hashedComapnyID, bool urlSession = false) { Uri uri = CreateURLOnAuthRootWithPath(PAGE_SWITCH_COMPANY); if (urlSession == true) { uri = uri.AddQueryParameter("urlSession", "true"); } if (string.IsNullOrWhiteSpace(continueToPage) == false) { uri = uri.AddQueryParameter("continueTo", System.Web.HttpUtility.UrlEncode(continueToPage)); } if (string.IsNullOrWhiteSpace(hashedComapnyID) == false) { uri = uri.AddQueryParameter("company", System.Web.HttpUtility.UrlEncode(hashedComapnyID)); } return(uri.ToString()); }
/// <summary> /// Lists accounts by agent. /// </summary> /// <param name="identifier">The identifier of the agents to be able to filter by agent.</param> /// <param name="skip">The number of accounts to skip (used for pagination).</param> /// <param name="take">The maximum number of accounts to be returned (used for pagination).</param> /// <returns>A list of accounts.</returns> public List <Account> ListAccountsByAgent(string identifier, int skip = 0, int take = 0) { if (string.IsNullOrEmpty(identifier)) { throw new ApiClientHttpException((int)System.Net.HttpStatusCode.BadRequest, "Agent Identifier missing."); } var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/{2}/accounts", _apiVersion, _path, identifier)); requestUri = requestUri.AddQueryParameter("skip", skip); if (take != 0) { requestUri = requestUri.AddQueryParameter("take", take); } var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Account> >()); }
/// <summary> /// Lists the agents categories. /// </summary> /// <param name="culture">The culture of the returned information.</param> /// <returns>A list of agent categories.</returns> public List <Category> ListCategories(string culture = null) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}", _apiVersion, _path)); requestUri = requestUri.AddQueryParameter("culture", culture); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <List <Category> >()); }
public static string CreateSignoutURL(string continueToPage) { Uri uri = CreateURLOnAuthRootWithPath(PAGE_SIGN_OUT); if (string.IsNullOrWhiteSpace(continueToPage) == false) { uri = uri.AddQueryParameter("continueTo", System.Web.HttpUtility.UrlEncode(continueToPage)); } return(uri.ToString()); }
/// <summary> /// Gets a specific document. /// </summary> /// <param name="id">The document identifier.</param> /// <param name="includeContent">Specifies if the response should include the document content encoded as base 64.</param> /// <returns>A Document object</returns> public Document GetDocument(int id, bool includeContent = true) { var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/{2}", _apiVersion, _path, id)); requestUri = requestUri.AddQueryParameter("includeContent", includeContent); var response = _authenticatedClient.HttpClient.ApiGet(requestUri); return(response.GetObjectFromResponse <Document>()); }
public static string CreateSignInURL(string continueToPage, int sessionLifetime, string languageISO = "EN", bool urlSession = false) { languageISO = (languageISO == null ? "en" : languageISO.ToLower()); Uri uri = CreateURLOnAuthRootWithPath(PAGE_SIGN_IN); if (string.IsNullOrWhiteSpace(continueToPage) == false) { uri = uri.AddQueryParameter("continueTo", System.Web.HttpUtility.UrlEncode(continueToPage)); } if (urlSession == true) { uri = uri.AddQueryParameter("urlSession", "true"); } if (sessionLifetime > 0) { uri = uri.AddQueryParameter("sessionTimeout", sessionLifetime.ToString()); } if (languageISO != "en") { uri = uri.AddQueryParameter("language", languageISO); } return(uri.ToString()); }
public static TResult SignWithAccessTokenAccount <TResult>(this Uri originalUrl, Guid sessionId, Guid accountId, DateTime expirationUtc, Func <Uri, TResult> onSuccess, Func <TResult> onSystemNotConfigured = default) { var expiresAfterEpoch = expirationUtc - GetEpoch(); var secondsAfterEpoch = (uint)expiresAfterEpoch.TotalSeconds; return(originalUrl.CreateSignature(sessionId, accountId, secondsAfterEpoch, (accessToken, signature) => { var accessTokenString = accessToken.ToBase64String(urlSafe: true); var accessTokenUrl = originalUrl.AddQueryParameter(QueryParameter, accessTokenString); return onSuccess(accessTokenUrl); }, onSystemNotConfigured)); }
public void Add_Parameter_Empty_Key() { Uri uri = new Uri("http://address.url/path/to/page.asp?query=value"); uri.AddQueryParameter("", "val"); }
public Uri BindUrlQueryValue(Uri url, MethodInfo method, Expression[] arguments) { return(method.TryParseMemberAssignment(arguments, (memberInfo, type, content) => { var queryParamName = GetParamName(); var queryParamValue = GetContent(type); return url.AddQueryParameter(queryParamName, queryParamValue); string GetParamName() { var apiBindings = memberInfo.GetAttributesInterface <IProvideApiValue>(true); if (apiBindings.Any()) { var apiBinding = apiBindings.First(); if (apiBinding.PropertyName.HasBlackSpace()) { return apiBinding.PropertyName; } } return memberInfo.Name; } string GetContent(ExpressionType expressionType) { if (expressionType == ExpressionType.Not) { if (content == null) { return "not(null)"; } var contentType = content.GetType(); if (contentType == typeof(bool)) { var boolContent = (bool)content; return (!boolContent).ToString(); } if (contentType == typeof(string)) { var stringContent = content as string; if (stringContent.ToLower() == "value") { return "null"; } if (stringContent.ToLower() == "not(null)") { return "null"; } if (stringContent.ToLower() == "null") { return "not(null)"; } return $"not({stringContent})"; } var innerContent = GetContent(ExpressionType.Equal); return $"not({innerContent})"; } var memberType = memberInfo.GetMemberType(); if (memberType.IsNullable()) { if (!content.NullableHasValue()) { return "null"; } memberType = memberType.GetNullableUnderlyingType(); content = content.GetNullableValue(); } if (typeof(string).IsAssignableFrom(memberType)) { return (string)content; } if (typeof(Guid).IsAssignableFrom(memberType)) { var contentId = (Guid)content; return contentId.ToString(); } if (memberType.IsSubClassOfGeneric(typeof(IReferenceable))) { if (content.IsDefaultOrNull()) { return string.Empty; } var contentType = content.GetType(); if (contentType.IsSubClassOfGeneric(typeof(IReferenceable))) { var contentRef = (IReferenceable)content; return contentRef.id.ToString(); } } if (memberType.IsSubClassOfGeneric(typeof(IReferenceableOptional))) { if (content.IsDefaultOrNull()) { return "null"; } var contentType = content.GetType(); if (contentType.IsSubClassOfGeneric(typeof(IReferenceableOptional))) { var contentRefOptional = (IReferenceableOptional)content; if (!contentRefOptional.HasValue) { return "empty"; } return contentRefOptional.id.Value.ToString(); } } if (typeof(DateTime).IsAssignableFrom(memberType)) { var contentDate = (DateTime)content; if (contentDate.Hour == 0 && contentDate.Minute == 0 && contentDate.Second == 0) { return contentDate.ToString("yyyy-MM-dd"); } return contentDate.ToString(); } if (memberType.IsNumeric()) { return content.ToString(); } if (typeof(Type) == memberType) { return (content as Type).GetCustomAttributes <FunctionViewControllerAttribute>() .First().ContentType; } throw new NotImplementedException(); } }, () => { throw new Exception(); })); }
public void Add_Query_Parameter_With_Query_Before() { Uri uri = new Uri("http://address.url/path/to/page.asp?query=value"); Assert.AreEqual("http://address.url/path/to/page.asp?query=value&added=value", uri.AddQueryParameter("added", "value").ToString()); }