Class: Clicksign::JsonApi::QueryBuilder
- Inherits:
-
Object
- Object
- Clicksign::JsonApi::QueryBuilder
- Defined in:
- lib/clicksign/json_api/query_builder.rb
Instance Method Summary collapse
- #fields(**types) ⇒ Object
- #filter(**filters) ⇒ Object
- #include(*types) ⇒ Object
-
#initialize ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #order(field) ⇒ Object
- #page(number) ⇒ Object
- #per(size) ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
6 7 8 |
# File 'lib/clicksign/json_api/query_builder.rb', line 6 def initialize @params = {} end |
Instance Method Details
#fields(**types) ⇒ Object
36 37 38 39 |
# File 'lib/clicksign/json_api/query_builder.rb', line 36 def fields(**types) types.each { |type, list| @params["fields[#{type}]"] = Array(list).join(',') } self end |
#filter(**filters) ⇒ Object
10 11 12 13 |
# File 'lib/clicksign/json_api/query_builder.rb', line 10 def filter(**filters) filters.each { |k, v| @params["filter[#{k}]"] = v } self end |
#include(*types) ⇒ Object
15 16 17 18 19 |
# File 'lib/clicksign/json_api/query_builder.rb', line 15 def include(*types) existing = @params['include']&.split(',') || [] @params['include'] = (existing + types.map(&:to_s)).uniq.join(',') self end |
#order(field) ⇒ Object
21 22 23 24 |
# File 'lib/clicksign/json_api/query_builder.rb', line 21 def order(field) @params['sort'] = field.to_s self end |
#page(number) ⇒ Object
26 27 28 29 |
# File 'lib/clicksign/json_api/query_builder.rb', line 26 def page(number) @params['page[number]'] = number self end |
#per(size) ⇒ Object
31 32 33 34 |
# File 'lib/clicksign/json_api/query_builder.rb', line 31 def per(size) @params['page[size]'] = size self end |
#to_params ⇒ Object
41 42 43 |
# File 'lib/clicksign/json_api/query_builder.rb', line 41 def to_params @params.dup end |