Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var TaskRouterBaseUrl = "https://taskrouter.twilio.com"

const TaskRouterVersion = "v1"

// Service Resource
const ServiceResourceBaseUrl = "https://messaging.twilio.com"
const ServiceResourceVersion = "v1"

type Client struct {
*rest.Client
Monitor *Client
Expand All @@ -78,6 +82,7 @@ type Client struct {
Verify *Client
Video *Client
TaskRouter *Client
Resource *Client

// FullPath takes a path part (e.g. "Messages") and
// returns the full API path, including the version (e.g.
Expand Down Expand Up @@ -134,6 +139,9 @@ type Client struct {

// NewTaskRouterClient initializes these services
Workspace func(sid string) *WorkspaceService

// NewServiceResourceClient initializes these services
ServiceResources *ServiceResourceService
}

const defaultTimeout = 30*time.Second + 500*time.Millisecond
Expand Down Expand Up @@ -318,6 +326,21 @@ func NewVideoClient(accountSid string, authToken string, httpClient *http.Client
return c
}

// NewServiceResourceClient returns a new Client to use the Service Resource API
//
//https://www.twilio.com/docs/sms/services/api#messaging-services-resource
func NewServiceResourceClient(accountSid string, authToken string, httpClient *http.Client) *Client {
c := newNewClient(accountSid, authToken, ServiceResourceBaseUrl, httpClient)
c.APIVersion = ServiceResourceVersion
c.ServiceResources = &ServiceResourceService{
MessagingService: &MessagingService{c},
PhoneNumbers: &PhoneNumberService{c},
AlphaSenders: &AlphaSenderService{c},
ShortCodes: &ShortCodeService{c},
}
return c
}

// NewClient creates a Client for interacting with the Twilio API. This is the
// main entrypoint for API interactions; view the methods on the subresources
// for more information.
Expand Down Expand Up @@ -345,6 +368,7 @@ func NewClient(accountSid string, authToken string, httpClient *http.Client) *Cl
c.Verify = NewVerifyClient(accountSid, authToken, httpClient)
c.Video = NewVideoClient(accountSid, authToken, httpClient)
c.TaskRouter = NewTaskRouterClient(accountSid, authToken, httpClient)
c.Resource = NewServiceResourceClient(accountSid, authToken, httpClient)

c.Accounts = &AccountService{client: c}
c.Applications = &ApplicationService{client: c}
Expand Down Expand Up @@ -392,7 +416,6 @@ func NewClient(accountSid string, authToken string, httpClient *http.Client) *Cl
client: c,
},
}

return c
}

Expand Down
7 changes: 3 additions & 4 deletions responses_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package twilio

import (
"flag"
"net/http"
"net/http/httptest"
"net/url"
"os"
"sync"
"testing"
)

// the envClient is configured to use an Account Sid and Auth Token set in the
// environment. all non-short tests should use the envClient
var envClient *Client

func init() {
flag.Parse()
if !testing.Short() && os.Getenv("TWILIO_ACCOUNT_SID") == "" {
if os.Getenv("TWILIO_ACCOUNT_SID") == "" {
os.Stderr.WriteString("warning: no TWILIO_ACCOUNT_SID configured, HTTP tests will probably fail...\n\n")
}
envClient = NewClient(os.Getenv("TWILIO_ACCOUNT_SID"), os.Getenv("TWILIO_AUTH_TOKEN"), nil)
Expand Down Expand Up @@ -75,6 +72,7 @@ func getServer(response []byte) (*Client, *Server) {
client.Verify.Base = s.URL
client.Video.Base = s.URL
client.TaskRouter.Base = s.URL
client.Resource.Base = s.URL
return client, s
}

Expand All @@ -90,6 +88,7 @@ func getServerCode(response []byte, code int) (*Client, *Server) {
client.Lookup.Base = s.URL
client.Video.Base = s.URL
client.TaskRouter.Base = s.URL
client.Resource.Base = s.URL
return client, s
}

Expand Down
Loading