Skip to content

jberke/plivo-dotnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Plivo C#.NET Helper Library

About

Plivo C#.NET Helper Library simplifies the process of making Plivo API calls and generating Plivo XML.

Getting Started

Minimum Prerequisites

  1. Windows 7
  2. Microsoft Visual Studio 2010
  3. NuGet Package Manger

NOTE: NuGET Package Manager installation procedure can be found in the NuGet Documentation here

Installation

This helper library can be installed / used in two ways,

  1. From Source.
  2. From the NuGet Package Manager (recommended).

From Source

To use this library from source follow the instructions below,

  • Get the source from Github using git clone or using the download link.
  • Open the solution file in Visual Studio.
  • Install NuGet Package Manager.
  • Go to Tools -> Library Package Manager -> Packager Manager Console.
  • Enter the following commands in the console to install RestSharp (a Simple REST and HTTP API Client) and Json.NET (a popular high-performance JSON framework for .NET),
PM> Install-Package RestSharpSigned -Version 105.1.0
PM> Install-Package Newtonsoft.Json -Version 7.0.1
  • Once the RestSharp and Json.NET packages are successfully installed, close the console. Right Click on the solution (in this case Plivo) in the Solution Explorer and click Clean and then Build.
  • Next, to start using it in your project, Right Click on your Project Name in the Solution Explorer and click Add Reference. In the dialog box which appears, go to the Browse tab and Navigate to plivo-dotnet\Plivo\bin\Debug and select the Plivo.dll and click OK.
  • Now, you can use Plivo in your code!

From NuGet Package Manager

  • Install NuGet Package Manager.
  • Go to Tools -> Library Package Manager -> Packager Manager Console.
  • RestSharp and Json.NET are automatically installed as a dependency.
PM> Install-Package Plivo

If you already have RestSharp or Json.NET installed, its best to uninstall it before installing the specific version.

PM> Uninstall-Package RestSharp -Force
PM> Uninstall-Package Newtonsoft.Json -Force
PM> Install-Package Plivo

Examples

Plivo.API

using System;
using System.Collections.Generic;
using System.Reflection;
using RestSharp;
using Plivo.API;

namespace SampleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string auth_id = "XXX";  // obtained from Plivo account dashboard
            string auth_token = "YYY";  // obtained from Plivo account dashboard

            // Creating the Plivo Client
            RestAPI plivo = new RestAPI(auth_id, auth_token);

            // Making a Call
            string from_number = "XXXXXXXXXXX";
            string to_number = "YYYYYYYYYYY";

            IRestResponse<Call> response = plivo.make_call(new Dictionary<string, string>() {
                { "from", from_number },
                { "to", to_number }, 
                { "answer_url", "http://some.domain.com/answer/" }, 
                { "answer_method", "GET" }
            });

            // The "Outbound call" API response has four properties -
            // message, request_uuid, error, and api_id.
            // error - contains the error response sent back from the server.
            if (response.Data != null)
            {
                PropertyInfo[] properties = response.Data.GetType().GetProperties();
                foreach (PropertyInfo property in properties)
                    Console.WriteLine("{0}: {1}", property.Name, property.GetValue(response.Data, null));
            }
            else
            {
                // ErrorMessage - contains error related to network failure.
                Console.WriteLine(response.ErrorMessage);
            }
            Console.Read();
        }
    }
}

Plivo.API

using System;
using System.Collection.Generic;
using Plivo.XML;

namespace SampleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Response response = new Response();
            // add 'Speak' element to 'Response'
            response.AddSpeak("Go green, go Plivo", 
                new Dictionary<string, string>() {
                    { "loop", "3" },
                    { "language", "en-US");
            });

            // or you can add as below
            // Speak speak = new Speak("Go green, go Plivo", 
            //    new Dictionary<string, string>() {
            //         { "loop", "3" },
            //         { "language", "en-US");
            // });
            // response.Add(speak);

            Console.WriteLine(response.ToString());
            Console.Read();
        }
    }
}

License

The MIT License (MIT)
Copyright (c) 2013 Plivo Inc

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"), 
to deal in the Software without restriction, including without limitation the 
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
sell copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in 
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Packages

No packages published

Languages

  • C# 100.0%