1
0
Fork 0

Fix exception while writing utf8 to cache

This commit is contained in:
Gregory Eremin 2012-12-05 08:53:33 +04:00
parent 517ff4bd76
commit 18ba6bea34
2 changed files with 4 additions and 2 deletions

View File

@ -9,6 +9,8 @@ module MusicBrainz
end
def load(resource, query, params)
raise Exception.new("You need to run MusicBrainz.configure before querying") if MusicBrainz.config.nil?
response = contents_of(build_url(resource, query))
xml = Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')
data = params[:binding].parse(xml)

View File

@ -18,12 +18,12 @@ module MusicBrainz
response = nil
if File.exist?(file_path)
response = File.open(file_path).gets
response = File.open(file_path, 'rb').gets
else
response = super
unless response.nil? or response.empty?
FileUtils.mkdir_p file_path.split('/')[0..-2].join('/')
File.open(file_path, 'w') do |f|
File.open(file_path, 'wb') do |f|
f.puts response
f.chmod 0755
f.close