Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CSV output from a JSON API with a call limit
require 'httparty'
require 'csv'
require 'json'
x = 0
while x < 46296 # this is the last record in my particular API
puts "on offset #{x}"
url = "{x}&limit=500"
response = HTTParty.get(url)
jobs_only = { |job| job["uuid"] != nil }
csv_string = CSV.generate do |csv|
jobs_only.each do |hash|
csv << hash.values
end"jobs.csv", "a") {|f| f.write(csv_string) }
x += 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.