Skip to content

Instantly share code, notes, and snippets.

@naoyashiga
Created March 18, 2015 13:30
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save naoyashiga/018613ddfed021766408 to your computer and use it in GitHub Desktop.
Seeing a cat image or GIF by using the Cat API
# -*- encoding: UTF-8 -*-
require 'nokogiri'
require 'open-uri'
API_URL = "http://thecatapi.com/api/images/get?format=xml"
doc = Nokogiri::XML(open(API_URL).read)
url_nodes = doc.xpath("//url").text
puts url_nodes
# open browser
system "open " + url_nodes
<?xml version="1.0"?>
<response>
<data>
<images>
<image>
<url>http://25.media.tumblr.com/qgIb8tERinzopu0j9Alm3YrHo1_500.jpg</url>
<id>8dd</id>
<source_url>http://thecatapi.com/?id=8dd</source_url>
</image>
</images>
</data>
</response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment