I like to have a script, which fetches data from a REST-API. Then then writes the data into a CSV-file file.
Here's what I've got so far (prototype, using ana publicly accessible dummy-API):
require 'net/http'
require 'json'
require 'csv'
uri = URI("https://swapi.dev/api/people/")
response = JSON.parse(Net::HTTP.get(uri))
response["results"].each do |person|
CSV.open("people.csv", "a+") do |csv|
csv << [person["name"], person["height"],
person["mass"], person["hair_color"],
person["skin_color"]]
end
end
=begin
-- File-content ----------------
Luke Skywalker,172,77,blond,fair
C-3PO,167,75,n/a,gold
R2-D2,96,32,n/a,"white, blue"
...
=end
Are there points to improve? Would you have chosen a completely different approach?