Giter Club home page Giter Club logo

textmagic-rest-cpp's Introduction

TextMagic C++ SDK

This library provides you with an easy way to send SMS and receive replies, by integrating the TextMagic SMS Gateway into your C++ 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.

For detailed documentation, please visit http://docs.textmagictesting.com/.

Requirements

Ubuntu dependencies quick installation example:

apt-get install build-essential cmake libcpprest-dev

Installation

Download and extract lib archive:

wget https://github.com/imissyouso/textmagic-rest-cpp/archive/v2.0.650.tar.gz && \
tar zxf v2.0.650.tar.gz && \
rm -f v2.0.650.tar.gz && \
cd textmagic-rest-cpp-2.0.650

Build using cmake

cmake . && cmake --build .

The output library file will be placed in textmagic-rest-cpp-2.0.650/lib directory:

Usage Example

In the example below, we assume that you moved the library sources textmagic-rest-cpp-2.0.650 directory to your test project root directory.

Configure your CMakeLists.txt as shown here:

cmake_minimum_required(VERSION 2.8)
project(test)

set(CMAKE_CXX_STANDARD 14)

add_executable(app main.cpp)

add_library(textmagic_client SHARED IMPORTED)
set_property(TARGET textmagic_client PROPERTY IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/textmagic-rest-cpp-2.0.650/lib/libtextmagic_client.so")

target_include_directories (app PRIVATE ${PROJECT_SOURCE_DIR}/textmagic-rest-cpp-2.0.650 ${PROJECT_SOURCE_DIR}/textmagic-rest-cpp-2.0.650/model ${PROJECT_SOURCE_DIR}/textmagic-rest-cpp-2.0.650/api)
target_link_libraries(app boost_system cpprest crypto textmagic_client )

main.cpp file example:

#include <iostream>
#include <fstream>
#include "textmagic-rest-cpp-2.0.650/ApiClient.h"
#include "textmagic-rest-cpp-2.0.650/ApiConfiguration.h"
#include "textmagic-rest-cpp-2.0.650/api/TextMagicApi.h"

using namespace com::textmagic::client::api;

int main() {
    std::shared_ptr<ApiClient> apiClient(new ApiClient);
    std::shared_ptr<ApiConfiguration> apiConfig(new ApiConfiguration);

    apiConfig->setBaseUrl("https://rest.textmagic.com");
    apiConfig->getHttpConfig().set_credentials(web::credentials("YOUR_NAME", "YOUR_PASSWORD"));
    apiClient->setConfiguration(apiConfig);

    TextMagicApi api(apiClient);

    // Simple ping request example
    pplx::task<std::shared_ptr<PingResponse>> pingResponse = api.ping();
    pingResponse.wait();

    try {
        std::cout << pingResponse.get()->getPing() << '\n';
    } catch(const std::exception& e) {
        std::cout << "getPing() exception: " << e.what() << '\n';
    }

    // Send a new message request example
    std::shared_ptr<SendMessageInputObject> sendMessageInputObject(new SendMessageInputObject);
    sendMessageInputObject->setPhones("+19998887766");
    sendMessageInputObject->setText("I love TextMagic!");

    pplx::task<std::shared_ptr<SendMessageResponse>> sendMessageResponse = api.sendMessage(sendMessageInputObject, false);
    sendMessageResponse.wait();

    try {
        std::cout << sendMessageResponse.get()->getId() << '\n';
    } catch(const std::exception& e) {
        std::cout << "getId() exception: " << e.what() << '\n';
    }

    // Get all outgoing messages request example
    pplx::task<std::shared_ptr<GetAllOutboundMessagesResponse>> getAllOutboundMessagesResponse = api.getAllOutboundMessages(boost::none, boost::none, boost::none);
    getAllOutboundMessagesResponse.wait();

    try {
        std::cout << getAllOutboundMessagesResponse.get()->getResources()[0]->getId() << '\n';
    } catch(const std::exception& e) {
        std::cout << "getId() exception: " << e.what() << '\n';
    }

    // Upload list avatar request example
    std::filebuf fb;
    fb.open ("test.jpg", std::ios::in);
    std::shared_ptr<std::istream> is(new std::istream(&fb));

    std::shared_ptr<HttpContent> image(new HttpContent);
    image->setName("test");
    image->setContentDisposition("attachment");
    image->setFileName("test.jpg");

    image->setContentType("image/jpeg");
    image->setData(is);

    // List ID in current example is 3223
    pplx::task<std::shared_ptr<ResourceLinkResponse>> resourceLinkResponse = api.uploadListAvatar(image, 3223);
    resourceLinkResponse.wait();

    try {
        std::cout << resourceLinkResponse.get()->getId() << '\n';
    } catch(const std::exception& e) {
        std::cout << "getId() exception: " << e.what() << '\n';
    }

    return 0;
}

Build your test project:

cmake . && cmake --build .

Run:

./app

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.