Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.