Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created December 15, 2010 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesrog/742656 to your computer and use it in GitHub Desktop.
Save wesrog/742656 to your computer and use it in GitHub Desktop.
Simple Discogs Ruby API Client
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