api_helper 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Appraisals +6 -0
- data/README.md +23 -27
- data/bin/setup +1 -0
- data/gemfiles/rails_5.0.0.gemfile +8 -0
- data/lib/api_helper/fieldsettable.rb +2 -1
- data/lib/api_helper/filterable.rb +2 -1
- data/lib/api_helper/includable.rb +2 -1
- data/lib/api_helper/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1895625d870d6629c579f3f165f1f37090dc4d12
|
4
|
+
data.tar.gz: b1fc9a045cebe92869ff7a4f666b3e813c5c7bb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c908f21b13a0f04dc0531cfe8fe97d2fd93182d1c119139caeb56387f6c905e4d516c40668ad5a1f2ba1ff05d580faa389eb1afa12a16774110136ef3b7478ac
|
7
|
+
data.tar.gz: 8800b5d99bd5e252474bdefb57792e6274eba29819da938c8931dde286e4ecea7a0fcd618c6af44f6f9ca60f658ea7f356fb6d8a38d27a26713491e188b30821
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -1,48 +1,44 @@
|
|
1
|
-
# APIHelper [![Gem Version](https://badge.fury.io/rb/api_helper.svg)](http://badge.fury.io/rb/api_helper) [![Build Status](https://travis-ci.org/Neson/api_helper.svg?branch=master)](https://travis-ci.org/Neson/api_helper) [![Docs Status](https://inch-ci.org/github/Neson/api_helper.svg?branch=master)](https://inch-ci.org/github/Neson/api_helper)
|
1
|
+
# APIHelper [![Gem Version](https://badge.fury.io/rb/api_helper.svg)](http://badge.fury.io/rb/api_helper) [![Build Status](https://travis-ci.org/Neson/api_helper.svg?branch=master)](https://travis-ci.org/Neson/api_helper) [![Coverage Status](https://coveralls.io/repos/Neson/api_helper/badge.svg?branch=master)](https://coveralls.io/r/Neson/api_helper?branch=master) [![Docs Status](https://inch-ci.org/github/Neson/api_helper.svg?branch=master)](https://inch-ci.org/github/Neson/api_helper)
|
2
2
|
|
3
3
|
Helpers for creating standard RESTful API for Rails or Grape with Active Record.
|
4
4
|
|
5
5
|
|
6
|
-
##
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'api_helper'
|
12
|
-
```
|
6
|
+
## API Standards
|
13
7
|
|
14
|
-
|
8
|
+
<dl>
|
15
9
|
|
16
|
-
|
10
|
+
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Fieldsettable">Fieldsettable</a></dt>
|
11
|
+
<dd>Let clients choose the fields they wanted to be returned with the <code>fields</code> query parameter, making their API calls optimizable to gain efficiency and speed.</dd>
|
17
12
|
|
18
|
-
|
13
|
+
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Includable">Includable</a></dt>
|
14
|
+
<dd>Clients can use the <code>include</code> query parameter to enable inclusion of related items - for instance, get the author's data along with a post.</dd>
|
19
15
|
|
20
|
-
|
16
|
+
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Paginatable">Paginatable</a></dt>
|
17
|
+
<dd>Paginate the results of a resource collection, client can get a specific page with the <code>page</code> query parameter and set a custom page size with the "per_page" query parameter.</dd>
|
21
18
|
|
19
|
+
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Sortable">Sortable</a></dt>
|
20
|
+
<dd>Client can set custom sorting with the <code>sort</code> query parameter while getting a resource collection.</dd>
|
22
21
|
|
23
|
-
|
22
|
+
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Filterable">Filterable</a></dt>
|
23
|
+
<dd>Enables clients to filter through a resource collection with their fields with the <code>filter</code> query parameter.</dd>
|
24
24
|
|
25
|
-
<
|
25
|
+
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Multigettable">Multigettable</a></dt>
|
26
|
+
<dd>Let Client execute operations on multiple resources with a single request.</dd>
|
26
27
|
|
27
|
-
|
28
|
-
<dd>Let clients choose the fields they wanted to be returned with the "fields" query parameter, making their API calls optimizable to gain efficiency and speed.</dd>
|
28
|
+
</dl>
|
29
29
|
|
30
|
-
<dt><a href="http://www.rubydoc.info/github/Neson/api_helper/master/APIHelper/Includable" target="_blank">Includable</a></dt>
|
31
|
-
<dd>Clients can use the "include" query parameter to enable inclusion of related items - for instance, get the author's data along with a post.</dd>
|
32
30
|
|
33
|
-
|
34
|
-
<dd>Paginate the results of a resource collection, client can get a specific page with the "page" query parameter and set a custom page size with the "per_page" query parameter.</dd>
|
31
|
+
## Installation
|
35
32
|
|
36
|
-
|
37
|
-
<dd>Client can set custom sorting with the "sort" query parameter while getting a resource collection.</dd>
|
33
|
+
Add this line to your application's Gemfile:
|
38
34
|
|
39
|
-
|
40
|
-
|
35
|
+
```ruby
|
36
|
+
gem 'api_helper'
|
37
|
+
```
|
41
38
|
|
42
|
-
|
43
|
-
<dd>Let Client execute operations on multiple resources with a single request.</dd>
|
39
|
+
And then execute:
|
44
40
|
|
45
|
-
|
41
|
+
$ bundle
|
46
42
|
|
47
43
|
|
48
44
|
## Usage
|
data/bin/setup
CHANGED
@@ -169,7 +169,8 @@ module APIHelper::Fieldsettable
|
|
169
169
|
@fieldset ||= ActiveSupport::HashWithIndifferentAccess.new
|
170
170
|
|
171
171
|
# put the fields in place
|
172
|
-
if params[:fields].is_a?(Hash)
|
172
|
+
if params[:fields].is_a?(Hash) ||
|
173
|
+
defined?(Rails) && Rails.version.to_i >= 5 && params[:fields].is_a?(ActionController::Parameters)
|
173
174
|
# get the specific resource fields from fields hash
|
174
175
|
@fieldset[resource] = params[:fields][resource] || params[:fields][resource]
|
175
176
|
elsif default
|
@@ -73,7 +73,8 @@ module APIHelper::Filterable
|
|
73
73
|
#
|
74
74
|
def filter(resource, filterable_fields: [])
|
75
75
|
# parse the request parameter
|
76
|
-
if params[:filter].is_a?(Hash)
|
76
|
+
if params[:filter].is_a?(Hash) ||
|
77
|
+
defined?(Rails) && Rails.version.to_i >= 5 && params[:filter].is_a?(ActionController::Parameters)
|
77
78
|
@filter = params[:filter]
|
78
79
|
filterable_fields = filterable_fields.map(&:to_s)
|
79
80
|
|
@@ -192,7 +192,8 @@ module APIHelper::Includable
|
|
192
192
|
@inclusion_specified ||= ActiveSupport::HashWithIndifferentAccess.new
|
193
193
|
|
194
194
|
# put the fields in place
|
195
|
-
if params[:include].is_a?(Hash)
|
195
|
+
if params[:include].is_a?(Hash) ||
|
196
|
+
defined?(Rails) && Rails.version.to_i >= 5 && params[:include].is_a?(ActionController::Parameters)
|
196
197
|
# get the specific resource inclusion fields from the "include" hash
|
197
198
|
@inclusion[resource] = params[:include][resource]
|
198
199
|
@inclusion_specified[resource] = true if params[:include][resource].present?
|
data/lib/api_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- gemfiles/rails_4.1.0.gemfile
|
175
175
|
- gemfiles/rails_4.1.8.gemfile
|
176
176
|
- gemfiles/rails_4.2.0.gemfile
|
177
|
+
- gemfiles/rails_5.0.0.gemfile
|
177
178
|
- lib/api_helper.rb
|
178
179
|
- lib/api_helper/fieldsettable.rb
|
179
180
|
- lib/api_helper/filterable.rb
|
@@ -201,9 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
202
|
version: '0'
|
202
203
|
requirements: []
|
203
204
|
rubyforge_project:
|
204
|
-
rubygems_version: 2.
|
205
|
+
rubygems_version: 2.5.1
|
205
206
|
signing_key:
|
206
207
|
specification_version: 4
|
207
208
|
summary: Helpers for creating standard web API.
|
208
209
|
test_files: []
|
209
|
-
has_rdoc:
|