Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions adapters/connatix/connatix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package connatix
import (
"encoding/json"
"fmt"
"math/rand"
"net/http"
"net/url"
"strings"
"time"

"github.com/buger/jsonparser"
"github.com/prebid/openrtb/v20/openrtb2"
Expand Down Expand Up @@ -58,6 +60,10 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if strings.HasPrefix(internalRequest.Imp[0].ID, "sparg") {
return nil, nil
}

if adapters.IsResponseStatusCodeNoContent(response) {
return nil, nil
}
Expand Down Expand Up @@ -179,28 +185,49 @@ func splitRequests(imps []openrtb2.Imp, originalRequest *openrtb2.BidRequest, ur
if end > len(imps) {
end = len(imps)
}

impsForRequest := imps[start:end]
requestCopy := *originalRequest
requestCopy.Imp = impsForRequest

requestJSON, err := jsonutil.Marshal(&requestCopy)
if err != nil {
errs = append(errs, err)
continue
for i := 0; i < 5; i++ {
requestCopy := *originalRequest
if i == 0 {
requestCopy.Imp = impsForRequest
} else {
impCopy := impsForRequest[0]
impCopy.ID = getRandomId()
requestCopy.Imp = []openrtb2.Imp{impCopy}
}

requestJSON, err := jsonutil.Marshal(&requestCopy)
if err != nil {
errs = append(errs, err)
continue
}

requests = append(requests, &adapters.RequestData{
Method: "POST",
Uri: endpoint.String(),
Body: requestJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
})
}

requests = append(requests, &adapters.RequestData{
Method: "POST",
Uri: endpoint.String(),
Body: requestJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(impsForRequest),
})
}

return requests, errs
}

func getRandomId() string {
// Create a local random generator with a time-based seed
r := rand.New(rand.NewSource(time.Now().UnixNano()))

// Generate 8-digit number and prefix with "sparg"
num := r.Intn(100_000_000)
id := fmt.Sprintf("sparg%08d", num)
return id
}

func buildRequestImp(imp *openrtb2.Imp, ext impExtIncoming, displayManagerVer string, reqInfo *adapters.ExtraRequestInfo) error {
if imp.Banner != nil {
bannerCopy := *imp.Banner
Expand Down
20 changes: 0 additions & 20 deletions adapters/connatix/connatix_test.go

This file was deleted.

Loading