Sha256: fa42c1da861c73ae993e5ce2d0d1a11dd9c92b9be8377f137f8693d5c341b3f3

Contents?: true

Size: 1003 Bytes

Versions: 23

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

# This is an example of a handler that can load and generate www-url-encoded payloads.
# Note that if you use your API to pass nil values for attributes as a way to unset their
# values, this handler will not work (as there isn't necessarily a defined "null" value in
# this encoding (although you can probably define how to encode/decode it and use it as such)
# Use at your own risk.
module Praxis
  module Handlers
    class WWWForm
      def initialize
        require 'rack' # superfluous, but might as well be safe
      end

      # Parse a URL-encoded WWW form into structured data.
      def parse(entity)
        ::Rack::Utils.parse_nested_query(entity)
      end

      # Generate a URL-encoded WWW form from structured data. Not implemented since this format
      # is not very useful for a response body.
      def generate(structured_data)
        return nil if structured_data.nil?

        URI.encode_www_form(structured_data)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.40 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.39 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.38 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.37 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.36 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.35 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.34 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.33 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.32 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.31 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.30 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.29 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.28 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.27 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.26 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.25 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.24 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.23 lib/praxis/handlers/www_form.rb
praxis-2.0.pre.22 lib/praxis/handlers/www_form.rb