api

package module
v0.0.0-...-c26fdb2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

README

goexotel GoDoc  Report Card

[Deprecated] - The REST service used here is not active any more

What is it?

GoExotel is a exotel platform api client written in golang

resources
  • Account
  • IncomingPhoneNumber
  • OutgoingCallerID
  • AvailablePhoneNumber
  • Call
  • Recording
how to use

Install the library using go get

go get github.com/exotel/goapi

or for keeping the version number

go get gopkg.in/exotel/goapi.v0 //for version v0.x.x
using the client

initiate the client

credentials := types.Credentials{
  UserCredentials:   types.UserCredentials{AccessToken: "APIAccessToken", UserName: "APIUsername"},
  ClientCredentials: types.ClientCredentials{ClientID: "CLIENT_id", ClientSecret: "CLIENT_SECRET"},
}
client = api.New(credentials)
client.SetAccountSid("<ACCOUNT_SID>") //parent working

for adding a sub account

c := client.
  Account().
  Create().
  Details(resources.AccountDetails{FriendlyName: "SARATH TESTING", CountryCode: "SNG"})
if status, data, err := c.Do(); err != nil {
  fmt.Printf(err.Error())
} else {
  fmt.Printf("No Error occured while doing the operation\nstatus : %d\ndata%v", status, data)
}
For any resource do the following

consider resource is Resource and the CRUD is allowed for Resource

1 . Create Request

client.Resource().Create().Details(resources.ResourceDetails{}).Do

2 . Read Request

  • bulk
client.Resource().Get().Filter(resources.ResourceFilter{}).Do()
  • Single
client.Resource().ID(string).Get().Do

3 . Update Request

client.Resource().ID(string).Update().UpdateDetails(resources.ResourceUpdatableDetails{}).Do

4 . Delete Request

client.Resource().ID(string).Delete().Do()
Sample Code
package main

import (
	"fmt"

	api "github.com/exotel/goapi"
	"github.com/exotel/goapi/assets/types"
	"github.com/exotel/goapi/resources"
)

func initClient() (client *api.Client) {
	credentials := types.Credentials{
		UserCredentials:   types.UserCredentials{AccessToken: "APIAccessToken", UserName: "APIUsername"},
		ClientCredentials: types.ClientCredentials{ClientID: "CLIENT_id", ClientSecret: "CLIENT_SECRET"},
	}
	client = api.New(credentials)
	client.SetAccountSid("<ACCOUNT_SID>") //parent working
	return
}


//ExampleCall Create call example
func ExampleCall(client *api.Client) {
	var callDetails resources.CallDetails
	callDetails.From = "+918030752401"
	callDetails.To = "+919742033616"
	callDetails.URL = "http://98ae7c6f.ngrok.io/dial/+919742033616"
	callDetails.Method = "GET"

	if status, data, err := client.Debug(true).Call().Create().Details(callDetails).Do(); err != nil {
		fmt.Println("error occured", err.Error())

	} else {
		fmt.Printf("No Error occured while doing the operation\nstatus : %d\ndata%v", status, data)
	}
}

func main() {
	client := initClient()
  //makes a call
	ExampleCall(client)
}

What if i don't have go installed ?

This is how you can install go in linux [this is for version 1.8 of golang]

wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

now you have go installed,try checking by checking the version

go version

Now you have to set the Workspace,say you are setting,~/go as the worksapce this is how it is done

export GOPATH=$HOME/go
export GOROOT=/usr/local/go

Add these two export statements in ~/.bashrc so that it is set all the time Now you are ready to test goapi,get the library using go get ie,

go get github.com/exotel/goapi

Now you can copy paste the sample codes from example folder to path/to/filename.go and test by running as

go run path/to/filename.go
contributions

sarath@exotel.in

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService

type AccountService struct {
	Client
}

AccountService is the struct that defines the account information and has fubnctions to perform account level

func (*AccountService) Create

func (__receiver_AService *AccountService) Create() *AccountService

Create sets the action as create

func (*AccountService) Details

func (__receiver_AService *AccountService) Details(details resources.AccountDetails) *AccountService

Details set the resource details for create resource requests

func (*AccountService) Filter

func (__receiver_AService *AccountService) Filter(filter resources.AccountFilter) *AccountService

Filter set the filter for read operation for read

func (*AccountService) Get

func (__receiver_AService *AccountService) Get() *AccountService

Get sets the action as types.READ

func (*AccountService) ID

func (__receiver_AService *AccountService) ID(id string) *AccountService

ID sets the id for the resource request

func (*AccountService) Update

func (__receiver_AService *AccountService) Update() *AccountService

Update sets the action as update

func (*AccountService) UpdateDetails

func (__receiver_AService *AccountService) UpdateDetails(details resources.AccountUpdatableDetails) *AccountService

UpdateDetails sets the details to be updated for the resource

type AvailablePhoneNumberService

type AvailablePhoneNumberService struct {
	Client
}

AvailablePhoneNumberService is the struct that defines the availablephonenumber information and has fubnctions to perform availablephonenumber level

func (*AvailablePhoneNumberService) Filter

Filter set the filter for read operation for read

func (*AvailablePhoneNumberService) Get

func (__receiver_AService *AvailablePhoneNumberService) Get() *AvailablePhoneNumberService

Get sets the action as types.READ

func (*AvailablePhoneNumberService) ID

func (__receiver_AService *AvailablePhoneNumberService) ID(id string) *AvailablePhoneNumberService

ID sets the id for the resource request

type CallService

type CallService struct {
	Client
}

CallService is the struct that defines the call information and has fubnctions to perform call level

func (*CallService) Create

func (__receiver_CService *CallService) Create() *CallService

Create sets the action as create

func (*CallService) Details

func (__receiver_CService *CallService) Details(details resources.CallDetails) *CallService

Details set the resource details for create resource requests

func (*CallService) Filter

func (__receiver_CService *CallService) Filter(filter resources.CallFilter) *CallService

Filter set the filter for read operation for read

func (*CallService) Get

func (__receiver_CService *CallService) Get() *CallService

Get sets the action as types.READ

func (*CallService) ID

func (__receiver_CService *CallService) ID(id string) *CallService

ID sets the id for the resource request

type Client

type Client struct {
	AccountSid string `url:"AccountSid"`
	UserName   string
	ResourceID string `url:"ResourceID"`

	Credentials types.Credentials
	// contains filtered or unexported fields
}

Client is the iam client struct that calls all the other services

func New

func New(cr types.Credentials) *Client

New Creates an instance of iam client

func (*Client) Account

func (c *Client) Account() *AccountService

Account returns an instance of AccountService

func (*Client) AvailablePhoneNumber

func (c *Client) AvailablePhoneNumber() *AvailablePhoneNumberService

AvailablePhoneNumber returns an instance of AvailablePhoneNumberService

func (*Client) Call

func (c *Client) Call() *CallService

Call returns an instance of CallService

func (*Client) Debug

func (c *Client) Debug(debug bool) *Client

Debug set the client in debug mode

func (*Client) Do

func (c *Client) Do() (status int, result map[string]interface{}, err error)

Do does the actual job

func (*Client) IncomingPhoneNumber

func (c *Client) IncomingPhoneNumber() *IncomingPhoneNumberService

IncomingPhoneNumber returns an instance of IncomingPhoneNumberService

func (Client) IsValidAction

func (c Client) IsValidAction() (ok bool, err error)

IsValidAction Checks if there are enough details for the execution It checks for if an action is set and if set is it a valid action on that resources For example if a resource does not accept POST then action being POST would return error

func (Client) IsValidCredentials

func (c Client) IsValidCredentials() (ok bool, err error)

IsValidCredentials Checks if the available credentials are valid or not checks if credentials are provided ,it does not check if the provided credentials are valid or not

func (Client) IsValidData

func (c Client) IsValidData() (ok bool, err error)

IsValidData checks if the data is valid or not It uses the tag `mandatory` to see if a field is mandatory or not

func (*Client) OutgoingCallerID

func (c *Client) OutgoingCallerID() *OutgoingCallerIDService

OutgoingCallerID returns an instance of OutgoingCallerIDService

func (*Client) Recording

func (c *Client) Recording() *RecordingService

Recording returns an instance of RecordingService

func (*Client) SetAccountSid

func (c *Client) SetAccountSid(accountSid string) *Client

SetAccountSid sets the account sid of the user

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(url string) *Client

SetBaseURL sets the base url for making api requests

func (*Client) SetLogger

func (c *Client) SetLogger(logger *log.Logger) *Client

SetLogger sets logger for the class

func (*Client) SetUserName

func (c *Client) SetUserName(userName string) *Client

SetUserName sets the user name of the user

type IncomingPhoneNumberService

type IncomingPhoneNumberService struct {
	Client
}

IncomingPhoneNumberService is the struct that defines the incomingphonenumber information and has fubnctions to perform incomingphonenumber level

func (*IncomingPhoneNumberService) Create

func (__receiver_IService *IncomingPhoneNumberService) Create() *IncomingPhoneNumberService

Create sets the action as create

func (*IncomingPhoneNumberService) Delete

func (__receiver_IService *IncomingPhoneNumberService) Delete() *IncomingPhoneNumberService

Delete sets the action as types.DELETE

func (*IncomingPhoneNumberService) Details

Details set the resource details for create resource requests

func (*IncomingPhoneNumberService) Filter

Filter set the filter for read operation for read

func (*IncomingPhoneNumberService) Get

func (__receiver_IService *IncomingPhoneNumberService) Get() *IncomingPhoneNumberService

Get sets the action as types.READ

func (*IncomingPhoneNumberService) ID

func (__receiver_IService *IncomingPhoneNumberService) ID(id string) *IncomingPhoneNumberService

ID sets the id for the resource request

func (*IncomingPhoneNumberService) Update

func (__receiver_IService *IncomingPhoneNumberService) Update() *IncomingPhoneNumberService

Update sets the action as update

func (*IncomingPhoneNumberService) UpdateDetails

UpdateDetails sets the details to be updated for the resource

type OutgoingCallerIDService

type OutgoingCallerIDService struct {
	Client
}

OutgoingCallerIDService is the struct that defines the outgoingcallerid information and has fubnctions to perform outgoingcallerid level

func (*OutgoingCallerIDService) Create

func (__receiver_OService *OutgoingCallerIDService) Create() *OutgoingCallerIDService

Create sets the action as create

func (*OutgoingCallerIDService) Delete

func (__receiver_OService *OutgoingCallerIDService) Delete() *OutgoingCallerIDService

Delete sets the action as types.DELETE

func (*OutgoingCallerIDService) Details

Details set the resource details for create resource requests

func (*OutgoingCallerIDService) Filter

Filter set the filter for read operation for read

func (*OutgoingCallerIDService) Get

func (__receiver_OService *OutgoingCallerIDService) Get() *OutgoingCallerIDService

Get sets the action as types.READ

func (*OutgoingCallerIDService) ID

func (__receiver_OService *OutgoingCallerIDService) ID(id string) *OutgoingCallerIDService

ID sets the id for the resource request

type RecordingService

type RecordingService struct {
	Client
}

RecordingService is the struct that defines the recording information and has fubnctions to perform recording level

func (*RecordingService) Filter

func (__receiver_RService *RecordingService) Filter(filter resources.RecordingFilter) *RecordingService

Filter set the filter for read operation for read

func (*RecordingService) Get

func (__receiver_RService *RecordingService) Get() *RecordingService

Get sets the action as types.READ

func (*RecordingService) ID

func (__receiver_RService *RecordingService) ID(id string) *RecordingService

ID sets the id for the resource request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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