Module: BooticClient::ResponseHandlers

Defined in:
lib/bootic_client/response_handlers.rb

Defined Under Namespace

Classes: IO, Set

Constant Summary collapse

JSON_MIME_EXP =
/^application\/json/.freeze
IMAGE_MIME_EXP =
/^image\//.freeze
CONTENT_TYPE =
'Content-Type'.freeze
Hal =
Proc.new do |resp, client|
  if resp.headers[CONTENT_TYPE] =~ JSON_MIME_EXP
    body = resp.body
    data = body.strip.empty? ? {} : ::JSON.parse(body)
    Entity.new(data, client)
  end
end
File =
Proc.new do |resp, client|
  if resp.headers[CONTENT_TYPE] =~ IMAGE_MIME_EXP
    fname = ::File.basename(resp.env[:url].to_s)
    IO.new(
      StringIO.new(resp.body),
      fname,
      resp.headers[CONTENT_TYPE]
    )
  end
end