Sha256: 9962905199a8a8c130ae7c598eded3be9389e1034b93a55ade8027f8a957d230

Contents?: true

Size: 540 Bytes

Versions: 24

Compression:

Stored size: 540 Bytes

Contents

# frozen_string_literal: true

require "forwardable"
require "json"

module HTTPX::Transcoder
  module JSON
    module_function

    class Encoder
      extend Forwardable

      def_delegator :@raw, :to_s

      def_delegator :@raw, :bytesize

      def initialize(json)
        @raw = ::JSON.dump(json)
        @charset = @raw.encoding.name.downcase
      end

      def content_type
        "application/json; charset=#{@charset}"
      end
    end

    def encode(json)
      Encoder.new(json)
    end
  end
  register "json", JSON
end

Version data entries

24 entries across 24 versions & 1 rubygems

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