Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/walkersumida/senro
gem for RESTful API
https://github.com/walkersumida/senro
gem rails restful-api ruby
Last synced: 3 months ago
JSON representation
gem for RESTful API
- Host: GitHub
- URL: https://github.com/walkersumida/senro
- Owner: walkersumida
- License: mit
- Created: 2020-01-04T10:16:34.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-17T07:13:06.000Z (over 3 years ago)
- Last Synced: 2024-04-26T01:41:52.445Z (8 months ago)
- Topics: gem, rails, restful-api, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/senro
- Size: 91.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Senro
![Build Status](https://github.com/walkersumida/senro/workflows/build/badge.svg?branch=master)
[![Gem Version](https://badge.fury.io/rb/senro.svg)](https://badge.fury.io/rb/senro)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'senro'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install senro
## Usage
### in Rails
#### format sort```ruby
class ApplicationController < ActionController::Base # or ::API class
include Senro::Controller
before_action :query_params_formatter_sort
endpp params['sort']
# => { id: 'asc', name: 'desc' }
pp params['original_sort']
# => 'id,-name'# e.g. in ActiveRecord
@items = Item.all.order(params['sort'])# e.g. in Mongoid
@items = Item.all.order_by(params['sort'])
```#### format query
```ruby
class ApplicationController < ActionController::Base # or ::API class
include Senro::Controller
before_action :query_params_formatter_query
endpp params['q']
# => { 'query' => 'senro gem', 'status' => { 'type' => ['pr'], 'is' => ['open'], 'label' => ['bug', 'ready'] } }
pp params['original_q']
# => 'type:pr is:open label:bug label:ready senro gem'# e.g.
@items = Item.where(title: params['q']['query'],
type: params['q']['status']['type'],
status: params['q']['status']['is'])
```## Development
- Run `docker-compose up --build` to set up.
- Run `docker-compose run ruby bundle exec rake spec` to run the tests.
- You can also run `docker-compose run ruby bin/console` for an interactive prompt that will allow you to experiment.## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/senro. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Senro project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/senro/blob/master/CODE_OF_CONDUCT.md).