Exemplo n.º 1
0
        internal PurchasedPhoneNumber(string id, string phoneNumber, string countryCode, PhoneNumberType phoneNumberType, PhoneNumberCapabilities capabilities, PhoneNumberAssignmentType assignmentType, DateTimeOffset purchaseDate, PhoneNumberCost cost)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (phoneNumber == null)
            {
                throw new ArgumentNullException(nameof(phoneNumber));
            }
            if (countryCode == null)
            {
                throw new ArgumentNullException(nameof(countryCode));
            }
            if (capabilities == null)
            {
                throw new ArgumentNullException(nameof(capabilities));
            }
            if (cost == null)
            {
                throw new ArgumentNullException(nameof(cost));
            }

            Id              = id;
            PhoneNumber     = phoneNumber;
            CountryCode     = countryCode;
            PhoneNumberType = phoneNumberType;
            Capabilities    = capabilities;
            AssignmentType  = assignmentType;
            PurchaseDate    = purchaseDate;
            Cost            = cost;
        }
        internal PhoneNumberSearchResult(string searchId, IEnumerable <string> phoneNumbers, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, PhoneNumberCapabilities capabilities, PhoneNumberCost cost, DateTimeOffset searchExpiresOn)
        {
            if (searchId == null)
            {
                throw new ArgumentNullException(nameof(searchId));
            }
            if (phoneNumbers == null)
            {
                throw new ArgumentNullException(nameof(phoneNumbers));
            }
            if (capabilities == null)
            {
                throw new ArgumentNullException(nameof(capabilities));
            }
            if (cost == null)
            {
                throw new ArgumentNullException(nameof(cost));
            }

            SearchId        = searchId;
            PhoneNumbers    = phoneNumbers.ToList();
            PhoneNumberType = phoneNumberType;
            AssignmentType  = assignmentType;
            Capabilities    = capabilities;
            Cost            = cost;
            SearchExpiresOn = searchExpiresOn;
        }
Exemplo n.º 3
0
        internal static PurchasedPhoneNumber DeserializePurchasedPhoneNumber(JsonElement element)
        {
            string                    id              = default;
            string                    phoneNumber     = default;
            string                    countryCode     = default;
            PhoneNumberType           phoneNumberType = default;
            PhoneNumberCapabilities   capabilities    = default;
            PhoneNumberAssignmentType assignmentType  = default;
            DateTimeOffset            purchaseDate    = default;
            PhoneNumberCost           cost            = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("phoneNumber"))
                {
                    phoneNumber = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("countryCode"))
                {
                    countryCode = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("phoneNumberType"))
                {
                    phoneNumberType = new PhoneNumberType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("capabilities"))
                {
                    capabilities = PhoneNumberCapabilities.DeserializePhoneNumberCapabilities(property.Value);
                    continue;
                }
                if (property.NameEquals("assignmentType"))
                {
                    assignmentType = new PhoneNumberAssignmentType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("purchaseDate"))
                {
                    purchaseDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("cost"))
                {
                    cost = PhoneNumberCost.DeserializePhoneNumberCost(property.Value);
                    continue;
                }
            }
            return(new PurchasedPhoneNumber(id, phoneNumber, countryCode, phoneNumberType, capabilities, assignmentType, purchaseDate, cost));
        }
 internal PhoneNumberSearchResult(string searchId, IReadOnlyList <string> phoneNumbers, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, PhoneNumberCapabilities capabilities, PhoneNumberCost cost, DateTimeOffset searchExpiresOn)
 {
     SearchId        = searchId;
     PhoneNumbers    = phoneNumbers;
     PhoneNumberType = phoneNumberType;
     AssignmentType  = assignmentType;
     Capabilities    = capabilities;
     Cost            = cost;
     SearchExpiresOn = searchExpiresOn;
 }
Exemplo n.º 5
0
        internal static PhoneNumberSearchResult DeserializePhoneNumberSearchResult(JsonElement element)
        {
            string searchId = default;
            IReadOnlyList <string>    phoneNumbers    = default;
            PhoneNumberType           phoneNumberType = default;
            PhoneNumberAssignmentType assignmentType  = default;
            PhoneNumberCapabilities   capabilities    = default;
            PhoneNumberCost           cost            = default;
            DateTimeOffset            searchExpiresBy = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("searchId"))
                {
                    searchId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("phoneNumbers"))
                {
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    phoneNumbers = array;
                    continue;
                }
                if (property.NameEquals("phoneNumberType"))
                {
                    phoneNumberType = new PhoneNumberType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("assignmentType"))
                {
                    assignmentType = new PhoneNumberAssignmentType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("capabilities"))
                {
                    capabilities = PhoneNumberCapabilities.DeserializePhoneNumberCapabilities(property.Value);
                    continue;
                }
                if (property.NameEquals("cost"))
                {
                    cost = PhoneNumberCost.DeserializePhoneNumberCost(property.Value);
                    continue;
                }
                if (property.NameEquals("searchExpiresBy"))
                {
                    searchExpiresBy = property.Value.GetDateTimeOffset("O");
                    continue;
                }
            }
            return(new PhoneNumberSearchResult(searchId, phoneNumbers, phoneNumberType, assignmentType, capabilities, cost, searchExpiresBy));
        }
Exemplo n.º 6
0
        public PhoneNumberSearchRequest(PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, PhoneNumberCapabilities capabilities)
        {
            if (capabilities == null)
            {
                throw new ArgumentNullException(nameof(capabilities));
            }

            PhoneNumberType = phoneNumberType;
            AssignmentType  = assignmentType;
            Capabilities    = capabilities;
        }
