mrjosh / rails-respond

Easy peasy json response for ruby on rails!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Easy peasy json response for ruby on rails!

License:MIT License


Languages

Language:Ruby 100.0%