sdk-go: github.com/THECALLR/sdk-go Index | Files | Directories

package callr

import "github.com/THECALLR/sdk-go"

Package callr implements the CALLR API, using JSON-RPC 2.0. See https://www.callr.com/ and https://www.callr.com/docs/.

Usage

package main

import (
    "fmt"
    "os"

    callr "github.com/THECALLR/sdk-go"
)

func main() {
    // use Basic Auth (not recommended)
    // api := callr.NewWithBasicAuth("login", "password")

    // or use Api Key Auth (recommended)
    api := api.NewWithAPIKeyAuth("key")

    // optional: set a proxy
    // api.SetProxy("http://proxy:port")

    // check for destination phone number parameter
    if len(os.Args) < 2 {
        fmt.Println("Please supply destination phone number!")
        os.Exit(1)
    }

    // Example to send a SMS
    result, err := api.Call("sms.send", "SMS", os.Args[1], "Hello, world", nil)

    // error management
    if err != nil {
        if e, ok := err.(*callr.JSONRPCError); ok {
            fmt.Printf("Remote error: code:%d message:%s data:%v\n", e.Code, e.Message, e.Data)
        } else {
            fmt.Println("Local error: ", err)
        }
        os.Exit(1)
    }

    fmt.Println(result)
}

Index

Package Files

callr.go

type API Uses

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

API represents a connection to the CALLR API.

func NewWithAPIKeyAuth Uses

func NewWithAPIKeyAuth(key string) *API

NewWithAPIKeyAuth returns an API object with an API Key Authentication.

func NewWithBasicAuth Uses

func NewWithBasicAuth(login, password string) *API

NewWithBasicAuth returns an API object with Basic Authentication (not recommended). Use NewWithAPIKeyAuth auth instead.

func (*API) Call Uses

func (api *API) Call(method string, params ...interface{}) (interface{}, error)

Call sends a JSON-RPC 2.0 request to the CALLR API, and returns either a result, or an error. The error may be of type JSONRPCError if the error comes from the API, or a native error if the error is local.

func (*API) SetProxy Uses

func (api *API) SetProxy(proxy string) error

SetProxy sets a proxy URL to use

func (*API) SetURL Uses

func (api *API) SetURL(url string) error

SetURL changes the URL for the API object

type JSONRPCError Uses

type JSONRPCError struct {
    Code    int64       `json:"code"`
    Message string      `json:"message"`
    Data    interface{} `json:"data"`
}

JSONRPCError is a JSON-RPC 2.0 error, returned by the API. It satisfies the native error interface.

func (*JSONRPCError) Error Uses

func (e *JSONRPCError) Error() string

Error implements the error interface. Returns a string with the Code and Message properties.

Directories

PathSynopsis
samples

Package callr imports 10 packages (graph) and is imported by 1 packages. Updated 2019-12-11. Refresh now. Tools for package owners.