Created
August 17, 2016 19:36
-
-
Save brunojppb/487d5c6c6917f5a91feab0569c3e5964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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