Skip to content

Instantly share code, notes, and snippets.

@naoyashiga naoyashiga/catApi.rb
Created Mar 18, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.