コード例 #1
0
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var phoneNumber = PhoneNumberResource.Fetch(
            new PhoneNumber("+15108675310"),
            type: new List <string> {
            "carrier"
        });

        var mcc = phoneNumber.Carrier["mobile_country_code"];
        var mnc = phoneNumber.Carrier["mobile_network_code"];

        var countryCode = phoneNumber.CountryCode;
        var countries   = CountryResource.Fetch(countryCode);

        var prices = countries
                     .OutboundSmsPrices
                     .Where(price => price.Mcc.Equals(mcc) && price.Mnc.Equals(mnc))
                     .SelectMany(price => price.Prices);


        foreach (var price in prices)
        {
            Console.WriteLine($"Country {countryCode}");
            Console.WriteLine($"Current price {price.BasePrice}");
            Console.WriteLine($"Current price {price.CurrentPrice}");
        }
    }
コード例 #2
0
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var phoneNumber = PhoneNumberResource.Fetch(
            new PhoneNumber("+15108675310"),
            type: new List <string> {
            "carrier"
        });

        var mcc = phoneNumber.Carrier["mobile_country_code"];
        var mnc = phoneNumber.Carrier["mobile_network_code"];

        var countryCode = phoneNumber.CountryCode;
        var countries   = CountryResource.Fetch(countryCode);

        var prices = countries
                     .OutboundSmsPrices
                     .Where(price => price.Mcc.Equals(mcc) && price.Mnc.Equals(mnc))
                     .SelectMany(price => price.Prices);


        foreach (var price in prices)
        {
            Console.WriteLine($"Country {countryCode}");
            Console.WriteLine($"Current price {price.BasePrice}");
            Console.WriteLine($"Current price {price.CurrentPrice}");
        }
    }
コード例 #3
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var country = CountryResource.Fetch(pathIsoCountry: "US");

        Console.WriteLine(country.Country);
    }
コード例 #4
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var country = CountryResource.Fetch(pathIsoCode: "US");

        Console.WriteLine(country.Name);
    }
コード例 #5
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"iso_code\": \"US\",\"name\": \"United States/Canada\",\"country_codes\": [\"+1\"],\"continent\": \"NORTH_AMERICA\",\"low_risk_numbers_enabled\": false,\"high_risk_special_numbers_enabled\": false,\"high_risk_tollfraud_numbers_enabled\": false,\"url\": \"https://voice.twilio.com/v1/DialingPermissions/Countries/US\",\"links\": {\"highrisk_special_prefixes\": \"https://voice.twilio.com/v1/DialingPermissions/Countries/US/HighRiskSpecialPrefixes\"}}"
                         ));

            var response = CountryResource.Fetch("US", client: twilioRestClient);

            Assert.NotNull(response);
        }
コード例 #6
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"country\": \"Estonia\",\"iso_country\": \"EE\",\"phone_number_prices\": [{\"base_price\": 3.0,\"current_price\": 3.0,\"type\": \"mobile\"},{\"base_price\": 1.0,\"current_price\": 1.0,\"type\": \"national\"}],\"price_unit\": \"usd\",\"url\": \"https://pricing.twilio.com/v1/PhoneNumbers/Countries/US\"}"
                         ));

            var response = CountryResource.Fetch("US", client: twilioRestClient);

            Assert.NotNull(response);
        }
コード例 #7
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"country\": \"United States\",\"inbound_call_prices\": [{\"current_price\": \"0.0085\",\"number_type\": \"local\",\"base_price\": \"0.0085\"},{\"current_price\": \"0.022\",\"number_type\": \"toll free\",\"base_price\": \"0.022\"}],\"iso_country\": \"US\",\"outbound_prefix_prices\": [{\"prefixes\": [\"1907\"],\"current_price\": \"0.090\",\"friendly_name\": \"Programmable Outbound Minute - United States - Alaska\",\"base_price\": \"0.090\"}],\"price_unit\": \"USD\",\"url\": \"https://pricing.twilio.com/v1/Voice/Countries/US\"}"
                         ));

            var response = CountryResource.Fetch("US", client: twilioRestClient);

            Assert.NotNull(response);
        }
コード例 #8
0
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var country = CountryResource.Fetch("EE");

        foreach (var price in country.InboundSmsPrices)
        {
            Console.WriteLine(price.CurrentPrice);
        }
    }
