2017 © Pedro Peláez
 

library nexmo-client

Unofficial Nexmo Rest Client

image

connect-corp/nexmo-client

Unofficial Nexmo Rest Client

  • Tuesday, April 19, 2016
  • by vood
  • Repository
  • 16 Watchers
  • 16 Stars
  • 88,651 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 14 Forks
  • 5 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

nexmo-client Build Status Code Climate

Unofficial Nexmo Rest Client, (*1)

Documentation

Nexmo API Documentation, (*2)

How to Install

$ composer require connect-corp/nexmo-client

Usage examples

Setting up the client object

    $apiKey = 'api_key_from_nexmo_account';
    $apiSecret = 'api_secret_from_nexmo_account';
    $nexmo = new \Nexmo\Client($apiKey, $apiSecret);

Sending a message

    $from = '1234567890';
    $to = '15551232020';
    $text = 'hello world';
    try {
        $response = $nexmo->message->invoke($from, $to, 'text', $text);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    foreach ($response['messages'] as $i => $m) {
        switch ($m['status']) {
        case '0':
            echo 'Message sent successfully:';
            print_r($m);
            break;

        default:
            echo 'Message sending failed:'
            print_r($m);
            break;
        }
    }

Getting account balance

    try {
        $response = $nexmo->account->balance();
    } catch (Exception $e) {
        die($e->getMessage());
    }
    echo "Account balance is $response";

Getting pricing by destination country

    $country = 'US';
    try {
        $response = $nexmo->account->pricing->country($country);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    echo 'Price is ' . $response->price();

Getting pricing by recipient number

    $number = '15551232020';
    try {
        // SMS pricing.
        $response = $nexmo->account->pricing->sms($number);
        // Voice pricing.
        $response = $nexmo->account->pricing->voice($number);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    echo 'Price is ' . $response->price();

Search for long virtual numbers by country

    $country = 'US';
    try {
        $response = $nexmo->number->search($country);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    $all = $response->all();
    if (isset($all['numbers'])) {
        foreach ($all['numbers'] as $n) {
            printf("%d  \$%01.2f  %-10s  %-15s\n", $n['msisdn'], $n['cost'], $n['type'], join(',', $n['features']));
        }
    }

Buy a long virtual number

    $country = 'US';
    $msisdn = '1234567890'; // Number found using $nexmo->number->search()
    try {
        $response = $nexmo->number->buy($country, $msisdn);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    if (200 == $response['error-code']) {
        echo 'Number purchase success';
    }

List long virtual numbers in your account

    $country = 'US';
    try {
        $response = $nexmo->account->numbers();
    } catch (Exception $e) {
        die($e->getMessage());
    }
    $all = $response->all();
    if (isset($all['numbers'])) {
        foreach ($all['numbers'] as $n) {
            printf("%d  %-2s  %-10s  %-15s\n", $n['msisdn'], $n['country'], $n['type'], join(',', $n['features']));
        }
    }

Cancel a long virtual number

    $country = 'US';
    $msisdn = '1234567890'; // Number found using $nexmo->account->numbers()
    try {
        $response = $nexmo->number->cancel($country, $msisdn);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    if (200 == $response['error-code']) {
        echo 'Number cancel success';
    }

Contributors

https://github.com/ConnectCorp/nexmo-client/network/members, (*3)

The Versions

19/04 2016

dev-master

9999999-dev

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

19/05 2015

0.1.0

0.1.0.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

04/03 2015

0.0.7

0.0.7.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

04/03 2015

0.0.6

0.0.6.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

04/03 2015

0.0.5

0.0.5.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

27/02 2015

0.0.4

0.0.4.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

27/02 2015

0.0.3

0.0.3.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib

27/02 2015

0.0.2

0.0.2.0 https://github.com/ConnectCorp/nexmo-client

Unofficial Nexmo Rest Client

  Sources   Download

MIT

The Requires

 

The Development Requires

nexmo sdk lib