hi everybody,
IMHO it would be great to have the fully ruby instructions available into spi ; a child can use the spi language and then go to more sophisticated concepts.
What i have understood is that sonic pi contains only a space of functions of ruby ? Am i wrong ?
the loading of a external json file works right now into sonic pi.
require "json"
require 'net/http'
# call to an external api
url = "https://quote-garden.herokuapp.com/quotes/search/love"
uri = URI(url)
puts response = Net::HTTP.get(uri)
# to get enough time to get the api answer
sleep 4
foo = JSON.parse(response)
puts foo
# to puts the values
foo["results"].each do | quote|
puts quote["quoteText"] + " by " + quote["quoteAuthor"]
end
# if you want to get the index
foo["results"].each_with_index do |quote, idx|
puts idx.to_s + " -- " + quote["quoteText"] + " by " + quote["quoteAuthor"]
end
# to get some indice quote
puts foo["results"][25]["quoteText"]
puts foo["results"][25]["quoteAuthor"]
# get json string from a local file
s = File.read("/home/nlb/audio/audio-code/spi/instruments.json")
# parse and convert JSON to Ruby
obj = JSON.parse(s)
puts obj