Skip to content

Commit

Permalink
Fixing bugs to validate empty response and remove "/" to avoid redire…
Browse files Browse the repository at this point in the history
…ct request
  • Loading branch information
dianibar committed Feb 7, 2024
1 parent 462e554 commit 72fd38b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions internal/provider/attribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *ClientTest) CreateAttribution(attribution Attribution) (*Attribution, e
return nil, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributions/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributions?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
log.Println("URL----------------")
log.Println(req.URL)
if err != nil {
Expand Down Expand Up @@ -47,7 +47,7 @@ func (c *ClientTest) UpdateAttribution(attributionID string, attribution Attribu
if err != nil {
return nil, err
}
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributions/%s/?customerContext=%s", c.HostURL, attributionID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributions/%s?customerContext=%s", c.HostURL, attributionID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
if err != nil {
return nil, err
}
Expand All @@ -69,7 +69,7 @@ func (c *ClientTest) UpdateAttribution(attributionID string, attribution Attribu
}

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

// GetAttribution - Returns a specifc attribution
func (c *ClientTest) GetAttribution(orderID string) (*Attribution, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributions/%s/?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributions/%s?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/attribution_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (c *ClientTest) CreateAttributionGroup(attributionGroup AttributionGroup) (
}
log.Println(strings.NewReader(string(rb)))

req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributiongroups/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/attributiongroups?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
log.Println("URL:")
log.Println(req.URL)
if err != nil {
Expand Down Expand Up @@ -48,7 +48,7 @@ func (c *ClientTest) UpdateAttributionGroup(attributionGroupID string, attributi
if err != nil {
return nil, err
}
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s/?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
if err != nil {
return nil, err
}
Expand All @@ -65,7 +65,7 @@ func (c *ClientTest) UpdateAttributionGroup(attributionGroupID string, attributi
}

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

// GetAttributionGroup - Returns a specifc attribution
func (c *ClientTest) GetAttributionGroup(attributionGroupID string) (*AttributionGroup, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s/?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/attributiongroups/%s?customerContext=%s", c.HostURL, attributionGroupID, c.Auth.CustomerContext), nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *ClientTest) CreateBudget(budget Budget) (*Budget, error) {
return nil, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/budgets/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/budgets?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
log.Println("URL----------------")
log.Println(req.URL)
if err != nil {
Expand Down Expand Up @@ -47,7 +47,7 @@ func (c *ClientTest) UpdateBudget(budgetID string, budget Budget) (*Budget, erro
if err != nil {
return nil, err
}
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/budgets/%s?customerContext=%s", c.HostURL, budgetID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
if err != nil {
return nil, err
}
Expand All @@ -72,7 +72,7 @@ func (c *ClientTest) UpdateBudget(budgetID string, budget Budget) (*Budget, erro
}

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

// GetBudget - Returns a specifc budget
func (c *ClientTest) GetBudget(orderID string) (*Budget, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/budgets/%s/?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/analytics/v1/budgets/%s?customerContext=%s", c.HostURL, orderID, c.Auth.CustomerContext), nil)
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -106,6 +107,11 @@ func (c *ClientTest) doRequest(req *http.Request) ([]byte, error) {
retryable := func() error {
var errRetry error
res, errRetry = operation()
if res == nil {
log.Println("no response")
log.Println(errRetry)
return fmt.Errorf("no response")
}
if res.StatusCode == http.StatusTooManyRequests {
return fmt.Errorf("rate limit exceeded")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (c *ClientTest) CreateReport(report Report) (*Report, error) {
log.Print("Report body----------------")
log.Println(string(rb))

req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/reports/?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("POST", fmt.Sprintf("%s/analytics/v1/reports?customerContext=%s", c.HostURL, c.Auth.CustomerContext), strings.NewReader(string(rb)))
log.Println("URL----------------")
log.Println(req.URL)
if err != nil {
Expand Down Expand Up @@ -53,7 +53,7 @@ func (c *ClientTest) UpdateReport(reportID string, report Report) (*Report, erro
}
log.Print("Report body----------------")
log.Println(string(rb))
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/reports/%s/?customerContext=%s", c.HostURL, reportID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/analytics/v1/reports/%s?customerContext=%s", c.HostURL, reportID, c.Auth.CustomerContext), strings.NewReader(string(rb)))
if err != nil {
return nil, err
}
Expand All @@ -75,7 +75,7 @@ func (c *ClientTest) UpdateReport(reportID string, report Report) (*Report, erro
}

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

0 comments on commit 72fd38b

Please sign in to comment.