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 #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
22 changes: 21 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,8 @@ type Client struct {

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

ServiceResourceService *ServiceResourceService
}

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

// NewServiceResource returns a new Client to use Service Resource API
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the*

Can you link to documentation here?

func NewServiceResource(accountSid string, authToken string, httpClient *http.Client) *Client {
c := newNewClient(accountSid, authToken, ServiceResourceBaseUrl, httpClient)
c.APIVersion = ServiceResourceVersion
c.ServiceResourceService = &ServiceResourceService{
MessagingService: &MessagingService{c},
PhoneNumber: &PhoneNumberService{c},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally these are plural elsewhere in the API... PhoneNumbers, AlphaSenders, ShortCodes.

AlphaSender: &AlphaSenderService{c},
ShortCode: &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 +365,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 = NewServiceResource(accountSid, authToken, httpClient)

c.Accounts = &AccountService{client: c}
c.Applications = &ApplicationService{client: c}
Expand Down Expand Up @@ -392,7 +413,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