Sha256: b87b81c2ffb7516d3134f4bf5b222edc5d56cea58ef177712e78279288ae235e

Contents?: true

Size: 634 Bytes

Versions: 3

Compression:

Stored size: 634 Bytes

Contents

module Suricate
  class OutputDriver
    def render(content);    raise NotImplementedError; end
    def status(code);       raise NotImplementedError; end
    def content_type(type); raise NotImplementedError; end

    def api_success(data)
      api_response(200, data)
    end

    def api_error(status, message)
      data = { error: { message: message } }
      api_response(status, data)
    end

    def api_response(status, data)
      response = {
        status: status,
        data: data
      }
      json = JSON.fast_generate(response)

      status(status)
      content_type(:json)
      render(json)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
suricate-0.0.4 lib/suricate/output_driver.rb
suricate-0.0.3 lib/suricate/output_driver.rb
suricate-0.0.2 lib/suricate/output_driver.rb