Created
August 7, 2015 23:17
-
-
Save soffes/bcffa0cee13c517d7710 to your computer and use it in GitHub Desktop.
Convert old DVR cassettes to the new format
This file contains 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 'json' | |
require 'base64' | |
unless input = ARGV.first | |
puts 'Run with `ruby convert.rb path_to_your_cassette.json`' and return | |
end | |
def process(r) | |
return unless r && (body = r['body']) && (content_type = r['headers']['Content-Type']) | |
if content_type.start_with?('text/') | |
r['body'] = Base64.decode64(body) | |
elsif content_type.start_with?('application/json') | |
r['body'] = JSON.load(Base64.decode64(body)) | |
end | |
end | |
json = JSON.load(File.read(input)) | |
json['interactions'].each do |interaction| | |
process interaction['request'] | |
process interaction['response'] | |
end | |
puts JSON.pretty_generate(json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment