Skip to content

Commit

Permalink
some fixies
Browse files Browse the repository at this point in the history
  • Loading branch information
RapidCodeLab committed Feb 17, 2024
1 parent e51e18a commit 1a62d25
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion items.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"1e4f53d0-a5f0-4011-a708-4cf04ae39d20":{"id":"1e4f53d0-a5f0-4011-a708-4cf04ae39d20","video_url":"http://cdn.host.com/file.mp4","destination_url":"http://click.ru","bid":1.22}}
{"1e4f53d0-a5f0-4011-a708-4cf04ae39d20":{"id":"1e4f53d0-a5f0-4011-a708-4cf04ae39d20","title":"Ad title","video_duration":"00:00:25","video_url":"http://cdn.host.com/file.mp4","destination_url":"http://click.ru?sub_id={{source_id}}\u0026sub_id_1={{ad_id}}","bid":1.25}}
5 changes: 5 additions & 0 deletions provider/item-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (p *Provider) GetItemsHandler(ctx *fasthttp.RequestCtx) {
return
}

ctx.SetContentType("application/json")
ctx.SetBody(data)
}

Expand All @@ -31,6 +32,7 @@ func (p *Provider) GetItemHandler(ctx *fasthttp.RequestCtx) {
return
}

ctx.SetContentType("application/json")
ctx.SetBody(data)
}

Expand All @@ -47,6 +49,9 @@ func (p *Provider) UpsertItemHandler(ctx *fasthttp.RequestCtx) {
item.ID = uuid.NewString()
}

p.items.mu.Lock()
defer p.items.mu.Unlock()

p.items.data[item.ID] = item
}

Expand Down
18 changes: 15 additions & 3 deletions provider/rtb-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ func (p *Provider) BidRequestHandler(ctx *fasthttp.RequestCtx) {
{
Bid: []openrtb2.Bid{
{
ID: uuid.NewString(),
ID: uuid.NewString(),
ImpID: bidRequest.Imp[0].ID,
AdID: item.ID,
Price: item.Bid,
CID: item.ID,
CrID: item.ID,
NURL: p.baseURL + "/rtb/notify/" + item.ID,
AdM: p.baseURL + "/rtb/vast/" + item.ID,
AdM: p.baseURL +
"/rtb/vast/" +
item.ID +
"?source_id=" +
bidRequest.Site.ID,
},
},
},
Expand All @@ -57,6 +61,7 @@ func (p *Provider) BidRequestHandler(ctx *fasthttp.RequestCtx) {
return
}

ctx.SetContentType("application/json")
ctx.SetBody(data)
}

Expand All @@ -78,9 +83,16 @@ func (p *Provider) VASTHandler(ctx *fasthttp.RequestCtx) {
return
}

sourceID := ctx.QueryArgs().Peek("source_id")

destURL := strings.Replace(item.DestinationUrl, "{{ad_id}}", item.ID, -1)
destURL = strings.Replace(destURL, "{{source_id}}", string(sourceID), -1)

data := strings.Replace(vastTemplate, "{{ad_id}}", item.ID, -1)
data = strings.Replace(data, "{{video_url}}", item.VideoURL, -1)
data = strings.Replace(data, "{{destination_url}}", item.DestinationUrl, -1)
data = strings.Replace(data, "{{title}}", item.Title, -1)
data = strings.Replace(data, "{{video_duration}}", item.VideoDuration, -1)
data = strings.Replace(data, "{{destination_url}}", destURL, -1)
data = strings.Replace(data, "{{base_url}}", p.baseURL, -1)

ctx.SetContentType("text/xml")
Expand Down
2 changes: 2 additions & 0 deletions provider/stat-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func (p *Provider) StatsHandler(ctx *fasthttp.RequestCtx) {
return
}

ctx.SetContentType("application/json")
ctx.SetBody(data)
}

Expand All @@ -30,5 +31,6 @@ func (p *Provider) ItemStatsHandler(ctx *fasthttp.RequestCtx) {
return
}

ctx.SetContentType("application/json")
ctx.SetBody(data)
}
2 changes: 2 additions & 0 deletions provider/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (
type (
item struct {
ID string `json:"id"`
Title string `json:"title"`
VideoDuration string `json:"video_duration"`
VideoURL string `json:"video_url"`
DestinationUrl string `json:"destination_url"`
Bid float64 `json:"bid"`
Expand Down
7 changes: 2 additions & 5 deletions provider/vast-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package provider
const vastTemplate = `<VAST version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<Ad id="{{ad_id}}">
<InLine>
<AdSystem version="4.0">iabtechlab</AdSystem>
<AdTitle>iabtechlab video ad</AdTitle>
<Error>http://example.com/error</Error>
<AdTitle>{{title}}</AdTitle>
<Impression id="Impression-ID">{{base_url}}/vast/impression/{{ad_id}}</Impression>
<Creatives>
<Creative id="{{ad_id}}" sequence="1">
<Linear>
<Duration>00:00:16</Duration>
<Duration>{{video_duration}}</Duration>
<TrackingEvents>
<Tracking event="start">{{base_url}}/vast/start/{{ad_id}}</Tracking>
Expand All @@ -34,7 +32,6 @@ const vastTemplate = `<VAST version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSc
<![CDATA[{{video_url}}]]>
</MediaFile>
</MediaFiles>
</Linear>
</Creative>
</Creatives>
Expand Down

0 comments on commit 1a62d25

Please sign in to comment.