public void DisconnectNumbersWithDefaultClientTest() { var data = new DisconnectTelephoneNumberOrder { Name = "order", DisconnectTelephoneNumberOrderType = new DisconnectTelephoneNumberOrderType { TelephoneNumbers = new[] { "111", "222" } } }; using (var server = new HttpServer(new RequestHandler { EstimatedMethod = "POST", EstimatedPathAndQuery = string.Format("/v1.0/accounts/{0}/disconnects", Helper.AccountId), EstimatedContent = Helper.ToXmlString(data) })) { Disconnect.Create("order", "111", "222").Wait(); if (server.Error != null) { throw server.Error; } } }
static void Main(string[] args) { Console.WriteLine("Starting the Phone Number Ordering App"); useHttp(true); //not https port("8080"); startServerInstance(); post("/subscriptions/orders", (EagleRequest request, HttpListenerResponse response) => { XmlSerializer serializer = new XmlSerializer(typeof(Notification)); Notification notification = (Notification)serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(request.Body))); Console.WriteLine(notification.Status); Console.WriteLine(notification.Message); }); post("/subscriptions/disconnects", (EagleRequest request, HttpListenerResponse response) => { XmlSerializer serializer = new XmlSerializer(typeof(Notification)); Notification notification = (Notification)serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(request.Body))); Console.WriteLine(notification.Status); Console.WriteLine(notification.Message); var phoneNumber = notification.CompletedTelephoneNumbers[0]; storage.Remove(phoneNumber); }); get("/availablePhoneNumbers", (EagleRequest request, HttpListenerResponse response) => { var queryParams = request.RawRequest.QueryString; var query = new Dictionary <string, object>() { { "quantity", 10 }, }; if (queryParams.Get("zipCode") != null) { query.Add("zip", queryParams.Get("zipCode")); } if (queryParams.Get("areaCode") != null) { query.Add("areaCode", queryParams.Get("areaCode")); } try { var res = AvailableNumbers.List(client, query).Result; return(res.TelephoneNumberList); } catch (AggregateException ex) { if (ex.InnerException is BandwidthIrisException) { response.StatusCode = 400; BandwidthIrisException irisEx = (BandwidthIrisException)ex.InnerException; return(new Error { BandwidthErrorCode = irisEx.Code, BandwidthErrorDescription = irisEx.Body.ToString(), Description = "Bandwidth Invalid User Input", Type = "validation" }); } throw ex; } }); post("/phoneNumbers", (EagleRequest request, HttpListenerResponse response) => { string phoneNumber = request.Body.phoneNumber; if (storage.ContainsKey(phoneNumber)) { return(new Error { Type = "owned number", Description = "You have already ordered this number." }); } OrderResult orderResult; try { orderResult = Order.Create(client, new Order { CustomerOrderId = "customerOrderId", SiteId = SITE_ID, //The site to order the number for ExistingTelephoneNumberOrderType = new ExistingTelephoneNumberOrderType { TelephoneNumberList = new string[] { phoneNumber } } }).Result; } catch (AggregateException ex) { if (ex.InnerException is BandwidthIrisException) { response.StatusCode = 400; BandwidthIrisException irisEx = (BandwidthIrisException)ex.InnerException; return(new Error { BandwidthErrorCode = irisEx.Code, BandwidthErrorDescription = irisEx.Body.ToString(), Description = "Bandwidth Invalid User Input", Type = "validation" }); } throw ex; } var orderIdentifier = new OrderIdentifier { OrderId = orderResult.Order.OrderId, PhoneNumber = phoneNumber }; storage.Add(phoneNumber, orderIdentifier); response.StatusCode = 201; return(orderIdentifier); }); get("/phoneNumbers", (EagleRequest request, HttpListenerResponse response) => { return(storage.Values); }); delete("/phoneNumbers/{phoneNumber}", (EagleRequest request, HttpListenerResponse response) => { string phoneNumber = request.PathInfo.PathParameters.phoneNumber; if (!storage.ContainsKey(phoneNumber)) { response.StatusCode = 404; return(new Error { Description = "This number has not ordered yet, cannot remove.", Type = "not found" }); } try { Disconnect.Create(client, "orderName", phoneNumber); } catch (AggregateException ex) { if (ex.InnerException is BandwidthIrisException) { response.StatusCode = 400; BandwidthIrisException irisEx = (BandwidthIrisException)ex.InnerException; return(new Error { BandwidthErrorCode = irisEx.Code, BandwidthErrorDescription = irisEx.Body.ToString(), Description = "Bandwidth Invalid User Input", Type = "validation" }); } throw ex; } response.StatusCode = 201; return(new Dictionary <string, bool>() { { "Recieved", true } }); }); post("/stop", (EagleRequest request, HttpListenerResponse response) => { stop(); return("Server Shutting Down"); }); Console.WriteLine("Server is Ready!!!!!!!!!"); WaitOnServerToStop(); }
static async Task disconnectNumbers(Client client, string name, string[] numbersToDisconnect) { await Disconnect.Create(client, name, numbersToDisconnect); Console.WriteLine("Disconnected"); }