lib/bamboozled/api/base.rb in bamboozled-0.0.7 vs lib/bamboozled/api/base.rb in bamboozled-0.1.0
- old
+ new
@@ -1,6 +1,7 @@
require 'json'
+require "time"
require 'active_support/core_ext/hash/indifferent_access'
module Bamboozled
module API
class Base
@@ -33,10 +34,14 @@
params[:response] = response.inspect.to_s
case response.code
when 200..201
begin
- JSON.parse(response).with_indifferent_access
+ if response.body.to_s.empty?
+ {"headers" => response.headers}.with_indifferent_access
+ else
+ JSON.parse(response.body).with_indifferent_access
+ end
rescue
MultiXml.parse(response, symbolize_keys: true)
end
when 400
raise Bamboozled::BadRequest.new(response, params, 'The request was invalid or could not be understood by the server. Resubmitting the request will likely result in the same error.')