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