lib/qualtrics/response.rb in qualtrics-0.5.7 vs lib/qualtrics/response.rb in qualtrics-0.5.8
- old
+ new
@@ -1,6 +1,7 @@
require 'json'
+require 'csv'
module Qualtrics
class Response
def initialize(raw_response)
@@ -26,14 +27,30 @@
def body
if @body.nil?
if @raw_response.body == ''
@body = {}
- else
+ elsif content_type == 'application/json'
@body = JSON.parse(@raw_response.body)
+ elsif content_type == 'application/vnd.msexcel'
+ @body = CSV.parse(@raw_response.body)
+ else
+ raise Qualtrics::UnexpectedContentType, content_type
end
end
@body
+ end
+
+ def content_type
+ if @content_type.nil?
+ header = @raw_response.headers['Content-Type']
+ if header.nil?
+ @content_type = {}
+ else
+ @content_type = header
+ end
+ end
+ @content_type
end
private
def error_message
body['Meta'].nil? ? 'No error message' : body['Meta']['ErrorMessage']