Module: HTTPX::Transcoder::JSON

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

Defined Under Namespace

Classes: Encoder

Constant Summary collapse

JSON_REGEX =
%r{
  \b
  application/
  # optional vendor specific type
  (?:
    # token as per https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
    [!#$%&'*+\-.^_`|~0-9a-z]+
    # literal plus sign
    \+
  )?
  json
  \b
}ix.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode(response) ⇒ Object

Raises:



46
47
48
49
50
51
52
# File 'lib/httpx/transcoder/json.rb', line 46

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)

  method(:json_load)
end

.encode(json) ⇒ Object



42
43
44
# File 'lib/httpx/transcoder/json.rb', line 42

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

Instance Method Details

#json_dump(*args) ⇒ Object



57
# File 'lib/httpx/transcoder/json.rb', line 57

def json_dump(*args); MultiJson.dump(*args); end

#json_load(*args) ⇒ Object



56
# File 'lib/httpx/transcoder/json.rb', line 56

def json_load(*args); MultiJson.load(*args); end