Sha256: f6a88e5a19a4f44815f1c5a6746e36736e6f324fadb1d97f2737f45866eafbb6
Contents?: true
Size: 805 Bytes
Versions: 6
Compression:
Stored size: 805 Bytes
Contents
require 'backlog_kit/response/middleware' require 'backlog_kit/resource_file' module BacklogKit class Response class FileParser < BacklogKit::Response::Middleware def on_complete(env) super env.body = BacklogKit::ResourceFile.new(decoded_filename, body) if file? end private def file? !(no_content? || json?) end def decoded_filename match_data = content_disposition.match(/=(.*)''(.+)\z/) encode = match_data[1] filename = match_data[2] return filename if encode.empty? URI.decode_www_form_component(filename, encode) end def content_disposition headers['content-disposition'] end end Faraday::Response.register_middleware(file_parser: FileParser) end end
Version data entries
6 entries across 6 versions & 1 rubygems