Sha256: 67b545ec3f1243f165067dfadddf6288e58092e7a7412c1d7450c196a6853b70

Contents?: true

Size: 814 Bytes

Versions: 23

Compression:

Stored size: 814 Bytes

Contents

# frozen_string_literal: true

require "forwardable"
require "uri"

module HTTPX::Transcoder
  module Form
    module_function

    class Encoder
      extend Forwardable

      def_delegator :@raw, :to_s

      def_delegator :@raw, :to_str

      def_delegator :@raw, :bytesize

      def initialize(form)
        @raw = form.each_with_object("".b) do |(key, val), buf|
          HTTPX::Transcoder.normalize_keys(key, val) do |k, v|
            buf << "&" unless buf.empty?
            buf << URI.encode_www_form_component(k)
            buf << "=#{URI.encode_www_form_component(v.to_s)}" unless v.nil?
          end
        end
      end

      def content_type
        "application/x-www-form-urlencoded"
      end
    end

    def encode(form)
      Encoder.new(form)
    end
  end
  register "form", Form
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
httpx-0.16.1 lib/httpx/transcoder/form.rb
httpx-0.16.0 lib/httpx/transcoder/form.rb
httpx-0.15.4 lib/httpx/transcoder/form.rb
httpx-0.15.3 lib/httpx/transcoder/form.rb
httpx-0.15.2 lib/httpx/transcoder/form.rb
httpx-0.15.1 lib/httpx/transcoder/form.rb
httpx-0.15.0 lib/httpx/transcoder/form.rb
httpx-0.14.5 lib/httpx/transcoder/form.rb
httpx-0.14.4 lib/httpx/transcoder/form.rb
httpx-0.14.3 lib/httpx/transcoder/form.rb
httpx-0.14.2 lib/httpx/transcoder/form.rb
httpx-0.14.1 lib/httpx/transcoder/form.rb
httpx-0.14.0 lib/httpx/transcoder/form.rb
httpx-0.13.2 lib/httpx/transcoder/form.rb
httpx-0.13.1 lib/httpx/transcoder/form.rb
httpx-0.13.0 lib/httpx/transcoder/form.rb
httpx-0.12.0 lib/httpx/transcoder/form.rb
httpx-0.11.3 lib/httpx/transcoder/form.rb
httpx-0.11.2 lib/httpx/transcoder/form.rb
httpx-0.11.1 lib/httpx/transcoder/form.rb