Skip to content

Commit

Permalink
Merge pull request #6 from taboola/support-native
Browse files Browse the repository at this point in the history
Support native
  • Loading branch information
ahmadlob authored Feb 7, 2023
2 parents 38fefab + 0a81621 commit 3e242bd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions adapters/taboola/taboola.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ type adapter struct {
endpoint *template.Template
}

const (
NATIVE_ENDPOINT_PREFIX = "native"
DISPLAY_ENDPOINT_PREFIX = "display"
)

// Builder builds a new instance of the Foo adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
endpointTemplate, err := template.New("endpointTemplate").Parse(config.Endpoint)
Expand All @@ -47,7 +42,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte

for _, taboolaRequest := range taboolaRequests {
if len(taboolaRequest.Imp) > 0 {
request, err := a.buildRequest(taboolaRequest)
request, err := buildRequest(taboolaRequest, a.endpoint)
if err != nil {
return nil, []error{fmt.Errorf("unable to build request %v", err)}
}
Expand Down Expand Up @@ -117,12 +112,17 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
return bidResponse, errs
}

func (a *adapter) buildRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) {
func buildRequest(request *openrtb2.BidRequest, endpoint *template.Template) (*adapters.RequestData, error) {
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, err
}

const (
NATIVE_ENDPOINT_PREFIX = "native"
DISPLAY_ENDPOINT_PREFIX = "display"
)

//set MediaType based on first imp
var mediaType string
if request.Imp[0].Banner != nil {
Expand All @@ -133,7 +133,7 @@ func (a *adapter) buildRequest(request *openrtb2.BidRequest) (*adapters.RequestD
return nil, fmt.Errorf("unsupported media type for imp: %v", request.Imp[0])
}

url, err := a.buildEndpointURL(request.Site.ID, mediaType)
url, err := buildEndpointURL(request.Site.ID, mediaType, endpoint)
if err != nil {
return nil, err
}
Expand All @@ -148,9 +148,9 @@ func (a *adapter) buildRequest(request *openrtb2.BidRequest) (*adapters.RequestD
}

// Builds endpoint url based on adapter-specific pub settings from imp.ext
func (a *adapter) buildEndpointURL(publisherId string, mediaType string) (string, error) {
func buildEndpointURL(publisherId string, mediaType string, endpoint *template.Template) (string, error) {
endpointParams := macros.EndpointTemplateParams{PublisherID: publisherId, MediaType: mediaType}
resolvedUrl, err := macros.ResolveMacros(a.endpoint, endpointParams)
resolvedUrl, err := macros.ResolveMacros(endpoint, endpointParams)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func overrideBidRequestImp(originBidRequest *openrtb2.BidRequest, imp []openrtb2
}

func overrideEventTrackers(nativePayload *nativeResponse.Response) {
// convert evventrackers to the deprecated imptrackers and jstracker because it's not supported in native 1.1v
// convert eventrackers to the deprecated imptrackers and jstracker because it's not supported in native 1.1v
for _, eventTracker := range nativePayload.EventTrackers {
if eventTracker.Event != native1.EventTypeImpression {
continue
Expand Down

0 comments on commit 3e242bd

Please sign in to comment.