Created
July 29, 2012 16:09
-
-
Save techmaniack/3199935 to your computer and use it in GitHub Desktop.
ISBN decoder
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
#!/usr/bin/env ruby | |
#------------------------------------------------------------------------------- | |
# Name: isbn_decoder.rb | |
# Purpose: Fetch title from ISBN . | |
# | |
# Author: AbdulKarim Memon | |
# | |
# Created: 29/07/2012 | |
# Copyright: (c) AbdulKarim Memon 2012 | |
# Licence: GPL v3 | |
# Notes: Fill the access 'key' information before running. | |
# | |
# Dependancy: 'xml-simple' | |
# $ gem install -V xml-simple | |
# | |
# Sample Usage: | |
# $ruby ./isbn_debugger.rb 978-0596516178 | |
# Title: ["The Ruby programming language"] | |
# Author: ["David Flanagan and Yukihiro Matsumoto"] | |
require 'net/http' | |
require 'xmlsimple' | |
key='12345678' # Access Key from isbndb.com | |
url='http://isbndb.com/api/books.xml?access_key=' | |
#ARGV[0] is the first command line arguement | |
full_url=url + key + '&index1=isbn&value1=' + ARGV[0] | |
#puts full_url | |
xml_data = Net::HTTP.get_response(URI.parse(full_url)).body | |
data=XmlSimple.xml_in(xml_data) | |
#Display the Title and Author | |
begin | |
puts "Title: #{data["BookList"][0]["BookData"][0]["Title"]}" | |
puts "Author: #{data["BookList"][0]["BookData"][0]["AuthorsText"]}" | |
rescue | |
puts "Invalid ISBN or Communication Error" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment