示例#1
0
        internal async Task EnableMms(IrisAuthData authData, MmsOptions options, MessagingApplication application,
                                      CancellationToken?cancellationToken = null)
        {
            if (options == null || !options.Enabled)
            {
                return;
            }
            var xml = new XDocument(
                new XElement("MmsFeature",
                             new XElement("MmsSettings",
                                          new XElement("protocol", "HTTP")
                                          ),
                             new XElement("Protocols",
                                          new XElement("HTTP",
                                                       new XElement("HttpSettings",
                                                                    new XElement("ProxyPeerId", "539692")
                                                                    )
                                                       )
                                          )
                             )
                );

            await MakeRequestAsync(authData, HttpMethod.Post,
                                   $"/sites/{authData.SubaccountId}/sippeers/{application.LocationId}/products/messaging/features/mms", xml, true,
                                   cancellationToken);
        }
示例#2
0
        internal async Task EnableSms(IrisAuthData authData, SmsOptions options, MessagingApplication application,
                                      CancellationToken?cancellationToken = null)
        {
            if (options == null || !options.Enabled)
            {
                return;
            }
            var xml = new XDocument(
                new XElement("SipPeerSmsFeature",
                             new XElement("SipPeerSmsFeatureSettings",
                                          new XElement("TollFree", options.TollFreeEnabled),
                                          new XElement("ShortCode", options.ShortCodeEnabled),
                                          new XElement("Protocol", "HTTP"),
                                          new XElement("Zone1", true),
                                          new XElement("Zone2", false),
                                          new XElement("Zone3", false),
                                          new XElement("Zone4", false),
                                          new XElement("Zone5", false)
                                          ),
                             new XElement("HttpSettings",
                                          new XElement("ProxyPeerId", "539692")
                                          )
                             )
                );

            await MakeRequestAsync(authData, HttpMethod.Post,
                                   $"/sites/{authData.SubaccountId}/sippeers/{application.LocationId}/products/messaging/features/sms", xml, true,
                                   cancellationToken);
        }
示例#3
0
        internal async Task AssignApplicationToLocation(IrisAuthData authData, MessagingApplication application,
                                                        CancellationToken?cancellationToken = null)
        {
            var xml = new XDocument(
                new XElement("ApplicationsSettings",
                             new XElement("HttpMessagingV2AppId", application.ApplicationId)
                             )
                );

            await MakeRequestAsync(authData, HttpMethod.Put,
                                   $"/sites/{authData.SubaccountId}/sippeers/{application.LocationId}/products/messaging/applicationSettings", xml,
                                   true, cancellationToken);
        }
示例#4
0
        public async Task <MessagingApplication> CreateMessagingApplicationAsync(IrisAuthData authData,
                                                                                 CreateMessagingApplicationData data, CancellationToken?cancellationToken = null)
        {
            var app = new MessagingApplication
            {
                ApplicationId = await CreateApplication(authData, data, cancellationToken),
                LocationId    = await CreateLocation(authData, data, cancellationToken)
            };

            await EnableSms(authData, data.SmsOptions, app, cancellationToken);
            await EnableMms(authData, data.MmsOptions, app, cancellationToken);
            await AssignApplicationToLocation(authData, app, cancellationToken);

            return(app);
        }
示例#5
0
        public async Task <string[]> SearchAndOrderNumbersAsync(IrisAuthData authData, MessagingApplication application,
                                                                SearchAndOrderNumbersQuery query, CancellationToken?cancellationToken = null)
        {
            var xml = new XDocument(
                new XElement("Order", query.ToXElement(),
                             new XElement("SiteId", authData.SubaccountId),
                             new XElement("PeerId", application.LocationId))
                );

            var(doc, _) = await MakeRequestAsync(authData, HttpMethod.Post, "/orders", xml, true, cancellationToken);

            var orderId         = doc.Descendants("Order").First().Element("id").Value;
            var successStatuses = new[] { "COMPLETE", "PARTIAL" };
            var stopwatch       = Stopwatch.StartNew();

            try
            {
                while (true)
                {
                    await Task.Delay(500, cancellationToken ?? default(CancellationToken));

                    if (stopwatch.Elapsed >= query.Timeout)
                    {
                        throw new TimeoutException();
                    }
                    var(result, _) = await MakeRequestAsync(authData, HttpMethod.Get, $"/orders/{orderId}", null, true,
                                                            cancellationToken);

                    var status = (result.Descendants("OrderStatus").FirstOrDefault() ?? new XElement("OrderStatus")).Value;
                    if (successStatuses.Contains(status))
                    {
                        return((result.Descendants("CompletedNumbers").FirstOrDefault() ?? new XElement("CompletedNumbers"))
                               .Descendants("FullNumber").Select(n => n.Value).ToArray());
                    }
                    if (status == "FAILED")
                    {
                        throw new BandwidthException("Error on reserving phone numbers", HttpStatusCode.BadRequest);
                    }
                }
            }
            finally
            {
                stopwatch.Stop();
            }
        }