コード例 #1
0
        /// <summary>
        /// Retrives fraud level for given call data.
        /// More information at: https://nextcaller.com/documentation/v2.1/#/fraud-levels/curl.
        /// </summary>
        /// <param name="callData">Call data to be posted.</param>
        /// <returns>Fraud level for given call data.</returns>
        public FraudLevel AnalyzeCall(AnalyzeCallData callData)
        {
            Utility.EnsureParameterValid(!(callData == null), "callData");

            string jsonData = JsonSerializer.Serialize(callData);
            string content  = AnalyzeCallJson(jsonData);

            return(JsonSerializer.Deserialize <FraudLevel>(content));
        }
コード例 #2
0
        public void AnalyzeCall_ValidData_FraudLevelReturned()
        {
            //Arrange
            const string AccountId      = "TestUser1";
            string       jsonFraudLevel = Properties.Resources.JsonFraudLevel;

            AnalyzeCallData data = new AnalyzeCallData
            {
                Ani     = "12125551212",
                Dnis    = "18005551212",
                Headers = new Dictionary <string, object>
                {
                    { "from", "\"John Smith\" <sip:[email protected]>" },
                    { "via", new List <string> {
                          "SIP/2.0//UDP 1.1.1.1:5060;branch=z9hG4bK3fe1.9a945462b4c1880c5f6fdc0214a205ca.1"
                      } }
                },
                Meta = new Dictionary <string, string>
                {
                    { "caller_id", "12125551212" },
                    { "charge_number", "12125551212" },
                    { "ani2", "0" },
                    { "private", "true" }
                }
            };

            Mock <IHttpTransport> httpTransportMock = new Mock <IHttpTransport>(MockBehavior.Strict);

            httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), It.IsIn("GET", "POST"), It.IsAny <string>(), It.IsAny <IEnumerable <Header> >()))
            .Returns(jsonFraudLevel);

            //Action
            NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object);
            string jsonData   = JsonSerializer.Serialize(data);
            string fraudLevel = client.AnalyzeCallJson(jsonData, AccountId);

            //Assert
            httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), It.IsIn("GET", "POST"), It.IsAny <string>(), It.IsAny <IEnumerable <Header> >()), Times.Once);

            Assert.IsNotNull(fraudLevel);
            Assert.AreEqual(jsonFraudLevel, fraudLevel);
        }
コード例 #3
0
        public static void Run()
        {
            const string Username = "";
            const string Password = "";
            const bool   Sandbox  = true;

            NextCallerClient client = new NextCallerClient(Username, Password, Sandbox);

            try
            {
                AnalyzeCallData callData = new AnalyzeCallData
                {
                    Ani     = "12125551212",
                    Dnis    = "18005551212",
                    Headers = new Dictionary <string, object>
                    {
                        { "from", "\"John Smith\" <sip:[email protected]>" },
                        { "via", new List <string> {
                              "SIP/2.0//UDP 1.1.1.1:5060;branch=z9hG4bK3fe1.9a945462b4c1880c5f6fdc0214a205ca.1"
                          } }
                    },
                    Meta = new Dictionary <string, string>
                    {
                        { "caller_id", "12125551212" },
                        { "charge_number", "12125551212" },
                        { "ani2", "0" },
                        { "private", "true" }
                    }
                };

                FraudLevel fraudLevel = client.AnalyzeCall(callData);
            }
            catch (FormatException formatException)
            {
                HttpWebRequest  request  = formatException.Request;
                HttpWebResponse response = formatException.Response;

                HttpStatusCode code = response.StatusCode;
                Console.WriteLine("Status code: {0}", code);

                string reasonPhrase = response.StatusDescription;
                Console.WriteLine("Reason Phrase: {0}", reasonPhrase);

                string responseContent = formatException.Content;
                Console.WriteLine("Content : {0}", responseContent);
            }
            catch (BadRequestException badRequestException)
            {
                HttpWebRequest  request  = badRequestException.Request;
                HttpWebResponse response = badRequestException.Response;

                Error parsedError = badRequestException.Error;

                string errorCode = parsedError.Code;
                string message   = parsedError.Message;
                string type      = parsedError.Type;

                Dictionary <string, string[]> description = parsedError.Description;

                Console.WriteLine(parsedError.ToString());
            }
        }