Skip to content

Commit

Permalink
Appnexus: Update appendMemberId function (#2747)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonali-More-Xandr authored May 18, 2023
1 parent 1e8faa7 commit 4492a17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
25 changes: 15 additions & 10 deletions adapters/appnexus/appnexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"

Expand All @@ -27,15 +28,20 @@ const (
)

type adapter struct {
uri string
uri url.URL
hbSource int
randomGenerator randomutil.RandomGenerator
}

// Builder builds a new instance of the AppNexus adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
uri, err := url.Parse(config.Endpoint)
if err != nil {
return nil, err
}

bidder := &adapter{
uri: config.Endpoint,
uri: *uri,
hbSource: resolvePlatformID(config.PlatformID),
randomGenerator: randomutil.RandomNumberGenerator{},
}
Expand Down Expand Up @@ -146,11 +152,11 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
// If impressions number per pod is more than maxImpsPerReq - divide those imps to several requests but keep pod id the same
// If adpodId feature disabled and impressions number per pod is more than maxImpsPerReq - divide those imps to several requests but do not include ad pod id
if isVIDEO == 1 && *shouldGenerateAdPodId {
requests, errors := a.buildAdPodRequests(request.Imp, request, reqExt, requestURI)
requests, errors := a.buildAdPodRequests(request.Imp, request, reqExt, requestURI.String())
return requests, append(errs, errors...)
}

requests, errors := splitRequests(request.Imp, request, reqExt, requestURI)
requests, errors := splitRequests(request.Imp, request, reqExt, requestURI.String())
return requests, append(errs, errors...)
}

Expand Down Expand Up @@ -375,12 +381,11 @@ func (a *adapter) findIabCategoryForBid(bid *appnexusBidExt) (string, bool) {
return iabCategory, ok
}

func appendMemberId(uri string, memberId string) string {
if strings.Contains(uri, "?") {
return uri + "&member_id=" + memberId
}

return uri + "?member_id=" + memberId
func appendMemberId(uri url.URL, memberId string) url.URL {
q := uri.Query()
q.Set("member_id", memberId)
uri.RawQuery = q.Encode()
return uri
}

func buildDisplayManageVer(req *openrtb2.BidRequest) string {
Expand Down
13 changes: 7 additions & 6 deletions adapters/appnexus/appnexus_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package appnexus

import (
"net/url"
"testing"

"github.com/prebid/prebid-server/adapters/adapterstest"
Expand All @@ -23,12 +24,12 @@ func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "appnexustest", bidder)
}

func TestMemberQueryParam(t *testing.T) {
uriWithMember := appendMemberId("http://ib.adnxs.com/openrtb2?query_param=true", "102")
expected := "http://ib.adnxs.com/openrtb2?query_param=true&member_id=102"
if uriWithMember != expected {
t.Errorf("appendMemberId() failed on URI with query string. Expected %s, got %s", expected, uriWithMember)
}
func TestAppendMemberID(t *testing.T) {
uri, err := url.Parse("http://ib.adnxs.com/openrtb2?query_param=true")
assert.NoError(t, err, "Failed to parse URI with query string")
uriWithMember := appendMemberId(*uri, "102")
expected := "http://ib.adnxs.com/openrtb2?member_id=102&query_param=true"
assert.Equal(t, expected, uriWithMember.String(), "Failed to append member id to URI with query string")
}

func TestBuilderWithPlatformID(t *testing.T) {
Expand Down

0 comments on commit 4492a17

Please sign in to comment.