Skip to content

Instantly share code, notes, and snippets.

@sujee
Created March 7, 2011 20:32
Show Gist options
  • Save sujee/859152 to your computer and use it in GitHub Desktop.
Save sujee/859152 to your computer and use it in GitHub Desktop.
covercake web service api client in ruby
require 'rubygems'
#install the following gems
require 'json'
require 'rest_client'
API_KEY="your_key_here"
response = RestClient.get "https://covercake.com/api/v1/feeds", {:params => {:key => API_KEY}}
j = JSON::parse(response)
#p response
unless j['status'] =~ /OK/i
puts "error : #{j['status_text']}"
exit
end
#p j
# get feeds, pick a random feed
feeds = j['feeds']
feed1 = feeds[4]
puts "feed: [#{feed1['id']}] #{feed1['name']}"
response = RestClient.get "https://covercake.com/api/v1/feed_info", {:params => {:key => API_KEY, :id => feed1['id']}}
j = JSON::parse(response)
unless j['status'] =~ /OK/i
puts "error : #{j['status_text']}"
exit
end
featurings = j['featurings']
#pick the first featuring
featuring1 = featurings[0]
#p featuring1
#extract the book info
book1 = featuring1['book']
puts "Featured date : #{featuring1['featured_date']}, book : #{book1['title']}"
#get more data about the book
response = RestClient.get "https://covercake.com/api/v1/book_info", {:params => {:key => API_KEY, :id => book1['id']}}
j = JSON::parse(response)
unless j['status'] =~ /OK/i
puts "error : #{j['status_text']}"
exit
end
#p j
book = j['book']
puts "book isbn: #{book['isbn10']}"
puts "this book has been featured #{j['featurings'].count} times"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment