github.com/twilio/twilio-go@v1.20.1/twilio.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * NOTE: This class is auto generated by OpenAPI Generator. 8 * https://openapi-generator.tech 9 * Do not edit the class manually. 10 */ 11 // Package twilio provides bindings for Twilio's REST APIs. 12 package twilio 13 14 import ( 15 "os" 16 "time" 17 18 "github.com/twilio/twilio-go/client" 19 AccountsV1 "github.com/twilio/twilio-go/rest/accounts/v1" 20 Api "github.com/twilio/twilio-go/rest/api/v2010" 21 BulkexportsV1 "github.com/twilio/twilio-go/rest/bulkexports/v1" 22 ChatV1 "github.com/twilio/twilio-go/rest/chat/v1" 23 ChatV2 "github.com/twilio/twilio-go/rest/chat/v2" 24 ChatV3 "github.com/twilio/twilio-go/rest/chat/v3" 25 ContentV1 "github.com/twilio/twilio-go/rest/content/v1" 26 ConversationsV1 "github.com/twilio/twilio-go/rest/conversations/v1" 27 EventsV1 "github.com/twilio/twilio-go/rest/events/v1" 28 FlexV1 "github.com/twilio/twilio-go/rest/flex/v1" 29 FlexV2 "github.com/twilio/twilio-go/rest/flex/v2" 30 FrontlineV1 "github.com/twilio/twilio-go/rest/frontline/v1" 31 InsightsV1 "github.com/twilio/twilio-go/rest/insights/v1" 32 IntelligenceV2 "github.com/twilio/twilio-go/rest/intelligence/v2" 33 IpMessagingV1 "github.com/twilio/twilio-go/rest/ip_messaging/v1" 34 IpMessagingV2 "github.com/twilio/twilio-go/rest/ip_messaging/v2" 35 LookupsV1 "github.com/twilio/twilio-go/rest/lookups/v1" 36 LookupsV2 "github.com/twilio/twilio-go/rest/lookups/v2" 37 MessagingV1 "github.com/twilio/twilio-go/rest/messaging/v1" 38 MicrovisorV1 "github.com/twilio/twilio-go/rest/microvisor/v1" 39 MonitorV1 "github.com/twilio/twilio-go/rest/monitor/v1" 40 NotifyV1 "github.com/twilio/twilio-go/rest/notify/v1" 41 NumbersV1 "github.com/twilio/twilio-go/rest/numbers/v1" 42 NumbersV2 "github.com/twilio/twilio-go/rest/numbers/v2" 43 OauthV1 "github.com/twilio/twilio-go/rest/oauth/v1" 44 PreviewMessagingV1 "github.com/twilio/twilio-go/rest/preview_messaging/v1" 45 PricingV1 "github.com/twilio/twilio-go/rest/pricing/v1" 46 PricingV2 "github.com/twilio/twilio-go/rest/pricing/v2" 47 ProxyV1 "github.com/twilio/twilio-go/rest/proxy/v1" 48 RoutesV2 "github.com/twilio/twilio-go/rest/routes/v2" 49 ServerlessV1 "github.com/twilio/twilio-go/rest/serverless/v1" 50 StudioV1 "github.com/twilio/twilio-go/rest/studio/v1" 51 StudioV2 "github.com/twilio/twilio-go/rest/studio/v2" 52 SupersimV1 "github.com/twilio/twilio-go/rest/supersim/v1" 53 SyncV1 "github.com/twilio/twilio-go/rest/sync/v1" 54 TaskrouterV1 "github.com/twilio/twilio-go/rest/taskrouter/v1" 55 TrunkingV1 "github.com/twilio/twilio-go/rest/trunking/v1" 56 TrusthubV1 "github.com/twilio/twilio-go/rest/trusthub/v1" 57 VerifyV2 "github.com/twilio/twilio-go/rest/verify/v2" 58 VideoV1 "github.com/twilio/twilio-go/rest/video/v1" 59 VoiceV1 "github.com/twilio/twilio-go/rest/voice/v1" 60 WirelessV1 "github.com/twilio/twilio-go/rest/wireless/v1" 61 ) 62 63 // RestClient provides access to Twilio services. 64 type RestClient struct { 65 *client.RequestHandler 66 AccountsV1 *AccountsV1.ApiService 67 Api *Api.ApiService 68 BulkexportsV1 *BulkexportsV1.ApiService 69 ChatV1 *ChatV1.ApiService 70 ChatV2 *ChatV2.ApiService 71 ChatV3 *ChatV3.ApiService 72 ContentV1 *ContentV1.ApiService 73 ConversationsV1 *ConversationsV1.ApiService 74 EventsV1 *EventsV1.ApiService 75 FlexV1 *FlexV1.ApiService 76 FlexV2 *FlexV2.ApiService 77 FrontlineV1 *FrontlineV1.ApiService 78 InsightsV1 *InsightsV1.ApiService 79 IntelligenceV2 *IntelligenceV2.ApiService 80 IpMessagingV1 *IpMessagingV1.ApiService 81 IpMessagingV2 *IpMessagingV2.ApiService 82 LookupsV1 *LookupsV1.ApiService 83 LookupsV2 *LookupsV2.ApiService 84 PreviewMessagingV1 *PreviewMessagingV1.ApiService 85 MessagingV1 *MessagingV1.ApiService 86 MicrovisorV1 *MicrovisorV1.ApiService 87 MonitorV1 *MonitorV1.ApiService 88 NotifyV1 *NotifyV1.ApiService 89 NumbersV1 *NumbersV1.ApiService 90 NumbersV2 *NumbersV2.ApiService 91 OauthV1 *OauthV1.ApiService 92 PricingV1 *PricingV1.ApiService 93 PricingV2 *PricingV2.ApiService 94 ProxyV1 *ProxyV1.ApiService 95 RoutesV2 *RoutesV2.ApiService 96 ServerlessV1 *ServerlessV1.ApiService 97 StudioV1 *StudioV1.ApiService 98 StudioV2 *StudioV2.ApiService 99 SupersimV1 *SupersimV1.ApiService 100 SyncV1 *SyncV1.ApiService 101 TaskrouterV1 *TaskrouterV1.ApiService 102 TrunkingV1 *TrunkingV1.ApiService 103 TrusthubV1 *TrusthubV1.ApiService 104 VerifyV2 *VerifyV2.ApiService 105 VideoV1 *VideoV1.ApiService 106 VoiceV1 *VoiceV1.ApiService 107 WirelessV1 *WirelessV1.ApiService 108 } 109 110 // Meta holds relevant pagination resources. 111 type Meta struct { 112 FirstPageURL *string `json:"first_page_url"` 113 Key *string `json:"key"` 114 LastPageURL *string `json:"last_page_url,omitempty"` 115 NextPageURL *string `json:"next_page_url"` 116 Page *int `json:"page"` 117 PageSize *int `json:"page_size"` 118 PreviousPageURL *string `json:"previous_page_url"` 119 URL *string `json:"url"` 120 } 121 122 type ClientParams struct { 123 Username string 124 Password string 125 AccountSid string 126 Client client.BaseClient 127 } 128 129 // NewRestClientWithParams provides an initialized Twilio RestClient with params. 130 func NewRestClientWithParams(params ClientParams) *RestClient { 131 requestHandler := client.NewRequestHandler(params.Client) 132 133 if params.Client == nil { 134 username := params.Username 135 if username == "" { 136 username = os.Getenv("TWILIO_ACCOUNT_SID") 137 } 138 139 password := params.Password 140 if password == "" { 141 password = os.Getenv("TWILIO_AUTH_TOKEN") 142 } 143 144 defaultClient := &client.Client{ 145 Credentials: client.NewCredentials(username, password), 146 } 147 148 if params.AccountSid != "" { 149 defaultClient.SetAccountSid(params.AccountSid) 150 } else { 151 defaultClient.SetAccountSid(username) 152 } 153 requestHandler = client.NewRequestHandler(defaultClient) 154 } 155 156 c := &RestClient{ 157 RequestHandler: requestHandler, 158 } 159 160 c.AccountsV1 = AccountsV1.NewApiService(c.RequestHandler) 161 c.Api = Api.NewApiService(c.RequestHandler) 162 c.BulkexportsV1 = BulkexportsV1.NewApiService(c.RequestHandler) 163 c.ChatV1 = ChatV1.NewApiService(c.RequestHandler) 164 c.ChatV2 = ChatV2.NewApiService(c.RequestHandler) 165 c.ChatV3 = ChatV3.NewApiService(c.RequestHandler) 166 c.ContentV1 = ContentV1.NewApiService(c.RequestHandler) 167 c.ConversationsV1 = ConversationsV1.NewApiService(c.RequestHandler) 168 c.EventsV1 = EventsV1.NewApiService(c.RequestHandler) 169 c.FlexV1 = FlexV1.NewApiService(c.RequestHandler) 170 c.FlexV2 = FlexV2.NewApiService(c.RequestHandler) 171 c.FrontlineV1 = FrontlineV1.NewApiService(c.RequestHandler) 172 c.InsightsV1 = InsightsV1.NewApiService(c.RequestHandler) 173 c.IntelligenceV2 = IntelligenceV2.NewApiService(c.RequestHandler) 174 c.IpMessagingV1 = IpMessagingV1.NewApiService(c.RequestHandler) 175 c.IpMessagingV2 = IpMessagingV2.NewApiService(c.RequestHandler) 176 c.LookupsV1 = LookupsV1.NewApiService(c.RequestHandler) 177 c.LookupsV2 = LookupsV2.NewApiService(c.RequestHandler) 178 c.PreviewMessagingV1 = PreviewMessagingV1.NewApiService(c.RequestHandler) 179 c.MessagingV1 = MessagingV1.NewApiService(c.RequestHandler) 180 c.MicrovisorV1 = MicrovisorV1.NewApiService(c.RequestHandler) 181 c.MonitorV1 = MonitorV1.NewApiService(c.RequestHandler) 182 c.NotifyV1 = NotifyV1.NewApiService(c.RequestHandler) 183 c.NumbersV1 = NumbersV1.NewApiService(c.RequestHandler) 184 c.NumbersV2 = NumbersV2.NewApiService(c.RequestHandler) 185 c.OauthV1 = OauthV1.NewApiService(c.RequestHandler) 186 c.PricingV1 = PricingV1.NewApiService(c.RequestHandler) 187 c.PricingV2 = PricingV2.NewApiService(c.RequestHandler) 188 c.ProxyV1 = ProxyV1.NewApiService(c.RequestHandler) 189 c.RoutesV2 = RoutesV2.NewApiService(c.RequestHandler) 190 c.ServerlessV1 = ServerlessV1.NewApiService(c.RequestHandler) 191 c.StudioV1 = StudioV1.NewApiService(c.RequestHandler) 192 c.StudioV2 = StudioV2.NewApiService(c.RequestHandler) 193 c.SupersimV1 = SupersimV1.NewApiService(c.RequestHandler) 194 c.SyncV1 = SyncV1.NewApiService(c.RequestHandler) 195 c.TaskrouterV1 = TaskrouterV1.NewApiService(c.RequestHandler) 196 c.TrunkingV1 = TrunkingV1.NewApiService(c.RequestHandler) 197 c.TrusthubV1 = TrusthubV1.NewApiService(c.RequestHandler) 198 c.VerifyV2 = VerifyV2.NewApiService(c.RequestHandler) 199 c.VideoV1 = VideoV1.NewApiService(c.RequestHandler) 200 c.VoiceV1 = VoiceV1.NewApiService(c.RequestHandler) 201 c.WirelessV1 = WirelessV1.NewApiService(c.RequestHandler) 202 203 return c 204 } 205 206 // NewRestClient provides an initialized Twilio RestClient. 207 func NewRestClient() *RestClient { 208 return NewRestClientWithParams(ClientParams{}) 209 } 210 211 // SetTimeout sets the Timeout for Twilio HTTP requests. 212 func (c *RestClient) SetTimeout(timeout time.Duration) { 213 c.RequestHandler.Client.SetTimeout(timeout) 214 } 215 216 // SetEdge sets the Edge for the Twilio request. 217 func (c *RestClient) SetEdge(edge string) { 218 c.RequestHandler.Edge = edge 219 } 220 221 // SetRegion sets the Region for the Twilio request. Defaults to "us1" if an edge is provided. 222 func (c *RestClient) SetRegion(region string) { 223 c.RequestHandler.Region = region 224 }