Sha256: 44dce02bcda9f860bff513b9ee48d56e6d828e74fc1c81e0df981e0e684173d5

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

class Response
  # JSON response
  class JSON < self
    HEADERS = IceNine.deep_freeze('Content-Type' => 'application/json; charset=UTF-8')

    # Build JSON response with defaults
    #
    # @param [Object] body
    #   rack compatible body
    #
    # @return [Response::JSON]
    #
    # @example
    #
    #   # With defaults
    #   response = Response::JSON.build('{"foo":"bar"}')
    #   response.status  # => Response::Status::OK
    #   response.headers # => { 'Content-Type' => 'application/json; charset=UTF-8' }
    #   response.body    # => "{\"foo\":\"bar\"}"
    #
    #   # With overriding defaults
    #   response = Response::JSON.build("<foo><bar>Hello</bar></foo>") do |response|
    #     response.with_status(Response::Status::NOT_FOUND)
    #   end
    #
    #   response.status  # => Response::Status::NOT_FOUND
    #   response.headers # => { 'Content-Type' => 'application/json; charset=UTF-8' }
    #   response.body    # => "{\"foo\":\"bar\"}"
    #
    # @api public
    #
    def self.build(body)
      super(Status::OK, HEADERS, body)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
response-0.0.5 lib/response/json.rb
response-0.0.4 lib/response/json.rb