Sha256: 57905a555d0075df1a7d1b674ec285845f4fe2a1996201a91042fa4c005ce718
Contents?: true
Size: 809 Bytes
Versions: 12
Compression:
Stored size: 809 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(filename, encode).flatten.first end def content_disposition headers['content-disposition'] end end Faraday::Response.register_middleware(file_parser: FileParser) end end
Version data entries
12 entries across 12 versions & 1 rubygems