lib/flexirest/request.rb in flexirest-1.10.2 vs lib/flexirest/request.rb in flexirest-1.10.3

- old
+ new

@@ -134,10 +134,34 @@ else @object.class.request_body_type end end + def ignore_root + if @method[:options][:ignore_root] + @method[:options][:ignore_root] + elsif @object.nil? + nil + elsif object_is_class? + @object.ignore_root + else + @object.class.ignore_root + end + end + + def wrap_root + if @method[:options][:wrap_root] + @method[:options][:wrap_root] + elsif @object.nil? + nil + elsif object_is_class? + @object.wrap_root + else + @object.class.wrap_root + end + end + def verbose? if object_is_class? @object.verbose else @object.class.verbose @@ -436,12 +460,12 @@ params elsif @post_params.is_a?(String) @post_params else p = (params || @post_params || {}) - if @method[:options][:wrap_root].present? - p = {@method[:options][:wrap_root] => p} + if wrap_root.present? + p = {wrap_root => p} end p.to_query end headers["Content-Type"] ||= "application/x-www-form-urlencoded" elsif request_body_type == :form_multipart @@ -450,12 +474,12 @@ params elsif @post_params.is_a?(String) @post_params else p = (params || @post_params || {}) - if @method[:options][:wrap_root].present? - p = {@method[:options][:wrap_root] => p} + if wrap_root.present? + p = {wrap_root => p} end data, mp_headers = Flexirest::Multipart::Post.prepare_query(p) mp_headers.each do |k,v| headers[k] = v end @@ -465,12 +489,12 @@ @body ||= if params.is_a?(String) params elsif @post_params.is_a?(String) @post_params else - if @method[:options][:wrap_root].present? - {@method[:options][:wrap_root] => (params || @post_params || {})}.to_json + if wrap_root.present? + {wrap_root => (params || @post_params || {})}.to_json else (params || @post_params || {}).to_json end end headers["Content-Type"] ||= "application/json; charset=utf-8" @@ -599,11 +623,11 @@ if @response.respond_to?(:proxied) && @response.proxied Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size" else Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response received #{@response.body.size} bytes" end - result = generate_new_object(ignore_root: @method[:options][:ignore_root], ignore_xml_root: @method[:options][:ignore_xml_root]) + result = generate_new_object(ignore_root: ignore_root, ignore_xml_root: @method[:options][:ignore_xml_root]) # TODO: Cleanup when ignore_xml_root is removed else raise ResponseParseException.new(status:status, body:@response.body, headers: @response.headers) end else @@ -812,18 +836,18 @@ if is_json_api_response? body = JsonAPIProxy::Response.parse(body, @object) end - if options[:ignore_root] - [options[:ignore_root]].flatten.each do |key| + if ignore_root + [ignore_root].flatten.each do |key| body = body[key.to_s] end end elsif is_xml_response? body = @response.body.blank? ? {} : Crack::XML.parse(@response.body) - if options[:ignore_root] - [options[:ignore_root]].flatten.each do |key| + if ignore_root + [ignore_root].flatten.each do |key| body = body[key.to_s] end elsif options[:ignore_xml_root] Flexirest::Logger.warn("Using `ignore_xml_root` is deprecated, please switch to `ignore_root`") body = body[options[:ignore_xml_root].to_s]