Recherche…


Obtenir la première page en Ruby

Cet exemple Ruby utilise Mechanize , une bibliothèque pour automatiser les interactions Web.

client_id est un identifiant client OAuth.

game est le répertoire de jeu à lister.

require 'mechanize'
master_agent = Mechanize.new

client_id = "123"
game = "Minecraft"

url = "https://api.twitch.tv/kraken/streams?game=#{game}&client_id=#{client_id}"
final_list = []
master_agent.get(url) do |page|
    master_list = JSON.parse(page.body)
    master_list["streams"].each do |stream|
        final_list << stream["channel"]["name"]
    end
end


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow