Files
old-vendor-scheduler-service/app/services/vendors/vistar/vistar_fetch_schedule.rb
2022-03-23 05:44:42 +01:00

38 lines
842 B
Ruby

module Vendors
module Vistar
class VistarFetchSchedule
def initialize(tokens)
@tokens = tokens
end
def call(params)
fetch = fetch_ad(params)
return nil unless fetch && fetch[:advertisement]
ad = fetch[:advertisement][0]
{
contents: [
{
name: "vistar_asset_#{ad[:asset_id]}",
url: ad[:asset_url]
}
],
startTime: Time.at(ad[:display_time]).to_datetime,
items: [
{
contentIndex: 0,
duration: "#{ad[:length_in_seconds]}s",
pop_url: ad[:proof_of_play_url]
}
]
}
end
private
def fetch_ad(params)
Vendors::Vistar::VistarFetchAd.new(@tokens).call(params)
end
end
end
end