Skip to content

Commit

Permalink
Fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanganderson committed Mar 27, 2024
1 parent eb2a460 commit 98a880d
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 117 deletions.
14 changes: 6 additions & 8 deletions api_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,16 @@ An OAuth 2.0 access token is required to access the API features. To create a to
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiAuthTokenRequest
*/
func (a *AuthenticationAPIService) AuthToken(ctx context.Context) ApiAuthTokenRequest {
func (a *AuthenticationAPIService) AuthToken(ctx context.Context, clientId string, clientSecret string) ApiAuthTokenRequest {
return ApiAuthTokenRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
clientId: &clientId,
clientSecret: &clientSecret,
}
}

func (r ApiAuthTokenRequest) GetAuthToken(clientId string, clientSecret string) (*OAuth, *http.Response, error) {
r.clientId = new(string)
*r.clientId = clientId
r.clientSecret = new(string)
*r.clientSecret = clientSecret
func (r ApiAuthTokenRequest) AuthToken() (*OAuth, *http.Response, error) {
return r.Execute()
}

Expand Down
5 changes: 2 additions & 3 deletions api_authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ func Test_TelstraMessaging_AuthenticationAPIService(t *testing.T) {
clientId := "YOUR CLIENT ID"
clientSecret := "YOUR CLIENT SECRET"

authApi := apiClient.AuthenticationAPI.AuthToken(context.Background())

oauthResult, resp, err := authApi.GetAuthToken(clientId, clientSecret)
authApi := apiClient.AuthenticationAPI.AuthToken(context.Background(), clientId, clientSecret)
oauthResult, resp, err := authApi.AuthToken()

if err != nil {
fmt.Println("Error:", err)
Expand Down
14 changes: 8 additions & 6 deletions api_free_trial_numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ Note that you can only message mobile numbers that have been added to your Free
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiCreateTrialNumbersRequest
*/
func (a *FreeTrialNumbersAPIService) CreateTrialNumbers(ctx context.Context) ApiCreateTrialNumbersRequest {
func (a *FreeTrialNumbersAPIService) CreateTrialNumbers(ctx context.Context, authorization string) ApiCreateTrialNumbersRequest {
return ApiCreateTrialNumbersRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -382,10 +383,11 @@ If you're using a paid plan, there's no limit to the number of recipients that y
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiGetTrialNumbersRequest
*/
func (a *FreeTrialNumbersAPIService) GetTrialNumbers(ctx context.Context) ApiGetTrialNumbersRequest {
func (a *FreeTrialNumbersAPIService) GetTrialNumbers(ctx context.Context, authorization string) ApiGetTrialNumbersRequest {
return ApiGetTrialNumbersRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down
8 changes: 2 additions & 6 deletions api_free_trial_numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func Test_TelstraMessaging_FreeTrialNumbersAPIService(t *testing.T) {
createTrialNumbersRequestFreeTrialNumbers := ArrayOfStringAsCreateTrialNumbersRequestFreeTrialNumbers(&trialNumbers)
createTrialNumbersRequest := NewCreateTrialNumbersRequest(createTrialNumbersRequestFreeTrialNumbers)

trialNumbersApi := apiClient.FreeTrialNumbersAPI.CreateTrialNumbers(context.Background())
trialNumbersApi.authorization = &authorization

trialNumbersApi := apiClient.FreeTrialNumbersAPI.CreateTrialNumbers(context.Background(), authorization)
resp, httpRes, err := trialNumbersApi.CreateTrialNumbers(*createTrialNumbersRequest)

if err != nil {
Expand All @@ -54,9 +52,7 @@ func Test_TelstraMessaging_FreeTrialNumbersAPIService(t *testing.T) {
t.Run("Test FreeTrialNumbersAPIService GetTrialNumbers", func(t *testing.T) {

//t.Skip("skip test")
trialNumbersApi := apiClient.FreeTrialNumbersAPI.GetTrialNumbers(context.Background())
trialNumbersApi.authorization = &authorization

trialNumbersApi := apiClient.FreeTrialNumbersAPI.GetTrialNumbers(context.Background(), authorization)
resp, httpRes, err := trialNumbersApi.GetTrialNumbers()

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions api_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ Use this endpoint to check the operational status of the messaging service. A 20
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiHealthCheckRequest
*/
func (a *HealthCheckAPIService) HealthCheck(ctx context.Context) ApiHealthCheckRequest {
func (a *HealthCheckAPIService) HealthCheck(ctx context.Context, authorization string) ApiHealthCheckRequest {
return ApiHealthCheckRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down
4 changes: 1 addition & 3 deletions api_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func Test_TelstraMessaging_HealthCheckAPIService(t *testing.T) {

//t.Skip("skip test") // remove to run test

healthCheckApi := apiClient.HealthCheckAPI.HealthCheck(context.Background())
healthCheckApi.authorization = &authorization

healthCheckApi := apiClient.HealthCheckAPI.HealthCheck(context.Background(), authorization)
resp, httpRes, err := healthCheckApi.HealthCheck()

if err != nil {
Expand Down
50 changes: 28 additions & 22 deletions api_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ Use this endpoint to delete a message that's been scheduled for sending, but has
@param messageId When you sent the original message, this is the UUID that was returned in the call response. Use this ID to fetch, update or delete a message with the appropriate endpoints.
@return ApiDeleteMessageByIdRequest
*/
func (a *MessagesAPIService) DeleteMessageById(ctx context.Context, messageId string) ApiDeleteMessageByIdRequest {
func (a *MessagesAPIService) DeleteMessageById(ctx context.Context, messageId string, authorization string) ApiDeleteMessageByIdRequest {
return ApiDeleteMessageByIdRequest{
ApiService: a,
ctx: ctx,
messageId: messageId,
ApiService: a,
ctx: ctx,
messageId: messageId,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -356,11 +357,12 @@ Use the **messageId** to fetch a message that's been sent from/to your account w
@param messageId When you sent the original message, this is the UUID that was returned in the response. Use this ID to fetch, update or delete a message with the appropriate endpoints. Incoming messages are also assigned a messageId. Use this ID with GET/ messages/{messageId} to fetch the message later.
@return ApiGetMessageByIdRequest
*/
func (a *MessagesAPIService) GetMessageById(ctx context.Context, messageId string) ApiGetMessageByIdRequest {
func (a *MessagesAPIService) GetMessageById(ctx context.Context, messageId string, authorization string) ApiGetMessageByIdRequest {
return ApiGetMessageByIdRequest{
ApiService: a,
ctx: ctx,
messageId: messageId,
ApiService: a,
ctx: ctx,
messageId: messageId,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -724,10 +726,11 @@ Fetch messages that have been sent from/to your account in the last 30 days.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiGetMessagesRequest
*/
func (a *MessagesAPIService) GetMessages(ctx context.Context) ApiGetMessagesRequest {
func (a *MessagesAPIService) GetMessages(ctx context.Context, authorization string) ApiGetMessagesRequest {
return ApiGetMessagesRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -1024,10 +1027,11 @@ Free Trial users can message to up to 10 unique recipient numbers for free. The
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiSendMessagesRequest
*/
func (a *MessagesAPIService) SendMessages(ctx context.Context) ApiSendMessagesRequest {
func (a *MessagesAPIService) SendMessages(ctx context.Context, authorization string) ApiSendMessagesRequest {
return ApiSendMessagesRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -1319,11 +1323,12 @@ Need to update a message that's scheduled for sending? You can change any of the
@param messageId When you sent the original message, this is the UUID that was returned in the call response. Use this ID to fetch, update or delete a message with the appropriate endpoints.
@return ApiUpdateMessageByIdRequest
*/
func (a *MessagesAPIService) UpdateMessageById(ctx context.Context, messageId string) ApiUpdateMessageByIdRequest {
func (a *MessagesAPIService) UpdateMessageById(ctx context.Context, messageId string, authorization string) ApiUpdateMessageByIdRequest {
return ApiUpdateMessageByIdRequest{
ApiService: a,
ctx: ctx,
messageId: messageId,
ApiService: a,
ctx: ctx,
messageId: messageId,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -1622,11 +1627,12 @@ Use the **messageId** to update the tag(s) assigned to a message. You can use th
@param messageId When you sent the original message, this is the UUID that was returned in the call response. Use this ID to fetch, update or delete a message with the appropriate endpoints.
@return ApiUpdateMessageTagsRequest
*/
func (a *MessagesAPIService) UpdateMessageTags(ctx context.Context, messageId string) ApiUpdateMessageTagsRequest {
func (a *MessagesAPIService) UpdateMessageTags(ctx context.Context, messageId string, authorization string) ApiUpdateMessageTagsRequest {
return ApiUpdateMessageTagsRequest{
ApiService: a,
ctx: ctx,
messageId: messageId,
ApiService: a,
ctx: ctx,
messageId: messageId,
authorization: &authorization,
}
}

Expand Down
35 changes: 18 additions & 17 deletions api_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {

t.Run("Test MessagesAPIService DeleteMessageById", func(t *testing.T) {
//t.Skip("skip test") // remove to run test
messagesApi := apiClient.MessagesAPI.DeleteMessageById(context.Background(), messageId)
messagesApi.authorization = &authorization

messagesApi := apiClient.MessagesAPI.DeleteMessageById(context.Background(), messageId, authorization)
httpRes, err := messagesApi.DeleteMessageById()

if err != nil {
Expand All @@ -52,9 +50,7 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {

//t.Skip("skip test") // remove to run test

messagesApi := apiClient.MessagesAPI.GetMessageById(context.Background(), messageId)
messagesApi.authorization = &authorization

messagesApi := apiClient.MessagesAPI.GetMessageById(context.Background(), messageId, authorization)
resp, httpRes, err := messagesApi.GetMessageById()

if err != nil {
Expand All @@ -73,8 +69,7 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {

t.Run("Test MessagesAPIService GetMessages", func(t *testing.T) {

messagesApi := apiClient.MessagesAPI.GetMessages(context.Background())
messagesApi.authorization = &authorization
messagesApi := apiClient.MessagesAPI.GetMessages(context.Background(), authorization)
reverse := true
messagesApi.reverse = &reverse
startTime := time.Now().AddDate(0, 0, -5).UTC()
Expand Down Expand Up @@ -116,6 +111,18 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {
sendMessagesRequest.SetRetryTimeout(10)
sendMessagesRequest.SetStatusCallbackUrl("http://www.example.com")

multimedia1 := Multimedia{
Type: "image/jpeg",
FileName: "image/jpeg",
Payload: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
}
multimedia2 := Multimedia{
Type: "image/jpeg",
FileName: "image/jpeg",
Payload: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
}
sendMessagesRequest.SetMultimedia([]Multimedia{multimedia1, multimedia2})

tags := []string{
"ip",
"deserunt exercitation",
Expand All @@ -133,9 +140,7 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {

sendMessagesRequest.SetTags(tags)

messagesApi := apiClient.MessagesAPI.SendMessages(context.Background())
messagesApi.authorization = &authorization

messagesApi := apiClient.MessagesAPI.SendMessages(context.Background(), authorization)
resp, httpRes, err := messagesApi.SendMessages(*sendMessagesRequest)

if err != nil {
Expand Down Expand Up @@ -178,9 +183,7 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {
}
updateMessageByIdRequest.SetTags(tags)

messagesApi := apiClient.MessagesAPI.UpdateMessageById(context.Background(), messageId)
messagesApi.authorization = &authorization

messagesApi := apiClient.MessagesAPI.UpdateMessageById(context.Background(), messageId, authorization)
resp, httpRes, err := messagesApi.UpdateMessageById(*updateMessageByIdRequest)

if err != nil {
Expand All @@ -202,9 +205,7 @@ func Test_TelstraMessaging_MessagesAPIService(t *testing.T) {
tags := []string{"marketing", "SMS"}
updateMessageTagsRequest := NewUpdateMessageTagsRequest(tags)

messagesApi := apiClient.MessagesAPI.UpdateMessageTags(context.Background(), messageId)
messagesApi.authorization = &authorization

messagesApi := apiClient.MessagesAPI.UpdateMessageTags(context.Background(), messageId, authorization)
httpRes, err := messagesApi.UpdateMessageTags(*updateMessageTagsRequest)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func SetRequestParams() *RequestParams {
}

func GetAuthorization(apiClient *APIClient, clientId string, clientSecret string) (string, error) {
authApi := apiClient.AuthenticationAPI.AuthToken(context.Background())
oauthResult, _, err := authApi.GetAuthToken(clientId, clientSecret)
authApi := apiClient.AuthenticationAPI.AuthToken(context.Background(), clientId, clientSecret)
oauthResult, _, err := authApi.AuthToken()
if err != nil {
return "", err
}
Expand Down
23 changes: 13 additions & 10 deletions api_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ Fetch a download link for a report generated with POST /reports/{reportId} using
@param reportId Use the reportId returned in the POST /reports/{reportType} response.
@return ApiGetReportRequest
*/
func (a *ReportsAPIService) GetReport(ctx context.Context, reportId string) ApiGetReportRequest {
func (a *ReportsAPIService) GetReport(ctx context.Context, reportId string, authorization string) ApiGetReportRequest {
return ApiGetReportRequest{
ApiService: a,
ctx: ctx,
reportId: reportId,
ApiService: a,
ctx: ctx,
reportId: reportId,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -363,10 +364,11 @@ Fetch details of all reports recently generated for your account. Use it to chec
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiGetReportsRequest
*/
func (a *ReportsAPIService) GetReports(ctx context.Context) ApiGetReportsRequest {
func (a *ReportsAPIService) GetReports(ctx context.Context, authorization string) ApiGetReportsRequest {
return ApiGetReportsRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down Expand Up @@ -631,10 +633,11 @@ Once your report is generated, it will be available for download for one week. T
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return ApiMessagesReportRequest
*/
func (a *ReportsAPIService) MessagesReport(ctx context.Context) ApiMessagesReportRequest {
func (a *ReportsAPIService) MessagesReport(ctx context.Context, authorization string) ApiMessagesReportRequest {
return ApiMessagesReportRequest{
ApiService: a,
ctx: ctx,
ApiService: a,
ctx: ctx,
authorization: &authorization,
}
}

Expand Down
12 changes: 3 additions & 9 deletions api_reports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func Test_TelstraMessaging_ReportsAPIService(t *testing.T) {
//t.Skip("skip test") // remove to run test
reportId := "c22d2050-eb37-11ee-ad5e-3d9263246ccb"

reportsApi := apiClient.ReportsAPI.GetReport(context.Background(), reportId)
reportsApi.authorization = &authorization

reportsApi := apiClient.ReportsAPI.GetReport(context.Background(), reportId, authorization)
resp, httpRes, err := reportsApi.GetReport()

if err != nil {
Expand All @@ -55,9 +53,7 @@ func Test_TelstraMessaging_ReportsAPIService(t *testing.T) {
t.Run("Test ReportsAPIService GetReports", func(t *testing.T) {

//t.Skip("skip test") // remove to run test
reportsApi := apiClient.ReportsAPI.GetReports(context.Background())
reportsApi.authorization = &authorization

reportsApi := apiClient.ReportsAPI.GetReports(context.Background(), authorization)
resp, httpRes, err := reportsApi.GetReports()

if err != nil {
Expand Down Expand Up @@ -85,9 +81,7 @@ func Test_TelstraMessaging_ReportsAPIService(t *testing.T) {
oneDayAgoFormatted := oneDayAgo.Format("2006-01-02")
messageReportRequest := NewMessagesReportRequest(threeDaysAgoFormatted, oneDayAgoFormatted)

reportsApi := apiClient.ReportsAPI.MessagesReport(context.Background())
reportsApi.authorization = &authorization

reportsApi := apiClient.ReportsAPI.MessagesReport(context.Background(), authorization)
resp, httpRes, err := reportsApi.MessagesReport(*messageReportRequest)

if err != nil {
Expand Down
Loading

0 comments on commit 98a880d

Please sign in to comment.