Sha256: b8043b2aeb88f1b567557b433db2262067e2b409400a02d4763edf8070a68c8e

Contents?: true

Size: 619 Bytes

Versions: 8

Compression:

Stored size: 619 Bytes

Contents

module Ctws
  module Response
    # responds with JSON and an HTTP status code (200 by default)
    # json_response(@todo, :created)
    def payload? object, status
      case status
      when :not_found, :unprocessable_entity, :unauthorized, :invalid_token
        self.errors_payload(object)
      else
        self.data_payload(object)
      end
    end
    
    def json_response(object = {}, status = :ok)
      render json: self.payload?(object, status), status: status
    end
    
    def data_payload(object)
      {data: object}
    end
    def errors_payload(object)
      {errors: object}
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ctws-0.1.12.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.11.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.10.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.9.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.8.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.7.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.6.alpha app/controllers/concerns/ctws/response.rb
ctws-0.1.5.alpha app/controllers/concerns/ctws/response.rb