Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make iab-vast-parser compatible with new version of iab-vast-model #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ on the fly.
## Maintainer

[Tim De Pauw](https://github.com/timdp)
[Laurent De Smet](https://github.com/laurentdesmet)

## License

Expand Down
52 changes: 27 additions & 25 deletions src/factory/vast.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import {VAST, AdPod} from 'iab-vast-model'
import {VAST} from 'iab-vast-model'
import createAd from './ad'

const triageAds = ($$ads) => {
const $$adsWithSequence = []
const $$adsWithoutSequence = []
for (let i = 0; i < $$ads.length; ++i) {
const $ad = $$ads[i]
if (typeof $ad.sequence !== 'undefined') {
$$adsWithSequence.push($ad)
} else {
$$adsWithoutSequence.push($ad)
}
const isSingleAdPod = $vast => $vast.ad.length === 1 && $vast.ad[0].sequence !== 'undefined'

const createPod = ($vast, vast, options) => {
if (!(options.noSingleAdPods && isSingleAdPod($vast))) {
$vast.ad
.filter($ad => typeof $ad.sequence !== 'undefined')
.map($ad => createAd($ad, options))
.forEach(podAd => vast.adPod.add(podAd))
}
}

const createBuffet = ($vast, vast, options) => {
if (options.noSingleAdPods && isSingleAdPod($vast)) {
const singlePodAd = createAd($vast.ad[0], options)
vast.adBuffet.add(singlePodAd)
} else {
$vast.ad
.filter($ad => typeof $ad.sequence === 'undefined')
.map($ad => createAd($ad, options))
.forEach(buffetAd => vast.adBuffet.add(buffetAd))
}
return [$$adsWithSequence, $$adsWithoutSequence]
}

const createVAST = ($vast, options) => {
const vast = new VAST()
vast.version = $vast.version
const [$$adsWithSequence, $$adsWithoutSequence] = triageAds($vast.ad)
if ($$adsWithSequence.length > 0) {
if (options.noSingleAdPods &&
$vast.ad.length === 1 && $$adsWithSequence.length === 1) {
$$adsWithoutSequence.push($$adsWithSequence[0])
} else {
vast.adPod = new AdPod()
for (let i = 0; i < $$adsWithSequence.length; i++) {
vast.adPod.ads.add(createAd($$adsWithSequence[i], options))
}
if ($vast.ad && $vast.ad.length > 0) {
try {
createPod($vast, vast, options)
createBuffet($vast, vast, options)
} catch (err) {
options.errorHandler(err)
}
}
for (let i = 0; i < $$adsWithoutSequence.length; i++) {
vast.ads.add(createAd($$adsWithoutSequence[i], options))
}
return vast
}

Expand Down
6 changes: 3 additions & 3 deletions src/factory/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default ($ad, options) => {
wrapper.vastAdTagURI = ($wrapper.vastAdTagURI != null)
? $wrapper.vastAdTagURI._value
: null
wrapper.followAdditionalWrappers = !!$wrapper.followAdditionalWrappers
wrapper.allowMultipleAds = !!$wrapper.allowMultipleAds
wrapper.fallbackOnNoAd = !!$wrapper.fallbackOnNoAd
wrapper.followAdditionalWrappers = $wrapper.followAdditionalWrappers
wrapper.allowMultipleAds = $wrapper.allowMultipleAds
wrapper.fallbackOnNoAd = $wrapper.fallbackOnNoAd
return wrapper
}
2 changes: 1 addition & 1 deletion test/lib/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getPropertyNames = (proto) => {
const marshalObject = (obj) => {
const result = Object.create(null)
const props = getPropertyNames(Object.getPrototypeOf(obj))
.filter((name) => (name !== '$type' && name !== 'error'))
.filter((name) => name !== '$type' && name !== 'error')
for (const prop of props) {
const value = obj[prop]
if (value != null) {
Expand Down
Loading