When my shell scripts get too large, I usually switch to Perl. Still best in class at handling text processing with a few shell commands here and there.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'json', require: false
gem 'nap', require: 'rest'
gem 'cocoapods', '~> 0.34.1'
end