Created
January 30, 2017 12:31
-
-
Save hjanuschka/a04a9af7de3f92a93a973f5bc30fc396 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "tty-spinner" | |
require "tty-table" | |
require 'rest-client' | |
require "pry" | |
require 'xmlsimple' | |
require "colored" | |
module HJ | |
class VAST | |
attr_accessor :spinner | |
attr_accessor :hops | |
attr_accessor :table_rows | |
def initialize(url) | |
@spinner = TTY::Spinner.new("Resolving VAST :spinner", format: :bouncing_ball) | |
@hops = 0 | |
spinner.auto_spin | |
@table_rows = [] | |
resolve_vast(url) | |
end | |
def resolve_vast(url) | |
@hops += 1 | |
data = RestClient.get(url) | |
xml = XmlSimple.xml_in(data.body) | |
@table_rows << [url, @hops.to_s] | |
if xml["Ad"].first["Wrapper"] && xml["Ad"].first["Wrapper"].first["VASTAdTagURI"] | |
resolve_vast(xml["Ad"].first["Wrapper"].first["VASTAdTagURI"].first) | |
else | |
spinner.stop | |
finished_urls = [] | |
xml["Ad"].first["InLine"].first["Creatives"].first["Creative"].first["Linear"].first["MediaFiles"].first["MediaFile"].each do | u | | |
finished_urls << "#{u["content"].chomp}" | |
end | |
puts "Path:" | |
@table_rows.each_with_index do | h, index | | |
puts "---------" | |
puts "Hop: #{index}".red | |
puts "#{h[0]}" | |
puts "---------" | |
end | |
puts "Resulted in: " | |
puts finished_urls.join("\n").green | |
end | |
end | |
end | |
end | |
HJ::VAST.new(ARGV[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment