Class: MailJack::ParamsDecoder
- Inherits:
-
Object
- Object
- MailJack::ParamsDecoder
- Defined in:
- lib/mail_jack/params_decoder.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #decode_params(env) ⇒ Object
-
#initialize(app) ⇒ ParamsDecoder
constructor
A new instance of ParamsDecoder.
Constructor Details
#initialize(app) ⇒ ParamsDecoder
3 4 5 |
# File 'lib/mail_jack/params_decoder.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/mail_jack/params_decoder.rb', line 7 def call(env) return @app.call(env) unless MailJack.configured? decode_params(env) if MailJack.config.enable_encoding? @status, @headers, @response = @app.call(env) [@status, @headers, @response] end |
#decode_params(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mail_jack/params_decoder.rb', line 14 def decode_params(env) param_name = MailJack.config.encode_to return unless env['QUERY_STRING'].present? and env['QUERY_STRING'].match(/#{param_name}\=/) params = {'QUERY_STRING' => env["QUERY_STRING"], 'REQUEST_URI' => env["REQUEST_URI"].split("?")[1]} params.each do |key, value| next unless value.present? hash = Rack::Utils.parse_query(value) # next unless hash.has_key?(param_name.to_s) encoded = hash.delete(param_name.to_s) decoded = Base64.decode64(encoded) if encoded env[key].gsub!("#{param_name}=#{encoded}", decoded) if decoded end end |