Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Created August 17, 2016 19:36
Show Gist options
  • Save brunojppb/487d5c6c6917f5a91feab0569c3e5964 to your computer and use it in GitHub Desktop.
Save brunojppb/487d5c6c6917f5a91feab0569c3e5964 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
def listar_usuarios
uri = URI('http://jsonplaceholder.typicode.com/users')
response = Net::HTTP.get(uri)
JSON.parse(response)
yield JSON.parse(response) if block_given?
puts "Finalizando listagem de usuarios"
end
listar_usuarios do |response|
puts "Total de usuarios: #{response.size}"
end
listar_usuarios do |usuarios|
usuarios.each do |usuario|
puts "Nome: #{usuario["name"]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment