Example #1
0
        /// <summary>
        /// Updates the customer's information.
        /// </summary>
        /// <param name="customer">The customer information to be updated. The <see cref="Customer.Gid"/> or <see cref="Customer.ExternalId"/> field must be set, since they contain the id of the customer. The <see cref="Customer.Country"/> field is mandatory.</param>
        /// <returns>The up-to-date updated customer information</returns>
        /// <exception cref="IcException">On bad json (sent or received) and when the server rejects the request (conflict, bad request, invalid parameters, etc)</exception>
        /// <exception cref="WebException">On connection or protocol related errors (except for the protocol errors sent by the Invisible Collector)</exception>
        /// <seealso cref="GetCustomerInfoAsync"/>
        /// <seealso cref="SetNewCustomerAsync"/>
        /// <seealso cref="Customer.RoutableId"/>
        public async Task <Customer> SetCustomerInfoAsync(Customer customer)
        {
            var id = HttpUriBuilder.NormalizeUriComponent(customer.RoutableId);

            customer.AssertHasMandatoryFields(Customer.CountryName);
            _logger.LogDebug("Making a request to update the customer's with ID: {Id} information: {Model}", customer.RoutableId, customer);
            var ret = await MakeRequestAsync <Customer, object>("PUT", customer.SendableDictionary, CustomersEndpoint, id);

            _logger.LogDebug("Updated for the customer with ID: {Id} information: {Model}", customer.RoutableId, ret);
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Get a list of the customer's debts
        /// </summary>
        /// <param name="customerId">The ID of the customer whose debts are to be retrieved. It can be the 'gid' or 'externalId' of the customer (or just use <see cref="Customer.RoutableId"/>)</param>
        /// <returns>The up-to-date list of debts</returns>
        /// <exception cref="IcException">On bad json (sent or received) and when the server rejects the request (conflict, bad request, invalid parameters, etc)</exception>
        /// <exception cref="WebException">On connection or protocol related errors (except for the protocol errors sent by the Invisible Collector)</exception>
        /// <seealso cref="SetNewDebtAsync"/>
        public async Task <IList <Debt> > GetCustomerDebtsAsync(string customerId)
        {
            const string customerDebtsPath = "debts";

            _logger.LogDebug("Making a request to get customer debts for customer ID: {Id}", customerId);
            var id  = HttpUriBuilder.NormalizeUriComponent(customerId);
            var ret = await MakeBodylessRequestAsync <List <Debt> >("GET", CustomersEndpoint, id, customerDebtsPath);

            _logger.LogDebug("Received for customer with id: {Id} debts: {Models}", customerId, ret.StringifyList());
            return(ret);
        }
Example #3
0
        /// <summary>
        /// Updates the customer's attributes
        /// </summary>
        /// <remarks>
        /// <para>Any previously existing attributes won't be deleted, existing attributes will be updated and not-previously existing attributes will be created.</para>
        /// </remarks>
        /// <param name="customerId">The ID of the customer whose information is to be retrieved. It can be the 'gid' or 'externalId' of the customer (or just use <see cref="Customer.RoutableId"/>)</param>
        /// <param name="attributes">The attributes to be set</param>
        /// <returns>All of the customer's up-to-date updated attributes</returns>
        /// <exception cref="IcException">On bad json (sent or received) and when the server rejects the request (conflict, bad request, invalid parameters, etc)</exception>
        /// <exception cref="WebException">On connection or protocol related errors (except for the protocol errors sent by the Invisible Collector)</exception>
        /// <seealso cref="GetCustomerAttributesAsync"/>
        public async Task <IDictionary <string, string> > SetCustomerAttributesAsync(string customerId,
                                                                                     IDictionary <string, string> attributes)
        {
            var id = HttpUriBuilder.NormalizeUriComponent(customerId);

            _logger.LogDebug("Making a request to set or update the customer's with ID: {Id} attributes: {Attributes}", customerId, attributes.StringifyDictionary());
            var ret = await MakeRequestAsync <Dictionary <string, string>, string>("POST", attributes, CustomersEndpoint, id,
                                                                                   CustomersAttributesPath);

            _logger.LogDebug("Updated for the customer with ID: {Id} attributes: {Attributes}", customerId, ret.StringifyDictionary());
            return(ret);
        }