nexmo

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

README

Build Status Go Report Card GoDoc

nexmo-go

Nexmo REST API client for Go.

Hugely inspired by: https://github.com/kevinburke/twilio-go

As it's a WIP it only supports SMS and TTS Call sending by now.

Install

Assuming you have your $GOPATH set:

$> go get github.com/lopezator/nexmo-go
$> cd $GOPATH/src/lopezator/nexmo-go
$> make install

Usage

nexmo-go is pretty straightforward to use, anyway, you can find some examples ready to run in the examples/ folder in addition to usage info below.

Send a SMS

const apiKey = "my-api-key"
const apiSecret = "my-api-secret"

// Create a client
client := nexmo.NewClient(apiKey, apiSecret, nil)

// Send a message
// Nexmo allows to use your either a random text as `from` value or your nexmo phone with country code but without "+" or "00" prefix
msg, err := client.Messages.SendMessage("ME", "34666666666", "Message sent via nexmo-go")

Make a TTS Call

const apiKey = "my-api-key"
const apiSecret = "my-api-secret"

// Create a client
client := nexmo.NewClient(apiKey, apiSecret, nil)

// Make a TTS call
msg, err := client.Calls.MakeTTSCall("15111111111", "34666666666", "TTS call sent via nexmo-go", "5")

Documentation

Index

Constants

View Source
const Version = "0.1"

Version of the program

Variables

This section is empty.

Functions

This section is empty.

Types

type Call added in v0.2.0

type Call struct {
	CallID    string `json:"call_id"`
	To        string `json:"to"`
	Status    string `json:"status"`
	ErrorText string `json:"error_text"`
}

Call holds call response data

type CallService added in v0.2.0

type CallService struct {
	// contains filtered or unexported fields
}

CallService is the client holding calling capatibilites

func (*CallService) Create added in v0.2.0

func (c *CallService) Create(ctx context.Context, data url.Values) (*Call, error)

Create creates a call resource

func (*CallService) MakeTTSCall added in v0.2.0

func (c *CallService) MakeTTSCall(from string, to string, text string, repeat string) (*Call, error)

MakeTTSCall makes an outbound Call reproducing using TTS with the given text.

type Client

type Client struct {
	*rest.Client

	APIKey    string
	APISecret string

	// FullPath takes a path part (e.g. "Messages") and returns the full API path, including the version (e.g. "/sms").
	FullPath func(pathPart string) string

	// The API Client uses these resources
	Messages *MessageService
	Calls    *CallService
}

Client holds all the necessary data to handle nexmo API

func NewClient

func NewClient(apiKey string, apiSecret string, httpClient *http.Client) *Client

NewClient creates a Client for interacting with the Nexmo API. This is the main entrypoint for API interactions; view the methods on the subresources for more information.

func (*Client) CreateResource

func (c *Client) CreateResource(ctx context.Context, pathPart string, data url.Values, v interface{}) error

CreateResource handles POST requests

func (*Client) MakeRequest

func (c *Client) MakeRequest(ctx context.Context, method string, pathPart string, data url.Values, v interface{}) error

MakeRequest makes a request to the Nexmo API.

type Message

type Message struct {
	MessageCount string `json:"message-count"`
	Messages     []struct {
		To               string `json:"to"`
		MessageID        string `json:"message-id"`
		Status           string `json:"status"`
		ClientReference  string `json:"client-ref"`
		RemainingBalance string `json:"remaining-balance"`
		MessagePrice     string `json:"message-price"`
		Network          string `json:"network"`
		ErrorText        string `json:"error-text"`
	} `json:"messages"`
}

Message holds message response data

type MessageService

type MessageService struct {
	// contains filtered or unexported fields
}

MessageService is the client holding messaging capatibilites

func (*MessageService) Create

func (m *MessageService) Create(ctx context.Context, data url.Values) (*Message, error)

Create creates a message resource

func (*MessageService) SendMessage

func (m *MessageService) SendMessage(from string, to string, text string) (*Message, error)

SendMessage sends an outbound Message with the given text.

Directories

Path Synopsis
examples
sms command
tts command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL