Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messaging service support #88

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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 @@ -73,6 +73,10 @@ var InsightsBaseUrl = "https://insights.twilio.com"

const InsightsVersion = "v1"

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

type Client struct {
*restclient.Client
Monitor *Client
Expand All @@ -85,6 +89,7 @@ type Client struct {
Video *Client
TaskRouter *Client
Insights *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 @@ -144,6 +149,9 @@ type Client struct {

// NewInsightsClient initializes these services
VoiceInsights func(sid string) *VoiceInsightsService

// NewServiceResourceClient initializes these services
ServiceResources *ServiceResourceService
}

const defaultTimeout = 30*time.Second + 500*time.Millisecond
Expand Down Expand Up @@ -350,6 +358,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 @@ -378,6 +401,7 @@ func NewClient(accountSid string, authToken string, httpClient *http.Client) *Cl
c.Video = NewVideoClient(accountSid, authToken, httpClient)
c.TaskRouter = NewTaskRouterClient(accountSid, authToken, httpClient)
c.Insights = NewInsightsClient(accountSid, authToken, httpClient)
c.Resource = NewServiceResourceClient(accountSid, authToken, httpClient)

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

return c
}

Expand Down
11 changes: 10 additions & 1 deletion responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import (

// 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 = NewClient(os.Getenv("TWILIO_ACCOUNT_SID"), os.Getenv("TWILIO_AUTH_TOKEN"), nil)
var envClient *Client

func init() {
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)
}

type Server struct {
s *httptest.Server
Expand Down Expand Up @@ -66,6 +73,7 @@ func getServer(response []byte) (*Client, *Server) {
client.Video.Base = s.URL
client.TaskRouter.Base = s.URL
client.Insights.Base = s.URL
client.Resource.Base = s.URL
return client, s
}

Expand All @@ -81,6 +89,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