2009-11-26 7 views
0

Je veux utiliser oohembed pour obtenir des informations sur certains liens.Importer des données json ooembed avec ruby ​​

Comment puis-je retreive données JSON d'un lien:

http://oohembed.com/oohembed/?url=http://www.youtube.com/watch?v=iWhmOPJXpSw&feature=subtivity 

comme

{ "title": "Aquarium", "html": "", "author_name": "passmorelab", "height": 344, "thumbnail_width": 120, "width": 425, "version": "1.0", "author_url": "http://www.youtube.com/user/passmorelab", "provider_name": "Youtube", "thumbnail_url": "http://i.ytimg.com/vi/iWhmOPJXpSw/1.jpg", "type": "video", "thumbnail_height": 90 } 

et l'importer dans une variable?

grâce

Répondre

0

façon la plus rapide

require "json" 
var= JSON.load(`wget -O - "url"`) 

Ce qui est bon pour un jet de script loin. Mais pas pour quelque chose de réel.

La belle façon

require "json" 
require "net/http" 
require "uri" 

JSON.load(Net::HTTP.get(URI.parse(url)))