Skip to content

Commit 72fd38b

Browse files
committed
Fixing bugs to validate empty response and remove "/" to avoid redirect request
1 parent 462e554 commit 72fd38b

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

internal/provider/attribution.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c *ClientTest) CreateAttribution(attribution Attribution) (*Attribution, e
1515
return nil, err
1616
}
1717

18-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributions/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
18+
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributions?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
1919
log.Println("URL----------------")
2020
log.Println(req.URL)
2121
if err != nil {
@@ -47,7 +47,7 @@ func (c *ClientTest) UpdateAttribution(attributionID string, attribution Attribu
4747
if err != nil {
4848
return nil, err
4949
}
50-
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributions/%s/?customerContext=%s", c.HostURL, attributionID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
50+
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributions/%s?customerContext=%s", c.HostURL, attributionID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
5151
if err != nil {
5252
return nil, err
5353
}
@@ -69,7 +69,7 @@ func (c *ClientTest) UpdateAttribution(attributionID string, attribution Attribu
6969
}
7070

7171
func (c *ClientTest) DeleteAttribution(attributionID string) error {
72-
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/attributions/%s/?customerContext=%s", c.HostURL, attributionID, c.Auth.CustomerContext), nil)
72+
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/attributions/%s?customerContext=%s", c.HostURL, attributionID, c.Auth.CustomerContext), nil)
7373
if err != nil {
7474
return err
7575
}
@@ -84,7 +84,7 @@ func (c *ClientTest) DeleteAttribution(attributionID string) error {
8484

8585
// GetAttribution - Returns a specifc attribution
8686
func (c *ClientTest) GetAttribution(orderID string) (*Attribution, error) {
87-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributions/%s/?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
87+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributions/%s?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
8888
if err != nil {
8989
return nil, err
9090
}

internal/provider/attribution_group.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (c *ClientTest) CreateAttributionGroup(attributionGroup AttributionGroup) (
1818
}
1919
log.Println(strings.NewReader(string(rb)))
2020

21-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributiongroups/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
21+
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributiongroups?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
2222
log.Println("URL:")
2323
log.Println(req.URL)
2424
if err != nil {
@@ -48,7 +48,7 @@ func (c *ClientTest) UpdateAttributionGroup(attributionGroupID string, attributi
4848
if err != nil {
4949
return nil, err
5050
}
51-
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s/?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
51+
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
5252
if err != nil {
5353
return nil, err
5454
}
@@ -65,7 +65,7 @@ func (c *ClientTest) UpdateAttributionGroup(attributionGroupID string, attributi
6565
}
6666

6767
func (c *ClientTest) DeleteAttributionGroup(attributionGroupID string) error {
68-
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s/?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), nil)
68+
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), nil)
6969
if err != nil {
7070
return err
7171
}
@@ -80,7 +80,7 @@ func (c *ClientTest) DeleteAttributionGroup(attributionGroupID string) error {
8080

8181
// GetAttributionGroup - Returns a specifc attribution
8282
func (c *ClientTest) GetAttributionGroup(attributionGroupID string) (*AttributionGroup, error) {
83-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s/?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), nil)
83+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), nil)
8484
if err != nil {
8585
return nil, err
8686
}

internal/provider/budget.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c *ClientTest) CreateBudget(budget Budget) (*Budget, error) {
1515
return nil, err
1616
}
1717

18-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/budgets/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
18+
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/budgets?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
1919
log.Println("URL----------------")
2020
log.Println(req.URL)
2121
if err != nil {
@@ -47,7 +47,7 @@ func (c *ClientTest) UpdateBudget(budgetID string, budget Budget) (*Budget, erro
4747
if err != nil {
4848
return nil, err
4949
}
50-
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
50+
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/budgets/%s?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
5151
if err != nil {
5252
return nil, err
5353
}
@@ -72,7 +72,7 @@ func (c *ClientTest) UpdateBudget(budgetID string, budget Budget) (*Budget, erro
7272
}
7373

7474
func (c *ClientTest) DeleteBudget(budgetID string) error {
75-
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), nil)
75+
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/budgets/%s?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), nil)
7676
if err != nil {
7777
return err
7878
}
@@ -87,7 +87,7 @@ func (c *ClientTest) DeleteBudget(budgetID string) error {
8787

8888
// GetBudget - Returns a specifc budget
8989
func (c *ClientTest) GetBudget(orderID string) (*Budget, error) {
90-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
90+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/budgets/%s?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
9191
if err != nil {
9292
return nil, err
9393
}

internal/provider/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"log"
78
"net/http"
89
"time"
910

@@ -106,6 +107,11 @@ func (c *ClientTest) doRequest(req *http.Request) ([]byte, error) {
106107
retryable := func() error {
107108
var errRetry error
108109
res, errRetry = operation()
110+
if res == nil {
111+
log.Println("no response")
112+
log.Println(errRetry)
113+
return fmt.Errorf("no response")
114+
}
109115
if res.StatusCode == http.StatusTooManyRequests {
110116
return fmt.Errorf("rate limit exceeded")
111117
}

internal/provider/report.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (c *ClientTest) CreateReport(report Report) (*Report, error) {
1919
log.Print("Report body----------------")
2020
log.Println(string(rb))
2121

22-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/reports/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
22+
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/reports?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
2323
log.Println("URL----------------")
2424
log.Println(req.URL)
2525
if err != nil {
@@ -53,7 +53,7 @@ func (c *ClientTest) UpdateReport(reportID string, report Report) (*Report, erro
5353
}
5454
log.Print("Report body----------------")
5555
log.Println(string(rb))
56-
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/reports/%s/?customerContext=%s", c.HostURL, reportID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
56+
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/reports/%s?customerContext=%s", c.HostURL, reportID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
5757
if err != nil {
5858
return nil, err
5959
}
@@ -75,7 +75,7 @@ func (c *ClientTest) UpdateReport(reportID string, report Report) (*Report, erro
7575
}
7676

7777
func (c *ClientTest) DeleteReport(reportID string) error {
78-
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/reports/%s/?customerContext=%s", c.HostURL, reportID, c.Auth.CustomerContext), nil)
78+
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/analytics/v1/reports/%s?customerContext=%s", c.HostURL, reportID, c.Auth.CustomerContext), nil)
7979
if err != nil {
8080
return err
8181
}

0 commit comments

Comments
 (0)