lib/gooddata/helpers/global_helpers_params.rb
def decode_params(params, options = {})
        key = ENCODED_PARAMS_KEY.to_s
        hidden_key = ENCODED_HIDDEN_PARAMS_KEY.to_s
        data_params = params[key] || '{}'
        hidden_data_params = if params.key?(hidden_key) && params[hidden_key].nil?
                               "{\"#{hidden_key}\" : null}"
                             elsif params.key?(hidden_key)
                               params[hidden_key]
                             else
                               '{}'
                             end

        reference_values = []
        # Replace reference parameters by the actual values. Use backslash to escape a reference parameter, e.g: \${not_a_param},
        # the ${not_a_param} will not be replaced
        if options[:resolve_reference_params]
          data_params, reference_values = resolve_reference_params(data_params, params)
          hidden_data_params, = resolve_reference_params(hidden_data_params, params)
        end

        begin
          parsed_data_params = data_params.is_a?(Hash) ? data_params : JSON.parse(data_params)
        rescue JSON::ParserError => exception
          reason = exception.message
          reference_values.each { |secret_value| reason.gsub!("\"#{secret_value}\"", '"***"') }
          raise exception.class, "Error reading json from '#{key}', reason: #{reason}"
        end

        begin
          parsed_hidden_data_params = hidden_data_params.is_a?(Hash) ? hidden_data_params : JSON.parse(hidden_data_params)
        rescue JSON::ParserError => exception
          raise exception.class, "Error reading json from '#{hidden_key}'"
        end

        # Add the nil on ENCODED_HIDDEN_PARAMS_KEY
        # if the data was retrieved from API You will not have the actual values so encode -> decode is not losless. The nil on the key prevents the server from deleting the key
        parsed_hidden_data_params[ENCODED_HIDDEN_PARAMS_KEY] = nil unless parsed_hidden_data_params.empty?

        params.delete(key)
        params.delete(hidden_key)
        params = params.deep_merge(parsed_data_params).deep_merge(parsed_hidden_data_params)

        if options[:convert_pipe_delimited_params]
          convert_pipe_delimited_params = lambda do |args|
            args = args.select { |k, _| k.include? "|" }
            lines = args.keys.map do |k|
              hash = {}
              last_a = nil
              last_e = nil
              k.split("|").reduce(hash) do |a, e|
                last_a = a
                last_e = e
                a[e] = {}
              end
              last_a[last_e] = args[k]
              hash
            end

            lines.reduce({}) do |a, e|
              a.deep_merge(e)
            end
          end

          pipe_delimited_params = convert_pipe_delimited_params.call(params)
          params.delete_if do |k, _|
            k.include?('|')
          end
          params = params.deep_merge(pipe_delimited_params)
        end

        params
      end
# Decodes params as they came from the platform.
# @params Parameter hash need to be decoded
# @option options [Boolean] :resolve_reference_params Resolve reference parameters in gd_encoded_params or not
# @return [Hash] Decoded parameters
Decodes params as they came from the platform.
Decodes params as they came from the platform .
def decode_params(params, options = {})
        key = ENCODED_PARAMS_KEY.to_s
        hidden_key = ENCODED_HIDDEN_PARAMS_KEY.to_s
        data_params = params[key] || '{}'
        hidden_data_params = if params.key?(hidden_key) && params[hidden_key].nil?
                               "{\"#{hidden_key}\" : null}"
                             elsif params.key?(hidden_key)
                               params[hidden_key]
                             else
                               '{}'
                             end
        reference_values = []
        if options[:resolve_reference_params]
          data_params, reference_values = resolve_reference_params(data_params, params)
          hidden_data_params, = resolve_reference_params(hidden_data_params, params)
        end
        begin
          parsed_data_params = data_params.is_a?(Hash) ? data_params : JSON.parse(data_params)
        rescue JSON::ParserError => exception
          reason = exception.message
          reference_values.each { |secret_value| reason.gsub!("\"#{secret_value}\"", '"***"') }
          raise exception.class, "Error reading json from '#{key}', reason: #{reason}"
        end
        begin
          parsed_hidden_data_params = hidden_data_params.is_a?(Hash) ? hidden_data_params : JSON.parse(hidden_data_params)
        rescue JSON::ParserError => exception
          raise exception.class, "Error reading json from '#{hidden_key}'"
        end
        parsed_hidden_data_params[ENCODED_HIDDEN_PARAMS_KEY] = nil unless parsed_hidden_data_params.empty?
        params.delete(key)
        params.delete(hidden_key)
        params = params.deep_merge(parsed_data_params).deep_merge(parsed_hidden_data_params)
        if options[:convert_pipe_delimited_params]
          convert_pipe_delimited_params = lambda do |args|
            args = args.select { |k, _| k.include? "|" }
            lines = args.keys.map do |k|
              hash = {}
              last_a = nil
              last_e = nil
              k.split("|").reduce(hash) do |a, e|
                last_a = a
                last_e = e
                a[e] = {}
              end
              last_a[last_e] = args[k]
              hash
            end
            lines.reduce({}) do |a, e|
              a.deep_merge(e)
            end
          end
          pipe_delimited_params = convert_pipe_delimited_params.call(params)
          params.delete_if do |k, _|
            k.include?('|')
          end
          params = params.deep_merge(pipe_delimited_params)
        end
        params
      end
def decode_params ( params , options = { } ) key = ENCODED_PARAMS_KEY . to_s hidden_key = ENCODED_HIDDEN_PARAMS_KEY . to_s data_params = params [ key ] || '{}' hidden_data_params = if params . key? ( hidden_key ) && params [ hidden_key ] . nil? "{\"#{hidden_key}\" : null}" elsif params . key? ( hidden_key ) params [ hidden_key ] else '{}' end reference_values = [ ] if options [ :resolve_reference_params ] data_params , reference_values = resolve_reference_params ( data_params , params ) hidden_data_params , = resolve_reference_params ( hidden_data_params , params ) end begin parsed_data_params = data_params . is_a? ( Hash ) ? data_params : JSON . parse ( data_params ) rescue JSON :: ParserError => exception reason = exception . message reference_values . each { | secret_value | reason . gsub! ( "\"#{secret_value}\"" , '"***"' ) } raise exception . class , "Error reading json from '#{key}', reason: #{reason}" end begin parsed_hidden_data_params = hidden_data_params . is_a? ( Hash ) ? hidden_data_params : JSON . parse ( hidden_data_params ) rescue JSON :: ParserError => exception raise exception . class , "Error reading json from '#{hidden_key}'" end parsed_hidden_data_params [ ENCODED_HIDDEN_PARAMS_KEY ] = nil unless parsed_hidden_data_params . empty? params . delete ( key ) params . delete ( hidden_key ) params = params . deep_merge ( parsed_data_params ) . deep_merge ( parsed_hidden_data_params ) if options [ :convert_pipe_delimited_params ] convert_pipe_delimited_params = lambda do | args | args = args . select { | k , _ | k . include? "|" } lines = args . keys . map do | k | hash = { } last_a = nil last_e = nil k . split ( "|" ) . reduce ( hash ) do | a , e | last_a = a last_e = e a [ e ] = { } end last_a [ last_e ] = args [ k ] hash end lines . reduce ( { } ) do | a , e | a . deep_merge ( e ) end end pipe_delimited_params = convert_pipe_delimited_params . call ( params ) params . delete_if do | k , _ | k . include? ( '|' ) end params = params . deep_merge ( pipe_delimited_params ) end params end
Decodes params as they came from the platform.
Decodes params as they came from the platform .
# Replace reference parameters by the actual values. Use backslash to escape a reference parameter, e.g: \${not_a_param}, # the ${not_a_param} will not be replaced # Add the nil on ENCODED_HIDDEN_PARAMS_KEY # if the data was retrieved from API You will not have the actual values so encode -> decode is not losless. The nil on the key prevents the server from deleting the key
None
Hash
params
options
:resolve_reference_params Resolve reference parameters in gd_encoded_params or not
: resolve_reference_params Resolve reference parameters in gd_encoded_params or not
params
Parameter hash need to be decoded
Parameter hash need to be decoded