/
client.go
50 lines (42 loc) · 1.35 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package v2010
import (
"github.com/RJPearson94/twilio-sdk-go/client"
"github.com/RJPearson94/twilio-sdk-go/service/api/v2010/account"
"github.com/RJPearson94/twilio-sdk-go/service/api/v2010/accounts"
"github.com/RJPearson94/twilio-sdk-go/session"
"github.com/RJPearson94/twilio-sdk-go/session/credentials"
)
// Client to manage resources that are part of the Twilio API
type V2010 struct {
client *client.Client
Accounts *accounts.Client
Account func(string) *account.Client
}
// Used for testing purposes only
func (s V2010) GetClient() *client.Client {
return s.client
}
// New creates a new instance of the client using session data
func New(sess *session.Session) *V2010 {
config := client.GetDefaultConfig()
config.Beta = false
config.SubDomain = "api"
config.APIVersion = "2010-04-01"
return NewWithClient(client.New(sess, config))
}
// NewWithClient creates a new instance of the client with a HTTP client
func NewWithClient(client *client.Client) *V2010 {
return &V2010{
client: client,
Accounts: accounts.New(client),
Account: func(accountSid string) *account.Client {
return account.New(client, account.ClientProperties{
Sid: accountSid,
})
},
}
}
// NewWithCredentials creates a new instance of the client with credentials
func NewWithCredentials(creds *credentials.Credentials) *V2010 {
return New(session.New(creds))
}