Created
March 7, 2011 20:32
-
-
Save sujee/859152 to your computer and use it in GitHub Desktop.
covercake web service api client in ruby
This file contains 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
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