twiliogo

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

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

Go to latest
Published: Sep 2, 2015 License: MIT Imports: 7 Imported by: 0

README

Build Status

twilio-go

The unofficial Go helper library for Twilio.

Installation

go get github.com/carlosdp/twiliogo

Documentation

GoDoc

Usage

Send a Text

package main

import (
  "fmt"
  twilio "github.com/carlosdp/twiliogo"
)

func main() {
  client := twilio.NewClient("<ACCOUNT_SID", "<AUTH_TOKEN>", nil)

  message, err := twilio.NewMessage(client, "3334445555", "2223334444", twilio.Body("Hello World!"))

  if err != nil {
    fmt.Println(err)
  } else {
    fmt.Println(message.Status)
  }
}

Make a Call

package main

import (
  "fmt"
  twilio "github.com/carlosdp/twiliogo"
)

func main() {
  client := twilio.NewClient("<ACCOUNT_SID>", "<AUTH_TOKEN>", nil)

  call, err := twilio.NewCall(client, "8883332222", "3334443333", nil)

  if err != nil {
    fmt.Println(err)
  } else {
    fmt.Println("Call Queued!")
  }
}

Implemented Resources

  • Calls
  • Messages
  • IncomingPhoneNumbers (partial)

Run Tests

Tests can be run using go test, as with most golang projects. This project also contains integration tests (where they can be done non-destructively using the API or the working Test Credential endpoints).

These integration tests can be run by providing the necessary environment variables to access the API, as in this Makefile:

test:
	@export API_KEY="<API KEY>";\
	export API_TOKEN="<API TOKEN>";\
	export TEST_KEY="<TEST KEY>";\
	export TEST_TOKEN="<TEST TOKEN>";\
	export TEST_FROM_NUMBER="<DEFAULT TEST CRED NUMBER>";\
	export FROM_NUMBER="<TEST FROM NUMBER>";\
	export TO_NUMBER="<TEST TO NUMBER>";\
	go test -v

Contributing

This is a side project meant to allow for quick adoption of the Twilio API for those programming web applications with it in Go. Feel free to submit pull requests so that we can cover all of the features the Twilio API has to offer!

To Do

Here are a few things that the project needs in order to reach v1.0:

  1. Complete test coverage. Right now, tests cover the bare minimum of usage for each feature implemented.
  2. Complete IncomingPhoneNumber functionality.
  3. Implement the following resources:
  • AvailablePhoneNumbers
  • OutgoingCallerIds
  • Applications
  • ConnectApps
  • AuthorizedConnectApps
  • Conferences
  • Queues
  • Short Codes
  • Recordings
  • Transcriptions
  • Notifications
  • SIP Domains
  • IpAccessControlLists
  • CredentialLists
  • Usage Records
  • Usage Triggers

License

This project is licensed under the MIT License

Documentation

Index

Constants

View Source
const ROOT = "https://api.twilio.com"
View Source
const VERSION = "2010-04-01"

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationSid

type ApplicationSid string

func (ApplicationSid) GetParam

func (applicationSid ApplicationSid) GetParam() (string, string)

type AreaCode

type AreaCode string

func (AreaCode) GetParam

func (areaCode AreaCode) GetParam() (string, string)

type Body

type Body string

func (Body) GetParam

func (body Body) GetParam() (string, string)

type Call

type Call struct {
	Sid            string `json:"sid"`
	ParentCallSid  string `json:"parent_call_sid"`
	DateCreated    string `json:"date_created"`
	DateUpdated    string `json:"date_updated"`
	AccountSid     string `json:"account_sid"`
	To             string `json:"to"`
	From           string `json:"from"`
	PhoneNumberSid string `json:"phone_number_sid"`
	Status         string `json:"status"`
	StartTime      string `json:"start_time"`
	EndTime        string `json:"end_time"`
	Duration       string `json:"duration"`
	Price          string `json:"price"`
	PriceUnit      string `json:"price_unit"`
	Direction      string `json:"direction"`
	AnsweredBy     string `json:"answered_by"`
	ForwardedFrom  string `json:"forwarded_from"`
	CallerName     string `json:"caller_name"`
	Uri            string `json:"uri"`
}

func GetCall

func GetCall(client Client, sid string) (*Call, error)

func NewCall

func NewCall(client Client, from, to string, callback Optional, optionals ...Optional) (*Call, error)

func (*Call) Update

func (call *Call) Update(client Client, optionals ...Optional) error

type CallList

type CallList struct {
	Client          Client
	Start           int    `json:"start"`
	Total           int    `json:"total"`
	NumPages        int    `json:"num_pages"`
	Page            int    `json:"page"`
	PageSize        int    `json:"page_size"`
	End             int    `json:"end"`
	Uri             string `json:"uri"`
	FirstPageUri    string `json:"first_page_uri"`
	LastPageUri     string `json:"last_page_uri"`
	NextPageUri     string `json:"next_page_uri"`
	PreviousPageUri string `json"previous_page_uri"`
	Calls           []Call `json:"calls"`
}

func GetCallList

func GetCallList(client Client, optionals ...Optional) (*CallList, error)

func (*CallList) FirstPage

func (currentCallList *CallList) FirstPage() (*CallList, error)

func (*CallList) GetCalls

func (callList *CallList) GetCalls() []Call

func (*CallList) HasNextPage

func (currentCallList *CallList) HasNextPage() bool

func (*CallList) HasPreviousPage

func (currentCallList *CallList) HasPreviousPage() bool

func (*CallList) LastPage

func (currentCallList *CallList) LastPage() (*CallList, error)

func (*CallList) NextPage

func (currentCallList *CallList) NextPage() (*CallList, error)

func (*CallList) PreviousPage

func (currentCallList *CallList) PreviousPage() (*CallList, error)

type Callback

type Callback string

func (Callback) GetParam

func (callback Callback) GetParam() (string, string)

type Capabilites

type Capabilites struct {
	Voice bool `json:"voice"`
	SMS   bool `json:"SMS"`
	MMS   bool `json:"MMS"`
}

type Client

type Client interface {
	AccountSid() string
	AuthToken() string
	RootUrl() string
	// contains filtered or unexported methods
}

type DateSent

type DateSent string

func (DateSent) GetParam

func (dateSent DateSent) GetParam() (string, string)

type Error

type Error struct {
	Description string
}

func (Error) Error

func (e Error) Error() string

type FallbackMethod

type FallbackMethod string

func (FallbackMethod) GetParam

func (fallbackMethod FallbackMethod) GetParam() (string, string)

type FallbackUrl

type FallbackUrl string

func (FallbackUrl) GetParam

func (fallbackUrl FallbackUrl) GetParam() (string, string)

type FriendlyName

type FriendlyName string

func (FriendlyName) GetParam

func (friendlyName FriendlyName) GetParam() (string, string)

type From

type From string

func (From) GetParam

func (from From) GetParam() (string, string)

type IfMachine

type IfMachine string

func (IfMachine) GetParam

func (ifMachine IfMachine) GetParam() (string, string)

type IncomingPhoneNumber

type IncomingPhoneNumber struct {
	Sid                  string      `json:"sid"`
	AccountSid           string      `json:"account_sid"`
	FriendlyName         string      `json:"friendly_name"`
	PhoneNumber          string      `json:"phone_number"`
	VoiceUrl             string      `json:"voice_url"`
	VoiceMethod          string      `json:"voice_method"`
	VoiceFallbackUrl     string      `json:"voice_fallback_url"`
	VoiceFallbackMethod  string      `json:"voice_fallback_method"`
	StatusCallback       string      `json:"status_callback"`
	StatusCallbackMethod string      `json:"status_callback_method"`
	VoiceCallerIdLookup  bool        `json:"voice_caller_id_lookup"`
	VoiceApplicationId   string      `json:"voice_application_id"`
	DateCreated          string      `json:"date_created"`
	DateUpdated          string      `json:"date_updated"`
	SmsUrl               string      `json:"sms_url"`
	SmsMethod            string      `json:"sms_method"`
	SmsFallbackUrl       string      `json:"sms_fallback_url"`
	SmsFallbackMethod    string      `json:"sms_fallback_method"`
	SmsApplicationId     string      `json:"sms_application_id"`
	Capabilities         Capabilites `json:"capabilities"`
	ApiVersion           string      `json:"api_version"`
	Uri                  string      `json:"uri"`
}

func BuyPhoneNumber

func BuyPhoneNumber(client Client, number Optional) (*IncomingPhoneNumber, error)

func GetIncomingPhoneNumber

func GetIncomingPhoneNumber(client Client, sid string) (*IncomingPhoneNumber, error)

type IncomingPhoneNumberList

type IncomingPhoneNumberList struct {
	Client               Client
	Start                int                   `json:"start"`
	Total                int                   `json:"total"`
	NumPages             int                   `json:"num_pages"`
	Page                 int                   `json:"page"`
	PageSize             int                   `json:"page_size"`
	End                  int                   `json:"end"`
	Uri                  string                `json:"uri"`
	FirstPageUri         string                `json:"first_page_uri"`
	LastPageUri          string                `json:"last_page_uri"`
	NextPageUri          string                `json:"next_page_uri"`
	PreviousPageUri      string                `json"previous_page_uri"`
	IncomingPhoneNumbers []IncomingPhoneNumber `json:"sms_messages"`
}

func GetIncomingPhoneNumberList

func GetIncomingPhoneNumberList(client Client, optionals ...Optional) (*IncomingPhoneNumberList, error)

type MediaUrl

type MediaUrl string

func (MediaUrl) GetParam

func (mediaUrl MediaUrl) GetParam() (string, string)

type Message

type Message struct {
	Sid         string `json:"sid"`
	DateCreated string `json:"date_created"`
	DateUpdated string `json:"date_updated"`
	DateSent    string `json:"date_sent"`
	AccountSid  string `json:"account_sid"`
	From        string `json:"from"`
	To          string `json:"to"`
	Body        string `json:"body"`
	NumSegments string `json:"num_segments"`
	Status      string `json:"status"`
	Direction   string `json:"direction"`
	Price       string `json:"price"`
	PriceUnit   string `json:"price_unit"`
	ApiVersion  string `json:"api_version"`
	Uri         string `json:"uri"`
}

func GetMessage

func GetMessage(client Client, sid string) (*Message, error)

func NewMessage

func NewMessage(client Client, from string, to string, content ...Optional) (*Message, error)

type MessageList

type MessageList struct {
	Client          Client
	Start           int       `json:"start"`
	Total           int       `json:"total"`
	NumPages        int       `json:"num_pages"`
	Page            int       `json:"page"`
	PageSize        int       `json:"page_size"`
	End             int       `json:"end"`
	Uri             string    `json:"uri"`
	FirstPageUri    string    `json:"first_page_uri"`
	LastPageUri     string    `json:"last_page_uri"`
	NextPageUri     string    `json:"next_page_uri"`
	PreviousPageUri string    `json"previous_page_uri"`
	Messages        []Message `json:"sms_messages"`
}

func GetMessageList

func GetMessageList(client Client, optionals ...Optional) (*MessageList, error)

func (*MessageList) FirstPage

func (currentMessageList *MessageList) FirstPage() (*MessageList, error)

func (*MessageList) GetMessages

func (m *MessageList) GetMessages() []Message

func (*MessageList) HasNextPage

func (currentMessageList *MessageList) HasNextPage() bool

func (*MessageList) HasPreviousPage

func (currentMessageList *MessageList) HasPreviousPage() bool

func (*MessageList) LastPage

func (currentMessageList *MessageList) LastPage() (*MessageList, error)

func (*MessageList) NextPage

func (currentMessageList *MessageList) NextPage() (*MessageList, error)

func (*MessageList) PreviousPage

func (currentMessageList *MessageList) PreviousPage() (*MessageList, error)

type Method

type Method string

func (Method) GetParam

func (method Method) GetParam() (string, string)

type MockClient

type MockClient struct {
	mock.Mock
}

func (*MockClient) AccountSid

func (client *MockClient) AccountSid() string

func (*MockClient) AuthToken

func (client *MockClient) AuthToken() string

func (*MockClient) RootUrl

func (client *MockClient) RootUrl() string

type Optional

type Optional interface {
	GetParam() (string, string)
}

type ParentCallSid

type ParentCallSid string

func (ParentCallSid) GetParam

func (parentCallSid ParentCallSid) GetParam() (string, string)

type PhoneNumber

type PhoneNumber string

func (PhoneNumber) GetParam

func (phoneNumber PhoneNumber) GetParam() (string, string)

type Record

type Record string

func (Record) GetParam

func (record Record) GetParam() (string, string)

type SendDigits

type SendDigits string

func (SendDigits) GetParam

func (sendDigits SendDigits) GetParam() (string, string)

type StartTime

type StartTime string

func (StartTime) GetParam

func (startTime StartTime) GetParam() (string, string)

type Status

type Status string

func (Status) GetParam

func (status Status) GetParam() (string, string)

type StatusCallback

type StatusCallback string

func (StatusCallback) GetParam

func (statusCallback StatusCallback) GetParam() (string, string)

type StatusCallbackMethod

type StatusCallbackMethod string

func (StatusCallbackMethod) GetParam

func (statusCallbackMethod StatusCallbackMethod) GetParam() (string, string)

type Timeout

type Timeout string

func (Timeout) GetParam

func (timeout Timeout) GetParam() (string, string)

type To

type To string

func (To) GetParam

func (to To) GetParam() (string, string)

type TwilioClient

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

func NewClient

func NewClient(accountSid, authToken string, c *http.Client) *TwilioClient

func (*TwilioClient) AccountSid

func (client *TwilioClient) AccountSid() string

func (*TwilioClient) AuthToken

func (client *TwilioClient) AuthToken() string

func (*TwilioClient) RootUrl

func (client *TwilioClient) RootUrl() string

type TwilioError

type TwilioError struct {
	Status   int    `json:"status"`
	Message  string `json:"message"`
	Code     int    `json:"code"`
	MoreInfo string `json:"more_info"`
}

func (TwilioError) Error

func (e TwilioError) Error() string

Jump to

Keyboard shortcuts

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