Skip to content

Commit

Permalink
Made changes regarding go test
Browse files Browse the repository at this point in the history
  • Loading branch information
pixfuture-media committed Jan 15, 2025
1 parent 3b4ca26 commit 1df8f71
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions adapters/pixfuture/pixfuture.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pixfuture

import (
"encoding/json"
"fmt"
"net/http"

Expand All @@ -24,21 +25,48 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
}

// MakeRequests prepares and serializes HTTP requests to be sent to the Pixfuture endpoint.
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := jsonutil.Marshal(request)
func (a *adapter) MakeRequests(bidRequest *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error

// Validate the bid request
if bidRequest == nil || len(bidRequest.Imp) == 0 {
errs = append(errs, fmt.Errorf("no valid impressions in bid request"))
return nil, errs
}

// Process impressions
var validImpressions []openrtb2.Imp
for _, imp := range bidRequest.Imp {
if imp.Banner == nil && imp.Video == nil {
errs = append(errs, fmt.Errorf("unsupported impression type for impID: %s", imp.ID))
continue
}
validImpressions = append(validImpressions, imp)
}

if len(validImpressions) == 0 {
errs = append(errs, fmt.Errorf("no valid impressions after filtering"))
return nil, errs
}

// Create the outgoing request
bidRequest.Imp = validImpressions
body, err := json.Marshal(bidRequest)
if err != nil {
return nil, []error{err}
errs = append(errs, fmt.Errorf("failed to marshal bid request: %v", err))
return nil, errs
}

requestData := &adapters.RequestData{
request := &adapters.RequestData{
Method: "POST",
Uri: a.endpoint,
Body: requestJSON,
Body: body,
Headers: http.Header{
"Content-Type": []string{"application/json"},
},
}
return []*adapters.RequestData{requestData}, nil

return []*adapters.RequestData{request}, errs
}

// getMediaTypeForBid extracts the bid type based on the bid extension data.
Expand Down

0 comments on commit 1df8f71

Please sign in to comment.