public void should_send_standard_ni_request() { var resp = new Mock <IWebResponse>(); resp.Setup(e => e.GetResponseStream()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("{\"status\": 0,\"status_message\": \"Success\",\"request_id\": \"bcf255a4-047c-4364-89b1-d5cf76ffffff\",\"international_format_number\": \"15555551212\",\"national_format_number\": \"(555) 555-1212\",\"country_code\": \"US\",\"country_code_iso3\": \"USA\",\"country_name\": \"United States of America\",\"country_prefix\": \"1\",\"request_price\": \"0.00500000\",\"remaining_balance\": \"1.1\",\"current_carrier\": {\"network_code\": \"310004\",\"name\": \"Verizon Wireless\",\"country\": \"US\",\"network_type\": \"mobile\"},\"original_carrier\": {\"network_code\": \"310004\",\"name\": \"Verizon Wireless\",\"country\": \"US\",\"network_type\": \"mobile\"}}"))); var postDataStream = new MemoryStream(); _request.Setup(e => e.GetRequestStream()).Returns(postDataStream); _request.Setup(e => e.GetResponse()).Returns(resp.Object); var result = NumberInsight.RequestStandard(new NumberInsight.NumberInsightBasicRequest { number = "15555551212" }); _mock.Verify(h => h.CreateHttp(new Uri( string.Format("{0}/number/lookup/json", ApiUrl))), Times.Once); postDataStream.Position = 0; var sr = new StreamReader(postDataStream); var postData = sr.ReadToEnd(); Assert.AreEqual(string.Format("number=15555551212&api_key={0}&api_secret={1}&", ApiKey, ApiSecret), postData); Assert.AreEqual("0", result.status); Assert.AreEqual("15555551212", result.international_format_number); Assert.AreEqual("(555) 555-1212", result.national_format_number); Assert.AreEqual("Verizon Wireless", result.current_carrier.name); }
public ActionResult Standard(string number) { var results = NumberInsight.RequestStandard(new NumberInsight.NumberInsightBasicRequest() { number = number, }); Session["requestID"] = results.request_id; Session["iNumber"] = results.international_format_number; Session["nNumber"] = results.national_format_number; Session["country"] = results.country_name; Session["countryCode"] = results.country_code; Session["status"] = results.status_message; Session["currentCarrierName"] = results.original_carrier.name; Session["currentCarrierCode"] = results.current_carrier.network_code; Session["currentCarrierType"] = results.current_carrier.network_type; Session["currentCarrierCountry"] = results.current_carrier.country; Session["originalCarrierName"] = results.original_carrier.name; Session["originalCarrierCode"] = results.original_carrier.network_code; Session["originalCarrierType"] = results.original_carrier.network_type; Session["originalCarrierCountry"] = results.original_carrier.country; return(RedirectToAction("StandardResults")); }
public async Task <IActionResult> Process([FromQuery] string num, [FromQuery] string token) { var cleanNum = Regex.Replace(num ?? "", "[^0-9]", ""); token = token ?? "e30="; var filter = BeaconJsonConvert.DeserializeObject <Filter>(Encoding.ASCII.GetString(Convert.FromBase64String(token))); // Get phone number info var numInfo = NumberInsight.RequestStandard(new NumberInsight.NumberInsightBasicRequest { number = cleanNum }); if (numInfo.status != "0") { return(new ObjectResult(new { Status = "err", Message = "Invalid phone number" }) { StatusCode = 400 }); } var passesFilter = true; // Filter on Country if applicable if (String.IsNullOrWhiteSpace(filter.Country) == false && filter.Country != "*") { passesFilter = passesFilter && numInfo.country_code == filter.Country; } // Filter on Carrier if applicable if (String.IsNullOrWhiteSpace(filter.Carrier) == false && filter.Carrier != "*") { passesFilter = passesFilter && numInfo.current_carrier.network_code == filter.Carrier; } if (passesFilter) { var response = await SendMessage(cleanNum, calculateSignature(cleanNum)); return(new ObjectResult(new { Status = "ok", NumberResponse = numInfo, MessageResponse = response })); } else { return(new ObjectResult(new { Status = "err", Message = "number failed test parameters" }) { StatusCode = 400 }); } }
public void should_send_standard_ni_request() { var result = NumberInsight.RequestStandard(new NumberInsight.NumberInsightBasicRequest() { number = Configuration.Instance.Settings["test_number"] }); Assert.AreEqual("0", result.status); Assert.AreEqual(Configuration.Instance.Settings["test_number"], result.international_format_number); Assert.AreEqual("(555) 555-1212", result.national_format_number); Assert.AreEqual("Verizon Wireless", result.current_carrier.name); }
public void should_send_standard_ni_request() { var result = NumberInsight.RequestStandard(new NumberInsight.NumberInsightRequest { Number = Configuration.Instance.Settings["test_number"] }); Assert.AreEqual("0", result.Status); Assert.AreEqual(Configuration.Instance.Settings["test_number"], result.InternationalFormatNumber); Assert.AreEqual("(555) 555-1212", result.NationalFormatNumber); Assert.AreEqual("Verizon Wireless", result.CurrentCarrier.Name); }
public void should_send_standard_ni_request() { SetExpect($"{ApiUrl}/ni/standard/json", "{\"status\": 0,\"status_message\": \"Success\",\"request_id\": \"bcf255a4-047c-4364-89b1-d5cf76ffffff\",\"international_format_number\": \"15555551212\",\"national_format_number\": \"(555) 555-1212\",\"country_code\": \"US\",\"country_code_iso3\": \"USA\",\"country_name\": \"United States of America\",\"country_prefix\": \"1\",\"request_price\": \"0.00500000\",\"remaining_balance\": \"1.1\",\"current_carrier\": {\"network_code\": \"310004\",\"name\": \"Verizon Wireless\",\"country\": \"US\",\"network_type\": \"mobile\"},\"original_carrier\": {\"network_code\": \"310004\",\"name\": \"Verizon Wireless\",\"country\": \"US\",\"network_type\": \"mobile\"}}", $"number=15555551212&api_key={ApiKey}&api_secret={ApiSecret}&"); var result = NumberInsight.RequestStandard(new NumberInsight.NumberInsightRequest { number = "15555551212" }); Assert.AreEqual("0", result.status); Assert.AreEqual("15555551212", result.international_format_number); Assert.AreEqual("(555) 555-1212", result.national_format_number); Assert.AreEqual("Verizon Wireless", result.current_carrier.name); }