コード例 #9
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"country\": \"country\",\"inbound_sms_prices\": [{\"base_price\": 0.05,\"current_price\": 0.05,\"number_type\": \"mobile\"}],\"iso_country\": \"US\",\"outbound_sms_prices\": [{\"carrier\": \"att\",\"mcc\": \"foo\",\"mnc\": \"bar\",\"prices\": [{\"base_price\": 0.05,\"current_price\": 0.05,\"number_type\": \"mobile\"}]}],\"price_unit\": \"USD\",\"url\": \"http://www.example.com\"}"
                         ));

            var response = CountryResource.Fetch("US", client: twilioRestClient);

            Assert.NotNull(response);
        }
コード例 #10
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"country\": \"Australia\",\"inbound_call_prices\": [{\"base_price\": \"0.0075\",\"current_price\": \"0.0075\",\"number_type\": \"local\"}],\"iso_country\": \"AU\",\"outbound_prefix_prices\": [{\"base_price\": \"0.024\",\"current_price\": \"0.024\",\"friendly_name\": \"Programmable Outbound Minute - Australia - Major Cities\",\"prefixes\": [\"6128\",\"6129\",\"6138\",\"6139\",\"6173\",\"61261\",\"61262\",\"61861\",\"61862\",\"61863\",\"61864\",\"61865\",\"61870\",\"61881\",\"61882\",\"61883\",\"61884\",\"61892\",\"61893\",\"61894\"]},{\"base_price\": \"0.035\",\"current_price\": \"0.035\",\"friendly_name\": \"Programmable Outbound Minute - Australia\",\"prefixes\": [\"61\"]},{\"base_price\": \"0.095\",\"current_price\": \"0.095\",\"friendly_name\": \"Programmable Outbound Minute - Australia - Shared Cost Service\",\"prefixes\": [\"6113\"]},{\"base_price\": \"0.095\",\"current_price\": \"0.095\",\"friendly_name\": \"Programmable Outbound Minute - Australia - Mobile\",\"prefixes\": [\"614\",\"6116\",\"61400\",\"61401\",\"61402\",\"61403\",\"61404\",\"61405\",\"61406\",\"61407\",\"61408\",\"61409\",\"61410\",\"61411\",\"61412\",\"61413\",\"61414\",\"61415\",\"61416\",\"61417\",\"61418\",\"61419\",\"61421\",\"61422\",\"61423\",\"61424\",\"61425\",\"61426\",\"61427\",\"61428\",\"61429\",\"61430\",\"61431\",\"61432\",\"61433\",\"61434\",\"61435\",\"61437\",\"61438\",\"61439\",\"61447\",\"61448\",\"61449\",\"61450\",\"61451\",\"61452\",\"61453\",\"61455\",\"61456\",\"61457\",\"61458\",\"61459\",\"61466\",\"61467\",\"61474\",\"61477\",\"61478\",\"61481\",\"61482\",\"61487\",\"61490\",\"61497\",\"61498\",\"61499\",\"614202\",\"614203\",\"614204\",\"614205\",\"614206\",\"614207\",\"614208\",\"614209\",\"614444\",\"614683\",\"614684\",\"614685\",\"614686\",\"614687\",\"614688\",\"614689\",\"614790\",\"614791\",\"614880\",\"614881\",\"614882\",\"614883\",\"614884\",\"614885\",\"614886\",\"614887\",\"614889\"]}],\"price_unit\": \"USD\",\"url\": \"https://pricing.twilio.com/v1/Voice/Countries/US\"}"
                         ));

            var response = CountryResource.Fetch("US", client: twilioRestClient);

            Assert.NotNull(response);
        }
コード例 #11
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"country\": \"United States\",\"iso_country\": \"US\",\"phone_number_prices\": [{\"number_type\": \"local\",\"base_price\": \"1.00\",\"current_price\": \"1.00\"},{\"number_type\": \"toll free\",\"base_price\": \"2.00\",\"current_price\": \"2.00\"}],\"price_unit\": \"USD\",\"url\": \"https://pricing.twilio.com/v1/PhoneNumbers/Countries/US\"}"
                         ));

            var response = CountryResource.Fetch("US", client: twilioRestClient);

            Assert.NotNull(response);
        }
コード例 #12
0
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var country = CountryResource.Fetch("EE");

        foreach (var price in country.InboundSmsPrices)
        {
            Console.WriteLine(price.CurrentPrice);
        }
    }
コード例 #13
0
        public void TestFetchRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Get,
                Twilio.Rest.Domain.Voice,
                "/v1/DialingPermissions/Countries/US",
                ""
                );

            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                CountryResource.Fetch("US", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }