Project

respond

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
This package is provided to be used on rails framework and it gives clean methods to handle json response with specific predetermined messages.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.5
 Project Readme

Build Status Gem Version Total Downloads License Scrutinizer Code Quality

Rails Respond

This package is provided to be used on rails framework and it gives clean methods to handle json response with specific predetermined messages.

Requirement

  • Ruby ^1.9
  • Rails ^4.2

The package is in process.

Install

Add this line to your application's Gemfile:

gem 'respond'

And then execute:

$ bundle

Or install it yourself as:

$ gem install respond

Usage

You can use these methods in deffernt ways:

There are hot ones for quick usage, besides some provided to manage outputs on your own way

require library

require 'respond'

create respond instance

respond = Anetwork::Respond.new

Some are shown below:

When request succeeds and contains data to return as a result:

respond.succeed(data)

When deletion action succeeds:

respond.delete_succeeded

When updating succeeds:

respond.update_succeeded

When insertion succeeds:

respond.insert_succeeded

When deletion action fails:

respond.delete_faild

When updating fails:

respond.update_faild

when insertion fails:

respond.insert_faild

Not Found Error:

respond.not_found

When db connetion is refused:

respond.connection_refused

When parameters entered are wrong:

respond.wrong_parameters

When requested method is not allowed:

respond.method_not_allowed
respond.request_field_notfound

Validation errors:

respond.validation_errors(data)

###customization Set custom message for methods is like this:

respond.not_found('Leave it empty or enter your custom message here')

And you can do more:

respond.set_status_code(200).set_status_text('succeed').respond_with_message('Your custom message')

###render for render the json response , you must use the render method

render :json => result

the "result" varibule must be instnace of Respond object for example:

render :json => respond.not_found

License

The MIT License (MIT). Please see License File for more information.