Module: HTTPX::Transcoder::JSON

Defined in:
lib/httpx/transcoder/json.rb

Defined Under Namespace

Classes: Encoder

Constant Summary collapse

JSON_REGEX =
%r{\bapplication/(?:vnd\.api\+)?json\b}i.freeze

Class Method Summary collapse

Class Method Details

.decode(response) ⇒ Object

Raises:



35
36
37
38
39
40
41
# File 'lib/httpx/transcoder/json.rb', line 35

def decode(response)
  content_type = response.content_type.mime_type

  raise HTTPX::Error, "invalid json mime type (#{content_type})" unless JSON_REGEX.match?(content_type)

  ::JSON.method(:parse)
end

.encode(json) ⇒ Object



31
32
33
# File 'lib/httpx/transcoder/json.rb', line 31

def encode(json)
  Encoder.new(json)
end