Sha256: ae9c66666c8dd7f382e8a0b0cb80a237cb0a8d9dae8c3ea229ab3df12448cb1d

Contents?: true

Size: 620 Bytes

Versions: 27

Compression:

Stored size: 620 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_str

      def_delegator :@raw, :to_s

      def_delegator :@raw, :bytesize

      def_delegator :@raw, :force_encoding

      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

27 entries across 27 versions & 1 rubygems

Version Path
httpx-0.9.0 lib/httpx/transcoder/json.rb
httpx-0.8.2 lib/httpx/transcoder/json.rb
httpx-0.8.1 lib/httpx/transcoder/json.rb
httpx-0.8.0 lib/httpx/transcoder/json.rb
httpx-0.7.0 lib/httpx/transcoder/json.rb
httpx-0.6.7 lib/httpx/transcoder/json.rb
httpx-0.6.6 lib/httpx/transcoder/json.rb
httpx-0.6.5 lib/httpx/transcoder/json.rb
httpx-0.6.4 lib/httpx/transcoder/json.rb
httpx-0.6.3 lib/httpx/transcoder/json.rb
httpx-0.6.2 lib/httpx/transcoder/json.rb
httpx-0.6.1 lib/httpx/transcoder/json.rb
httpx-0.6.0 lib/httpx/transcoder/json.rb
httpx-0.5.1 lib/httpx/transcoder/json.rb
httpx-0.5.0 lib/httpx/transcoder/json.rb
httpx-0.4.1 lib/httpx/transcoder/json.rb
httpx-0.4.0 lib/httpx/transcoder/json.rb
httpx-0.3.1 lib/httpx/transcoder/json.rb
httpx-0.3.0 lib/httpx/transcoder/json.rb
httpx-0.2.1 lib/httpx/transcoder/json.rb