Class: MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb

Constant Summary collapse

@@default_option =
ParametersNameDecodingOption.new

Instance Method Summary collapse

Instance Method Details

#call(request_env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb', line 7

def call(request_env)
    request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil?
    request_option = @@default_option if request_option.nil?
    unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty? then
        request_url = request_env[:url].to_s
        request_option.characters_to_decode.each do |character|
            request_url = request_url.gsub(get_regex_for_character(character), character)
        end
        request_env[:url] = URI.parse(request_url)
    end
    @app.call(request_env) unless @app.nil?
end

#get_regex_for_character(character) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb', line 20

def get_regex_for_character(character)
    @regex_cache ||= Hash.new
    if @regex_cache[character].nil? then
        @regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true)
    end
    return @regex_cache[character]
end