示例#1
0
        public void GetMessage(bool passCreds)
        {
            //ARRANGE
            var uri = $"{RestUrl}/search/message?id=03000000FFFFFFFF&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponse = "{\"message-id\":\"03000000FFFFFFFF\",\"account-id\":\"deadbeef\",\"network\":\"310004\",\"from\":\"17775551212\",\"to\":\"17775551213\",\"body\":\"web test\",\"price\":\"0.00480000\",\"date-received\":\"2015-12-31 14:08:40\",\"status\":\"ACCEPTD\",\"error-code\":\"1\",\"error-code-label\":\"Unknown\",\"type\":\"MT\"}";

            Setup(uri: uri, responseContent: expectedResponse);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Search.Message msg;
            if (passCreds)
            {
                msg = client.Search.GetMessage("03000000FFFFFFFF", creds);
            }
            else
            {
                msg = client.Search.GetMessage("03000000FFFFFFFF");
            }

            //ASSERT
            Assert.Equal("03000000FFFFFFFF", msg.messageId);
            Assert.Equal("17775551212", msg.from);
            Assert.Equal("17775551213", msg.to);
        }
示例#2
0
        public void TestRedact(bool passCreds)
        {
            var expectedUri    = $"{ApiUrl}/v1/redact/transaction";
            var requestContent = "{\"id\":\"Abc1234567\",\"product\":\"sms\",\"type\":\"outbound\"}";
            var responseContet = "{}";

            Setup(uri: expectedUri, responseContet, requestContent: requestContent, System.Net.HttpStatusCode.NoContent);

            var request = new Redact.RedactRequest("Abc1234567", "sms", "outbound");
            var creds   = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var  client = new Client(creds);
            bool response;

            if (passCreds)
            {
                response = client.Redact.RedactTransaction(request, creds);
            }
            else
            {
                response = client.Redact.RedactTransaction(request);
            }
            Assert.True(response);
        }
        public void Initiate2FA(bool passCreds)
        {
            //ARRANGE
            var request = new ShortCode.TwoFactorAuthRequest
            {
                to  = "15555551212",
                pin = 1247
            };
            var uri = $"{RestUrl}/sc/us/2fa/json?to={request.to}&pin={request.pin}&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponse = "{\"message-count\":\"1\",\"messages\":[{\"message-id\":\"02000000AE70FFFF\",\"to\":\"15555551212\",\"remaining-balance\":7.546,\"message-price\":0.0048,\"ok\":true,\"status\":\"0\",\"msisdn\":\"15555551212\",\"network\":\"US-FIXED\",\"messageId\":\"02000000AE70FFFF\",\"remainingBalance\":7.546,\"messagePrice\":0.0048}]}";

            Setup(uri: uri, responseContent: expectedResponse);
            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            SMS.SMSResponse response;
            if (passCreds)
            {
                response = client.ShortCode.RequestTwoFactorAuth(request, creds);
            }
            else
            {
                response = client.ShortCode.RequestTwoFactorAuth(request);
            }

            //ASSERT
            Assert.Equal("1", response.message_count);
            Assert.Equal("15555551212", response.messages.First().to);
        }
示例#4
0
        public void GetPricing(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{RestUrl}/account/get-pricing/outbound/?country=US&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = @"{""country"":""US"",""name"":""United States"",""countryDisplayName"":""United States"",""prefix"":""1"",""mt"":""0.00480000"",""networks"":[{""code"":""US-FIXED"",""network"":""United States of America Landline"",""mtPrice"":""0.00480000"",""ranges"":""""},{""code"":""311340"",""network"":""Illinois Valley Cellular RSA 2-I Partnership"",""mtPrice"":""0.00480000""},{""code"":""311740"",""network"":""TelAlaska Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""311910"",""network"":""SI WIRELESS, LLC"",""mtPrice"":""0.00480000""},{""code"":""310860"",""network"":""Five Star Wireless"",""mtPrice"":""0.00480000""},{""code"":""310760"",""network"":""Panhandle Telecommunications Systems, Inc."",""mtPrice"":""0.00480000""},{""code"":""310011"",""network"":""Northstar Technology, LLC"",""mtPrice"":""0.00480000""},{""code"":""311887"",""network"":""XO California, Inc."",""mtPrice"":""0.00480000""},{""code"":""311380"",""network"":""NEW DIMENSION WIRELESS LTD."",""mtPrice"":""0.00480000""},{""code"":""310300"",""network"":""Smart Call, LLC"",""mtPrice"":""0.00480000""},{""code"":""310004"",""network"":""Verizon Wireless"",""mtPrice"":""0.00480000""},{""code"":""US-VOIP"",""network"":""United States of America VoIP"",""mtPrice"":""0.00480000""},{""code"":""311580"",""network"":""United States Cellular Corp. - Maine"",""mtPrice"":""0.00480000""},{""code"":""311230"",""network"":""Cellular South, Inc."",""mtPrice"":""0.00480000""},{""code"":""310610"",""network"":""Epic Touch Co."",""mtPrice"":""0.00480000""},{""code"":""310060"",""network"":""New Cell, Inc. dba CeLLCom"",""mtPrice"":""0.00480000""},{""code"":""310870"",""network"":""Kaplan Telephone Company"",""mtPrice"":""0.00480000""},{""code"":""310750"",""network"":""East Kentucky Netwrk, LLC dba Appalachian Wireless"",""mtPrice"":""0.00480000""},{""code"":""311290"",""network"":""Pinpoint Wireless, Inc."",""mtPrice"":""0.00480000""},{""code"":""311330"",""network"":""Michigan Wireless, LLC dba Bug Tussel Wireless"",""mtPrice"":""0.00480000""},{""code"":""310710"",""network"":""ASTAC Wireless LLC"",""mtPrice"":""0.00480000""},{""code"":""311050"",""network"":""Wilkes Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""310770"",""network"":""Iowa Wireless Services, Lp"",""mtPrice"":""0.00480000""},{""code"":""310100"",""network"":""Plateau Telecommunications, Inc."",""mtPrice"":""0.00480000""},{""code"":""311090"",""network"":""Flat Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""311190"",""network"":""Cellular Properties, Inc."",""mtPrice"":""0.00480000""},{""code"":""311710"",""network"":""NORTHEAST WIRELESS NETWORKS, LLC"",""mtPrice"":""0.00480000""},{""code"":""311370"",""network"":""NACS Wireless, Inc."",""mtPrice"":""0.00480000""},{""code"":""311430"",""network"":""RSA 1 Limited Partnership dba Chat Mobility"",""mtPrice"":""0.00480000""},{""code"":""311100"",""network"":""Nex-Tech Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""311240"",""network"":""Cordova Wireless Communications, Inc."",""mtPrice"":""0.00480000""},{""code"":""316011"",""network"":""Southern Communications Services"",""mtPrice"":""0.00480000""},{""code"":""310340"",""network"":""Westlink Communications, LLC"",""mtPrice"":""0.00480000""},{""code"":""311860"",""network"":""Uintah Basin Electronic Telecommunications"",""mtPrice"":""0.00480000""},{""code"":""311670"",""network"":""Pine Belt Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""US-PREMIUM"",""network"":""United States Premium"",""mtPrice"":""0.00480000""},{""code"":""310570"",""network"":""MTPCS, LLC"",""mtPrice"":""0.00480000""},{""code"":""310180"",""network"":""CT Cube, L.P. dba West Central Cellular"",""mtPrice"":""0.00480000""},{""code"":""311080"",""network"":""Pine Telephone Co."",""mtPrice"":""0.00480000""},{""code"":""310130"",""network"":""Carolina West"",""mtPrice"":""0.00480000""},{""code"":""310580"",""network"":""Inland Cellular"",""mtPrice"":""0.00480000""},{""code"":""311040"",""network"":""Commnet Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""316993"",""network"":""Cablevision Lightpath, Inc. - NY"",""mtPrice"":""0.00480000""},{""code"":""316995"",""network"":""Coral Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""311410"",""network"":""Iowa RSA 2 Limited Partnership dba Chat Mobility"",""mtPrice"":""0.00480000""},{""code"":""310630"",""network"":""Choice Wireless LC"",""mtPrice"":""0.00480000""},{""code"":""311420"",""network"":""Northwest Missouri Cellular Limited Partnership"",""mtPrice"":""0.00480000""},{""code"":""310270"",""network"":""POWERTEL MEMPHIS LICENSES, INC."",""mtPrice"":""0.00480000""},{""code"":""31100"",""network"":""Mid-Tex Cellular Ltd."",""mtPrice"":""0.00480000""},{""code"":""311610"",""network"":""North Dakota Network Co dba SRT Wireless"",""mtPrice"":""0.00480000""},{""code"":""316884"",""network"":""Kentucky RSA 4 Cellular General Partnership"",""mtPrice"":""0.00480000""},{""code"":""310540"",""network"":""Oklahoma Western Telephone Company"",""mtPrice"":""0.00480000""},{""code"":""316885"",""network"":""Sagebrush Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""316883"",""network"":""Virginia PCS Alliance, L.c."",""mtPrice"":""0.00480000""},{""code"":""312040"",""network"":""Custer Telephone Cooperative, Inc."",""mtPrice"":""0.00480000""},{""code"":""311650"",""network"":""United Wireless Communications, Inc."",""mtPrice"":""0.00480000""},{""code"":""310690"",""network"":""Keystone Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""310120"",""network"":""SPRINT Spectrum L.P."",""mtPrice"":""0.00480000""},{""code"":""310020"",""network"":""Union Telephone Company"",""mtPrice"":""0.00480000""},{""code"":""311020"",""network"":""Chariton Valley Cellular"",""mtPrice"":""0.00480000""},{""code"":""311030"",""network"":""Indigo Wireless, Inc."",""mtPrice"":""0.00480000""},{""code"":""311310"",""network"":""New Mexico RSA 6-III Partnership dba Leaco Rural"",""mtPrice"":""0.00480000""},{""code"":""310023"",""network"":""Voicestream GSM I, LLC"",""mtPrice"":""0.00480000""},{""code"":""310320"",""network"":""Smith Bagley Inc. dba Cellular One of Ne Arizona"",""mtPrice"":""0.00480000""},{""code"":""311730"",""network"":""Proximity Mobility, LLC"",""mtPrice"":""0.00480000""},{""code"":""310260"",""network"":""T-mobile USA, Inc."",""mtPrice"":""0.00480000""},{""code"":""310450"",""network"":""N.E. Colorado Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""310090"",""network"":""AT&T Mobility"",""mtPrice"":""0.00480000""},{""code"":""310740"",""network"":""Tracy Corporation Ii"",""mtPrice"":""0.00480000""},{""code"":""311690"",""network"":""Telebeeper of New Mexico"",""mtPrice"":""0.00480000""},{""code"":""310840"",""network"":""Telecom North America Mobile Inc"",""mtPrice"":""0.00480000""},{""code"":""310880"",""network"":""Advantage Cellular Systems, Inc."",""mtPrice"":""0.00480000""}]}";

            Setup(uri: expectedUri, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Account.Pricing pricing;
            if (passCreds)
            {
                pricing = client.Account.GetPricing("US", creds: creds);
            }
            else
            {
                pricing = client.Account.GetPricing("US");
            }

            //ASSERT
            Assert.Equal("US-FIXED", pricing.networks[0].code);
            Assert.Equal("United States of America Landline", pricing.networks[0].network);
        }
示例#5
0
        public void GetNumbers(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{RestUrl}/account/numbers?api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = @"{""count"":1,""numbers"":[{""country"":""US"",""msisdn"":""17775551212"",""type"":""mobile-lvn"",""features"":[""VOICE"",""SMS""]}]}";

            Setup(uri: expectedUri, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Account.NumbersResponse numbers;
            if (passCreds)
            {
                numbers = client.Account.GetNumbers(creds);
            }
            else
            {
                numbers = client.Account.GetNumbers();
            }


            Assert.Equal(1, numbers.count);
            Assert.Equal("17775551212", numbers.numbers[0].msisdn);
        }
示例#6
0
        public void TopUp(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{RestUrl}/account/top-up?trx=00X123456Y7890123Z&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = @"{}";

            Setup(uri: expectedUri, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            if (passCreds)
            {
                client.Account.TopUp("00X123456Y7890123Z", creds);
            }
            else
            {
                client.Account.TopUp("00X123456Y7890123Z");
            }


            //ASSERT
            //nothing to assert as nothing is returned
        }
示例#7
0
        public void UpdateApplication(bool passCreds)
        {
            //ARRANGE
            var appId      = "ffffffff-ffff-ffff-ffff-ffffffffffff";
            var appRequest = new AppRequest
            {
                Id   = "ffffffff-ffff-ffff-ffff-ffffffffffff",
                Name = "UpdatedAppTest"
            };
            var uri = $"{ApiUrl}/v2/applications/{appId}";
            var expectedResposne = "{  \"id\": \"ffffffff-ffff-ffff-ffff-ffffffffffff\",  \"name\": \"UpdatedAppTest\", \"capabilities\": {\"voice\": {\"webhooks\": {\"answer_url\": {\"address\": \"https://example.com/webhooks/answer\",\"http_method\": \"POST\"},\"fallback_answer_url\": {\"address\": \"https://fallback.example.com/webhooks/answer\",\"http_method\": \"POST\"},\"event_url\": {\"address\": \"https://example.com/webhooks/event\",\"http_method\": \"POST\"}}},\"messages\": {\"webhooks\": {\"inbound_url\": {\"address\": \"https://example.com/webhooks/inbound\",\"http_method\": \"POST\"},\"status_url\": {\"address\": \"https://example.com/webhooks/status\",\"http_method\": \"POST\"}}},\"rtc\": {\"webhooks\": {\"event_url\": {\"address\": \"https://example.com/webhooks/event\",\"http_method\": \"POST\"}}},\"vbc\": {}}}";

            Setup(uri: uri, responseContent: expectedResposne);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var         client = new Client(creds);
            AppResponse result;

            if (passCreds)
            {
                result = client.ApplicationV2.Update(appRequest, creds);
            }
            else
            {
                result = client.ApplicationV2.Update(appRequest);
            }

            //ASSERT
            Assert.Equal("UpdatedAppTest", result.Name);
        }
示例#8
0
        public void CreateApplication(bool passCreds)
        {
            //ARRANGE
            var uri = $"{ApiUrl}/v2/applications";
            var expectedResponse       = "{\"id\":\"ffffffff-ffff-ffff-ffff-ffffffffffff\",\"name\":\"AppV2Test\",\"capabilities\":{},\"keys\":{\"public_key\":\"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwxyBT5FqzibSYK0vB+Gr\\nP+YlyYqsx4lvAmotTwmObZEhTWNAdU0p9hrnNXWX1Gy5O0NDIue40SUhYhJT5r4x\\nugbpNA/1KJauB8VQjetKr9bu697yskz2+EuKa2D9e6N2EMY6PD1tJWmeMmddM1tW\\n2DAXuYo7/xsDWIIA6egCTzyShNvzlKo5081t41xVVsPjsWN887Xp1KYfE0IMGV2j\\n8Nwdtw/MQfP/7Qz7i9VXb7bgx0LEg84dWsnz8u3VZ3IQHlydzPX/2iw7e4pc+k27\\nOU1SkmPn/2JtfFFS2LJpcO/FmdSyNnyHezNPyzNRLVbE0sJJ1tEhxi9GZc1I+Oc4\\ndwIDAQAB\\n-----END PUBLIC KEY-----\\n\",\"private_key\":\"-----BEGIN PRIVATE KEY-----\\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDHIFPkWrOJtJg\\nrS8H4as/5iXJiqzHiW8Cai1PCY5tkSFNY0B1TSn2Guc1dZfUbLk7Q0Mi57jRJSFi\\nElPmvjG6Buk0D/Uolq4HxVCN60qv1u7r3vKyTPb4S4prYP17o3YQxjo8PW0laZ4y\\nZ10zW1bYMBe5ijv/GwNYggDp6AJPPJKE2/OUqjnTzW3jXFVWw+OxY3zztenUph8T\\nQgwZXaPw3B23D8xB8//tDPuL1VdvtuDHQsSDzh1ayfPy7dVnchAeXJ3M9f/aLDt7\\nilz6Tbs5TVKSY+f/Ym18UVLYsmlw78WZ1LI2fId7M0/LM1EtVsTSwknW0SHGL0Zl\\nzUj45zh3AgMBAAECggEAFP06iJ7p9fkQKwKbwMXNQIes1fm7QjtDJr0vAvB8vXBe\\nPER/7n6EE+vApqwapBP5eJTGTU7PP382kFB3bScAaMo4iSIUVgRLqXNXtJoKGVDO\\nYq/DvQbxjzQVKnMEdyoBAqdIeYAu1IEAWdzBFnbDfhNCYh0q/MkLpZhVVSm2dzkq\\nl+xrEOTyuE48RQxTQqliUYXXlUd5+bjR+oREuYsjt8j9iiK1u6Gv2ztDPeyzupny\\ntCvSlykvAKn/K6xmeO4hapPKUZ7DRthg3I3uPx+mw48GvO28mzhsqXpbDcYI7q82\\nfZgZJ3JKBTRaNnEE8d5llblC5dksMttLgO2EewdXlQKBgQDscfdVVvLYDW3lsPKl\\nAhEmi3ZcWvzDMCGeGLjJEZPfMnc+7rKbCBADQzNMZI/bsWwMJdQCMy2xMaDXr4Ew\\n4TiBdQ7ogpRex9yuJ3miKs3eey6bvpNxV70lj/xvZoSu7oANSFOCMNFUvSWFTPC5\\nNiNGk35g6xklf3WAYLx4bVJcDQKBgQDTP2qL2zQbU/hmQPnq8x/wgGn8T6zQZXbt\\nojyNPTsnIbQhwQzlFM01SzNsF4hVMB8Zz6r+8XHuo3TsDdg6Orx1auIV5lXCWMj/\\n3MW/jy2JabXJyh7BViHFqQjBPHWDrX17TGGsLK/rfOqMRPPgBGTXfVhINaCo7EAh\\nSTPv2x2RkwKBgBQinGpzDhkiA6LUz8UHiQhcRgcVZIMGvUYmWs4cphgSxx7f2uvi\\n4uI0PdEamzmdQVNDgWtyikiVrlnPw1OzSkmT+2IHhLURlhRqniwWMxPoL47pysqT\\nKzNgsKGX/GKdQuBesWXb3Ge399MDO1i6aIShGNkODEUqNoppMoOa47GdAoGAWn3t\\n/F84YQSFgfgPlu/zHKlFvYm788GjQoSe/7ndHxQ2/8ac6X0RsuS18HXcNvHYQMxO\\n6cswDRQEQCJmH/uNQ5c3pj33OruhzskaBMcmsJiSAREOP6/P48ZXM7/cbz3gZPMB\\nXCoAahYmu1PGTI5VTGIrcTNX0UTy689Z6kOo1PUCgYEAjYPkvv4j286XbGHDQyt7\\ngPvbFUPwtYxwk0u/CuZ1scBkVRCMwc8Gic1hL0yB09nvp86cCjNyYcFqa8fTpjom\\n0C7wjZd6zHR4y23U/jVxhdny6lotpgpWKO7DVprjyHQ90yGu+EDq3jDCOjyhdmqP\\n766dkdpKIYoBJOTH9+3r8gc=\\n-----END PRIVATE KEY-----\\n\"}}";
            var expectedRequestContent = "{\"name\":\"AppV2Test\"}";

            Setup(uri: uri, responseContent: expectedResponse, requestContent: expectedRequestContent);

            //ACT
            var appRequest = new AppRequest
            {
                Name = "AppV2Test"
            };

            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var         client = new Client(creds);
            AppResponse result;

            if (passCreds)
            {
                result = client.ApplicationV2.Create(appRequest, creds);
            }
            else
            {
                result = client.ApplicationV2.Create(appRequest);
            }

            //ASSERT
            Assert.Equal("ffffffff-ffff-ffff-ffff-ffffffffffff", result.Id);
        }
示例#9
0
        public void SetSettings(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{RestUrl}/account/settings";
            var expectedRequestContents = $"newSecret=newSecret1&moCallBackUrl=http%3a%2f%2fmo.callbackurl.com&drCallBackUrl=http%3a%2f%2fdr.callbackurl.com&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = @"{""api-secret"": ""newSecret1"",""mo-callback-url"": ""http://mo.callbackurl.com"",""dr-callback-url"": ""http://dr.callbackurl.com"", ""max-outbound-request"":30, ""max-inbound-request"":15}";

            Setup(uri: expectedUri, responseContent: expectedResponseContent, requestContent: expectedRequestContents);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Account.Settings result;

            if (passCreds)
            {
                result = client.Account.SetSettings("newSecret1", "http://mo.callbackurl.com", "http://dr.callbackurl.com", creds);
            }
            else
            {
                result = client.Account.SetSettings("newSecret1", "http://mo.callbackurl.com", "http://dr.callbackurl.com");
            }


            Assert.Equal("newSecret1", result.apiSecret);
            Assert.Equal("http://mo.callbackurl.com", result.moCallbackUrl);
            Assert.Equal("http://dr.callbackurl.com", result.drCallbackUrl);
            Assert.Equal(15, result.maxInboundRequest);
            Assert.Equal(30, result.maxOutboundRequest);
        }
        public void SearchNumbers(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{RestUrl}/number/search/?country=US&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = "{\"count\":177,\"numbers\":[{\"country\":\"US\",\"msisdn\":\"15102694548\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568490\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568491\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568492\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"},{\"country\":\"US\",\"msisdn\":\"17088568973\",\"type\":\"mobile-lvn\",\"features\":[\"SMS\",\"VOICE\"],\"cost\":\"0.67\"}]}";

            Setup(uri: expectedUri, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Number.SearchResults results;
            if (passCreds)
            {
                results = client.Number.Search(new Number.SearchRequest()
                {
                    country = "US"
                }, creds);
            }
            else
            {
                results = client.Number.Search(new Number.SearchRequest()
                {
                    country = "US"
                });
            }

            //ASSERT
            Assert.Equal(177, results.count);
            Assert.Equal(5, results.numbers.Count());
        }
示例#11
0
        public void CreateSecret(bool passCreds)
        {
            var secretId               = "ad6dc56f-07b5-46e1-a527-85530e625800";
            var expectedUri            = $"https://api.nexmo.com/accounts/{ApiKey}/secrets/?api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponse       = @"{
                  ""_links"": {
                    ""self"": {
                           ""href"": ""abc123""
                      }
                    },
                  ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"",
                  ""created_at"": ""2017-03-02T16:34:49Z""
                }";
            var expectedRequestContent = @"{""secret"":""8675309""}";

            Setup(expectedUri, expectedResponse, expectedRequestContent);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Api.ApiSecret.Secret secret;
            if (passCreds)
            {
                secret = client.ApiSecret.Create(ApiKey, "8675309", creds);
            }
            else
            {
                secret = client.ApiSecret.Create(ApiKey, "8675309");
            }
            //ASSERT
            Assert.Equal(secretId, secret.Id);
        }
示例#12
0
        public void ShouldDeleteApplication(bool passCreds)
        {
            //ARRANGE
            var appId    = "ffffffff-ffff-ffff-ffff-ffffffffffff";
            var uri      = $"{ApiUrl}/v2/applications/{appId}";
            var response = "";

            Setup(uri: uri, responseContent: response, expectedCode: System.Net.HttpStatusCode.NoContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var  client = new Client(creds);
            bool result;

            if (passCreds)
            {
                result = client.ApplicationV2.Delete(appId, creds);
            }
            else
            {
                result = client.ApplicationV2.Delete(appId);
            }

            //ASSERT
            Assert.True(result);
        }
        public void BuyNumber(bool passCreds)
        {
            //ARRANGE
            var expectedUri            = $"{RestUrl}/number/buy";
            var expectedResponse       = "{\"error-code\":\"200\",\"error-code-label\":\"success\"}";
            var expectedRequestContent = $"country=US&msisdn=17775551212&api_key={ApiKey}&api_secret={ApiSecret}&";

            Setup(uri: expectedUri, responseContent: expectedResponse, requestContent: expectedRequestContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var          client = new Client(creds);
            ResponseBase result;

            if (passCreds)
            {
                result = client.Number.Buy("US", "17775551212", creds);
            }
            else
            {
                result = client.Number.Buy("US", "17775551212");
            }

            //ASSERT
            Assert.Equal("200", result.ErrorCode);
        }
示例#14
0
        public void GetAccountBalance(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{RestUrl}/account/get-balance?api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = @"{""value"": 3.14159, ""autoReload"": false }";

            Setup(uri: expectedUri, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Account.Balance balance;
            if (passCreds)
            {
                balance = client.Account.GetBalance(creds);
            }
            else
            {
                balance = client.Account.GetBalance();
            }


            //ASSERT
            Assert.Equal(3.14159m, balance.value);
            Assert.False(balance.autoReload);
        }
        public void InitiateAlert(bool passCreds)
        {
            //ARRANGE
            var request = new ShortCode.AlertRequest
            {
                to = "15555551212"
            };
            var customValues = new Dictionary <string, string>
            {
                { "mcount", "xyz123" }
            };
            var uri = $"{RestUrl}/sc/us/alert/json?to={request.to}&mcount={customValues["mcount"]}&api_key={ApiKey}&api_secret={ApiSecret}&";
            var ExpectedResponse = "{\"message-count\":\"1\",\"messages\":[{\"message-id\":\"02000000AE70FFFF\",\"to\":\"15555551212\",\"remaining-balance\":7.546,\"message-price\":0.0048,\"ok\":true,\"status\":\"0\",\"msisdn\":\"15555551212\",\"network\":\"US-FIXED\",\"messageId\":\"02000000AE70FFFF\",\"remainingBalance\":7.546,\"messagePrice\":0.0048}]}";

            Setup(uri: uri, responseContent: ExpectedResponse);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            SMS.SMSResponse response;
            if (passCreds)
            {
                response = client.ShortCode.RequestAlert(request, customValues, creds);
            }
            else
            {
                response = client.ShortCode.RequestAlert(request, customValues);
            }

            Assert.Equal("1", response.message_count);
            Assert.Equal("15555551212", response.messages.First().to);
        }
示例#16
0
        public void GetPrefixPricing(bool passCreds)
        {
            var expectedResponse = @"{
                  ""count"": ""243"",
                  ""countries"": [
                    {
                      ""countryName"": ""Canada"",
                      ""countryDisplayName"": ""Canada"",
                      ""currency"": ""EUR"",
                      ""defaultPrice"": ""0.00620000"",
                      ""dialingPrefix"": ""1"",
                      ""networks"": [
                        {
                          ""type"": ""mobile"",
                          ""price"": ""0.00590000"",
                          ""currency"": ""EUR"",
                          ""mcc"": ""302"",
                          ""mnc"": ""530"",
                          ""networkCode"": ""302530"",
                          ""networkName"": ""Keewaytinook Okimakanak""
                        }
                      ]
                    }
                  ]
                }";
            var expectedUri      = $"{RestUrl}/account/get-pricing/outbound/?country=CA&type=sms&api_key={ApiKey}&api_secret={ApiSecret}&";

            Setup(expectedUri, expectedResponse);

            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Account.Pricing response;
            if (passCreds)
            {
                response = client.Account.GetPrefixPricing("CA", "sms", creds);
            }
            else
            {
                response = client.Account.GetPrefixPricing("CA", "sms");
            }


            Assert.NotNull(response);
        }
示例#17
0
        public void ListSecrets(bool passCreds)
        {
            //ARRANGE
            var expectedResponse = @"{
                  ""_links"": {
                    ""self"": {
                        ""href"": ""abc123""
                      }
                  },
                  ""_embedded"": {
                    ""secrets"": [
                      {
                        ""_links"": {
                          ""self"": {
                            ""href"": ""abc123""
                          }
                        },
                        ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"",
                        ""created_at"": ""2017-03-02T16:34:49Z""
                      }
                    ]
                  }
                }";
            var expectedUri      = $"https://api.nexmo.com/accounts/{ApiKey}/secrets?api_key={ApiKey}&api_secret={ApiSecret}&";

            Setup(expectedUri, expectedResponse);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);
            List <Api.ApiSecret.Secret> secrets;

            if (passCreds)
            {
                secrets = client.ApiSecret.List(ApiKey, creds);
            }
            else
            {
                secrets = client.ApiSecret.List(ApiKey);
            }

            //ASSERT
            Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secrets[0].Id);
            Assert.Equal("abc123", secrets[0]._links.self.href);
        }
        public void SendVerifyRequest(bool passCreds)
        {
            //ARRANGE
            var expectedUri = $"{ApiUrl}/verify/json?number=12018675309&country=US&brand=AcmeInc&sender_id=ACME&code_length=6&lg=en-US&pin_expiry=240&next_event_wait=120&workflow_id=4&api_key={ApiKey}&api_secret={ApiSecret}&";

            var expectedResult = @"{
              ""request_id"": ""abcdef012345..."",
              ""status"": ""0""
              }";

            Setup(uri: expectedUri, responseContent: expectedResult);

            //ACT
            var request = new NumberVerify.VerifyRequest()
            {
                number          = "12018675309",
                brand           = "AcmeInc",
                country         = "US",
                sender_id       = "ACME",
                code_length     = "6",
                lg              = "en-US",
                pin_expiry      = "240",
                next_event_wait = "120",
                workflow_id     = "4"
            };
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            NumberVerify.VerifyResponse response;
            if (passCreds)
            {
                response = client.NumberVerify.Verify(request);
            }
            else
            {
                response = client.NumberVerify.Verify(request);
            }
            Assert.Equal("0", response.status);
            Assert.Equal("abcdef012345...", response.request_id);
        }
        public void UpdateNumber(bool passCreds)
        {
            //ARRANGE
            var expectedUri            = $"{RestUrl}/number/update";
            var expectedResponse       = "{\"error-code\":\"200\",\"error-code-label\":\"success\"}";
            var expectedRequestContent = $"country=US&msisdn=17775551212&moHttpUrl=https%3a%2f%2ftest.test.com%2fmo&moSmppSysType=inbound&api_key={ApiKey}&api_secret={ApiSecret}&";

            Setup(uri: expectedUri, responseContent: expectedResponse, requestContent: expectedRequestContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var          client = new Client(creds);
            ResponseBase result;

            if (passCreds)
            {
                result = client.Number.Update(new Number.NumberUpdateCommand
                {
                    country       = "US",
                    msisdn        = "17775551212",
                    moHttpUrl     = "https://test.test.com/mo",
                    moSmppSysType = "inbound"
                }, creds);
            }
            else
            {
                result = client.Number.Update(new Number.NumberUpdateCommand
                {
                    country       = "US",
                    msisdn        = "17775551212",
                    moHttpUrl     = "https://test.test.com/mo",
                    moSmppSysType = "inbound"
                });
            }

            //ASSERT
            Assert.Equal("200", result.ErrorCode);
        }
示例#20
0
        public void GetRejections(bool passCreds)
        {
            //ARRANGE
            var uri = $"{RestUrl}/search/rejections?date=2015-12-31&to=17775551213&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponse = "{\"count\":1,\"items\":[{\"account-id\":\"deadbeef\",\"from\":\"17775551212\",\"to\":\"17775551213\",\"body\":\"web test\",\"date-received\":\"2015-12-31 14:08:40\",\"error-code\":\"1\",\"error-code-label\":\"Unknown\",\"type\":\"MT\"}]}";

            Setup(uri: uri, responseContent: expectedResponse);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            Search.Messages <Search.MessageBase> msgs;
            if (passCreds)
            {
                msgs = client.Search.GetRejections(new Search.SearchRequest
                {
                    date = "2015-12-31",
                    to   = "17775551213"
                }, creds);
            }
            else
            {
                msgs = client.Search.GetRejections(new Search.SearchRequest
                {
                    date = "2015-12-31",
                    to   = "17775551213"
                });
            }
            Assert.Single(msgs.items);
            var msg = msgs.items[0];

            Assert.Equal("17775551212", msg.from);
            Assert.Equal("17775551213", msg.to);
            Assert.Equal("web test", msg.body);
        }
示例#21
0
        public void TestSmsWithoutFrom(bool passCreds)
        {
            // ARRANGE
            var restUrl         = "https://rest.nexmo.com";
            var expectedUri     = $"{restUrl}/sms/json";
            var responseContent = "{\"message-count\": \"1\",\"messages\": [{\"to\": \"17775551212\",\"message-id\": \"02000000A3AF32FA\",\"status\": \"0\",\"remaining-balance\": \"7.55560000\",\"message-price\": \"0.00480000\",\"network\": \"310004\"}]}";

            var to             = "17775551212";
            var text           = "this is a test";
            var requestContent = $"to={to}&text={HttpUtility.UrlEncode(text)}&api_key={ApiKey}&api_secret={ApiSecret}&";

            Setup(uri: expectedUri, responseContent: responseContent, requestContent: requestContent);

            // ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            SMS.SMSResponse response;
            if (passCreds)
            {
                response = client.SMS.Send(new SMS.SMSRequest()
                {
                    to = to, text = text
                }, creds);
            }
            else
            {
                response = client.SMS.Send(new SMS.SMSRequest()
                {
                    to = to, text = text
                });
            }

            //ASSERT
            Assert.True(response.messages.Count == 1);
        }
示例#22
0
        public void SendStandardNiRequest(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{ApiUrl}/ni/standard/json";
            var expectedRequestContent  = $"number=15555551212&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = "{\"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\"}}";

            Setup(uri: expectedUri, requestContent: expectedRequestContent, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            NumberInsight.NumberInsightStandardResponse result;
            if (passCreds)
            {
                result = client.NumberInsight.RequestStandard(new NumberInsight.NumberInsightRequest
                {
                    Number = "15555551212"
                }, creds);
            }
            else
            {
                result = client.NumberInsight.RequestStandard(new NumberInsight.NumberInsightRequest
                {
                    Number = "15555551212"
                });
            }

            //ASSERT
            Assert.Equal("0", result.Status);
            Assert.Equal("15555551212", result.InternationalFormatNumber);
            Assert.Equal("(555) 555-1212", result.NationalFormatNumber);
            Assert.Equal("Verizon Wireless", result.CurrentCarrier.Name);
        }
示例#23
0
        public void SendBasicNiRequest(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{ApiUrl}/ni/basic/json";
            var expectedRequestContent  = $"number=15555551212&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = "{\"status\": 0,\"status_message\": \"Success\",\"request_id\": \"ca4f82b6-73aa-43fe-8c52-874fd9ffffff\",\"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\"}";

            Setup(uri: expectedUri, requestContent: expectedRequestContent, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            NumberInsight.NumberInsightBasicResponse response;
            if (passCreds)
            {
                response = client.NumberInsight.RequestBasic(new NumberInsight.NumberInsightRequest
                {
                    Number = "15555551212"
                }, creds);
            }
            else
            {
                response = client.NumberInsight.RequestBasic(new NumberInsight.NumberInsightRequest
                {
                    Number = "15555551212"
                });
            }

            //ASSERT
            Assert.Equal("0", response.Status);
            Assert.Equal("15555551212", response.InternationalFormatNumber);
            Assert.Equal("(555) 555-1212", response.NationalFormatNumber);
        }
        public void SendControl(bool passCreds)
        {
            //ARRANGE
            var expectedUri             = $"{ApiUrl}/verify/control/json?request_id=B41F2D19-913C-4BB3-B825-624E375D2C31&cmd=cancel&api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponseContent = "{\"status\":\"0\",\"command\":\"cancel\"}";

            Setup(uri: expectedUri, responseContent: expectedResponseContent);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            NumberVerify.ControlResponse results;
            if (passCreds)
            {
                results = client.NumberVerify.Control(new NumberVerify.ControlRequest
                {
                    request_id = "B41F2D19-913C-4BB3-B825-624E375D2C31",
                    cmd        = "cancel"
                }, creds);
            }
            else
            {
                results = client.NumberVerify.Control(new NumberVerify.ControlRequest
                {
                    request_id = "B41F2D19-913C-4BB3-B825-624E375D2C31",
                    cmd        = "cancel"
                });
            }

            //ASSERT
            Assert.Equal("0", results.status);
            Assert.Equal("cancel", results.command);
        }
示例#25
0
        public void DeleteSecret(bool passCreds)
        {
            var secretId               = "ad6dc56f-07b5-46e1-a527-85530e625800";
            var expectedUri            = $"https://api.nexmo.com/accounts/{ApiKey}/secrets/{secretId}?api_key={ApiKey}&api_secret={ApiSecret}&";
            var expectedResponse       = @"{
                  ""_links"": {
                    ""self"": {
                           ""href"": ""abc123""
                      }
                    },
                  ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"",
                  ""created_at"": ""2017-03-02T16:34:49Z""
                }";
            var expectedRequestContent = "null";

            Setup(expectedUri, expectedResponse, expectedRequestContent);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var  client = new Client(creds);
            bool revoked;

            if (passCreds)
            {
                revoked = client.ApiSecret.Delete(ApiKey, secretId, creds);
            }
            else
            {
                revoked = client.ApiSecret.Delete(ApiKey, secretId);
            }


            Assert.True(revoked);
        }
示例#26
0
        public void ListApplications(bool passCreds)
        {
            //ARRANGE
            var uri      = $"{ApiUrl}/v2/applications?page_size=10&page=0&";
            var expected = "{" +
                           "\"page_size\": 10," +
                           "\"page\": 1," +
                           "\"total_items\": 6," +
                           "\"total_pages\": 1," +
                           "\"_embedded\": {" +
                           "\"applications\": [" +
                           "{" +
                           "\"id\": \"78d335fa323d01149c3dd6f0d48968cf\"," +
                           "\"name\": \"My Application\"," +
                           "\"capabilities\": {" +
                           "\"voice\": {" +
                           "\"webhooks\": {" +
                           "\"answer_url\": {" +
                           "\"address\": \"https://example.com/webhooks/answer\"," +
                           "\"http_method\": \"POST\"" +
                           "}," +
                           "\"fallback_answer_url\": {" +
                           "\"address\": \"https://fallback.example.com/webhooks/answer\"," +
                           "\"http_method\": \"POST\"" +
                           "}," +
                           "\"event_url\": {" +
                           "\"address\": \"https://example.com/webhooks/event\"," +
                           "\"http_method\": \"POST\"" +
                           "}" +
                           "}" +
                           "}," +
                           "\"messages\": {" +
                           "\"webhooks\": {" +
                           "\"inbound_url\": {" +
                           "\"address\": \"https://example.com/webhooks/inbound\"," +
                           "\"http_method\": \"POST\"" +
                           "}," +
                           "\"status_url\": {" +
                           "\"address\": \"https://example.com/webhooks/status\"," +
                           "\"http_method\": \"POST\"" +
                           "}" +
                           "}" +
                           "}," +
                           "\"rtc\": {" +
                           "\"webhooks\": {" +
                           "\"event_url\": {" +
                           "\"address\": \"https://example.com/webhooks/event\"," +
                           "\"http_method\": \"POST\"" +
                           "}" +
                           "}" +
                           "}," +
                           "\"vbc\": {}" +
                           "}" +
                           "}" +
                           "]" +
                           "}" +
                           "}";

            Setup(uri: uri, responseContent: expected);

            //ACT
            var creds = new Request.Credentials()
            {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);
            List <AppResponse> results;

            if (passCreds)
            {
                results = client.ApplicationV2.List(credentials: creds);
            }
            else
            {
                results = client.ApplicationV2.List();
            }

            //ASSERT
            Assert.Single(results);
            Assert.True(results[0].Id == "78d335fa323d01149c3dd6f0d48968cf");
        }