lib/async/rest/wrapper/url_encoded.rb in async-rest-0.8.2 vs lib/async/rest/wrapper/url_encoded.rb in async-rest-0.9.0

- old
+ new

@@ -21,14 +21,16 @@ require 'json' require 'protocol/http/body/wrapper' require 'protocol/http/body/buffered' +require_relative 'generic' + module Async module REST module Wrapper - class URLEncoded + class URLEncoded < Generic APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded".freeze def initialize(content_type = APPLICATION_FORM_URLENCODED) @content_type = content_type end @@ -49,27 +51,31 @@ ::Protocol::HTTP::URL.encode(payload) ]) end end + class Parser < ::Protocol::HTTP::Body::Wrapper + def join + ::Protocol::HTTP::URL.decode(super, symbolize_keys: true) + end + end + + def wrap_response(response) + if body = response.body + response.body = Parser.new(body) + end + end + def process_response(request, response) if content_type = response.headers['content-type'] if content_type.start_with? @content_type - if body = response.body - response.body = Parser.new(body) - end + wrap_response(response) else - warn "Unknown content type: #{content_type}!" + raise Error, "Unknown content type: #{content_type}!" end end return response - end - - class Parser < ::Protocol::HTTP::Body::Wrapper - def join - ::Protocol::HTTP::URL.decode(super, symbolize_keys: true) - end end end end end end