Skip to content

Instantly share code, notes, and snippets.

@soffes
Created August 7, 2015 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soffes/bcffa0cee13c517d7710 to your computer and use it in GitHub Desktop.
Save soffes/bcffa0cee13c517d7710 to your computer and use it in GitHub Desktop.
Convert old DVR cassettes to the new format
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