Giter Club home page Giter Club logo

textmagic-rest-csharp's Introduction

TextMagic C# / .Net SDK

This library provides you with an easy way to send SMS and receive replies, by integrating the TextMagic SMS Gateway into your C# / .Net application.

What Is TextMagic?

TextMagic’s application programming interface (API) provides the communication link between your application and TextMagic’s SMS Gateway, allowing you to send and receive text messages and to check the delivery status of text messages you’ve already sent.

Frameworks supported

  • .NET 4.0 or later
  • Windows Phone 7.1 (Mango)

Dependencies

The DLLs included in the package may not be the latest versions. We recommend using NuGet to obtain the latest version of the packages:

Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes

NOTE: RestSharp versions later than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742

Installation

Add the library to your project references or install it as a NuGet package.

C# usage example

using System;
using System.IO;
using TextMagicClient.Api;
using TextMagicClient.Client;
using TextMagicClient.Model;

namespace ExampleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure HTTP basic authorization: BasicAuth
            Configuration.Default.Username = "YOUR_USERNAME";
            Configuration.Default.Password = "YOUR_PASSWORD";
            Configuration.Default.BasePath = "https://rest.textmagic.com";

            var apiInstance = new TextMagicApi();

            // Simple Ping request sample
            try
            {
                var result = apiInstance.Ping();
                Console.WriteLine(result.Ping);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling TextMagicApi.Ping: " + e.Message );
            }

            // Send a new message request sample
            try
            {
                var sendMessageInputObject = new SendMessageInputObject
                {
                    Text = "I love TextMagic!", Phones = "+199988887766"
                };

                var result = apiInstance.SendMessage(sendMessageInputObject);
                Console.WriteLine(result.Id);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling TextMagicApi.SendMessage: " + e.Message );
            }

            // Get all outgoing messages sample
            try
            {
                var result = apiInstance.GetAllOutboundMessages(1, 10);
                Console.WriteLine(result.Resources[0].Id);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling TextMagicApi.GetAllOutboundMessages: " + e.Message );
            }

            // Upload list avatar sample, 3223 here is a sample list id
            try
            {
                var stream = File.Open("/CustomPath/Images/test.png", FileMode.Open);
                var result = apiInstance.UploadListAvatar(stream, 3223);
                Console.WriteLine(result.Href);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when calling TextMagicApi.UploadListAvatar: " + e.Message );
            }
        }
    }
}

VB.Net usage example

Imports System
Imports System.IO
Imports TextMagicClient.Api
Imports TextMagicClient.Client
Imports TextMagicClient.Model

Module Program
    Sub Main(args As String())
        Configuration.Default.Username = "YOUR_USERNAME"
        Configuration.Default.Password = "YOUR_PASSWORD"
        Configuration.Default.BasePath = "https://rest.textmagic.com"

        Dim apiInstance = New TextMagicApi()

        ' Simple Ping request sample
        Try
            Dim result = apiInstance.Ping()
            Console.WriteLine(result.Ping)
            Catch ex As Exception
            Console.WriteLine("Exception when calling TextMagicApi.Ping: " + ex.Message )
        End Try

        ' Send a new message request sample
        Try
            Dim sendMessageInputObject = New SendMessageInputObject With {
            .Text = "I love TextMagic!",
            .Phones = "+199988887766"
            }
            Dim result = apiInstance.SendMessage(sendMessageInputObject)
            Console.WriteLine(result.Id)
        Catch e As Exception
            Console.WriteLine("Exception when calling TextMagicApi.SendMessage: " & e.Message)
        End Try

        ' Get all outgoing messages sample
        Try
            Dim result = apiInstance.GetAllOutboundMessages(1, 10)
            Console.WriteLine(result.Resources(0).Id)
        Catch e As Exception
            Console.WriteLine("Exception when calling TextMagicApi.GetAllOutboundMessages: " & e.Message)
        End Try

        ' Upload list avatar sample, 3223 here is a sample list id
        Try
            Dim stream = File.Open("/CustomPath/Images/test.png", FileMode.Open)
            Dim result = apiInstance.UploadListAvatar(stream, 3223)
            Console.WriteLine(result.Href)
        Catch e As Exception
            Console.WriteLine("Exception when calling TextMagicApi.UploadListAvatar: " & e.Message)
        End Try
    End Sub
End Module

License

The library is available as open source under the terms of the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.