Exemplo n.º 7
0
        /// <summary> Search for available phone numbers to purchase. </summary>
        /// <param name="twoLetterIsoCountryName"> The ISO 3166-2 country code, e.g. US. </param>
        /// <param name="phoneNumberType"> The type of phone numbers to search for. </param>
        /// <param name="phoneNumberAssignmentType"> The assignment type of the phone numbers to search for. </param>
        /// <param name="capabilities"> Capabilities of a phone number. </param>
        /// <param name="options"> The phone number search options. </param>
        /// <param name="cancellationToken"> The cancellation token to use. </param>
        /// <exception cref="ArgumentNullException"> <paramref name="twoLetterIsoCountryName"/> is null. </exception>
        public virtual SearchAvailablePhoneNumbersOperation StartSearchAvailablePhoneNumbers(string twoLetterIsoCountryName, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType phoneNumberAssignmentType,
                                                                                             PhoneNumberCapabilities capabilities, PhoneNumberSearchOptions options = null, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(twoLetterIsoCountryName, nameof(twoLetterIsoCountryName));
            Argument.AssertNotNull(capabilities, nameof(capabilities));

            using var scope = _clientDiagnostics.CreateScope($"{nameof(PhoneNumbersClient)}.{nameof(StartSearchAvailablePhoneNumbers)}");
            scope.Start();
            try
            {
                var searchRequest = new PhoneNumberSearchRequest(phoneNumberType, phoneNumberAssignmentType, capabilities)
                {
                    AreaCode = options?.AreaCode, Quantity = options?.Quantity
                };
                var originalResponse = RestClient.SearchAvailablePhoneNumbers(twoLetterIsoCountryName, searchRequest, cancellationToken);
                return(new SearchAvailablePhoneNumbersOperation(_clientDiagnostics, _pipeline, RestClient.CreateSearchAvailablePhoneNumbersRequest(twoLetterIsoCountryName, searchRequest).Request, originalResponse));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemplo n.º 8
0
 public static PhoneNumberSearchResult PhoneNumberSearchResult(string searchId = default, IReadOnlyList <string> phoneNumbers = default, PhoneNumberType phoneNumberType = default, PhoneNumberAssignmentType assignmentType = default, PhoneNumberCapabilities capabilities = default, PhoneNumberCost cost = default, DateTimeOffset searchExpiresOn = default)
 {
     phoneNumbers ??= new List <string>();
     return(new PhoneNumberSearchResult(searchId, phoneNumbers, phoneNumberType, assignmentType, capabilities, cost, searchExpiresOn));
 }
Exemplo n.º 9
0
 /// <summary> Initializes a new instance of PhoneNumberSearchResult. </summary>
 /// <param name="searchId"> The search id. </param>
 /// <param name="phoneNumbers"> The phone numbers that are available. Can be fewer than the desired search quantity. </param>
 /// <param name="phoneNumberType"> The phone number&apos;s type, e.g. geographic, or tollFree. </param>
 /// <param name="assignmentType"> Phone number&apos;s assignment type. </param>
 /// <param name="capabilities"> Capabilities of a phone number. </param>
 /// <param name="cost"> The incurred cost for a single phone number. </param>
 /// <param name="searchExpiresOn"> The date that this search result expires and phone numbers are no longer on hold. A search result expires in less than 15min, e.g. 2020-11-19T16:31:49.048Z. </param>
 /// <exception cref="ArgumentNullException"> <paramref name="searchId"/>, <paramref name="phoneNumbers"/>, <paramref name="capabilities"/>, or <paramref name="cost"/> is null. </exception>
 public static PhoneNumberSearchResult PhoneNumberSearchResult(string searchId, IEnumerable <string> phoneNumbers, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, PhoneNumberCapabilities capabilities, PhoneNumberCost cost, DateTimeOffset searchExpiresOn)
 => new PhoneNumberSearchResult(searchId, phoneNumbers, phoneNumberType, assignmentType, capabilities, cost, searchExpiresOn);
Exemplo n.º 10
0
        /// <summary> Initializes a new instance of <see cref="PurchasedPhoneNumber"/>. </summary>
        /// <param name="id"> The id of the phone number, e.g. 14255550123. </param>
        /// <param name="phoneNumber"> String of the E.164 format of the phone number, e.g. +14255550123. </param>
        /// <param name="countryCode"> The ISO 3166-2 code of the phone number&apos;s country, e.g. US. </param>
        /// <param name="phoneNumberType"> The phone number&apos;s type, e.g. Geographic, TollFree. </param>
        /// <param name="capabilities"> Capabilities of a phone number. </param>
        /// <param name="assignmentType"> The assignment type of the phone number. A phone number can be assigned to a person, or to an application. </param>
        /// <param name="purchaseDate"> The date and time that the phone number was purchased. </param>
        /// <param name="cost"> The incurred cost for a single phone number. </param>
#pragma warning disable CA1054 // URI-like parameters should not be strings
        public static PurchasedPhoneNumber PurchasedPhoneNumber(string id, string phoneNumber, string countryCode, PhoneNumberType phoneNumberType, PhoneNumberCapabilities capabilities, PhoneNumberAssignmentType assignmentType, DateTimeOffset purchaseDate, PhoneNumberCost cost)
#pragma warning restore CA1054 // URI-like parameters should not be strings
        => new PurchasedPhoneNumber(id, phoneNumber, countryCode, phoneNumberType, capabilities, assignmentType, purchaseDate, cost);