Created
December 15, 2010 21:40
-
-
Save wesrog/742656 to your computer and use it in GitHub Desktop.
Simple Discogs Ruby API Client
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
require 'zlib' | |
require 'open-uri' | |
url = "http://www.discogs.com/release/123?f=xml&api_key=111" | |
headers = {'Accept-Encoding' => 'gzip', 'User-Agent' => 'MyDiscogsClient/1.0 +http://mydiscogsclient.org'} | |
begin | |
response = open(url, headers) | |
begin | |
data = Zlib::GzipReader.new(response) | |
rescue Zlib::GzipFile::Error | |
response.seek(0) | |
data = response.read | |
end | |
rescue OpenURI::HTTPError => e | |
data = e.io.read | |
end | |
puts data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment