Class: Payrix::Http::RequestParams
- Inherits:
-
Object
- Object
- Payrix::Http::RequestParams
- Defined in:
- lib/payrix/http/request_params.rb
Instance Method Summary collapse
- #expand ⇒ Object
- #expand=(expand) ⇒ Object
- #go_next_page ⇒ Object
-
#initialize(sort = '', expand = [], page = 1, totals = {}) ⇒ RequestParams
constructor
A new instance of RequestParams.
- #page ⇒ Object
- #page=(page) ⇒ Object
- #sort ⇒ Object
- #sort=(sort) ⇒ Object
-
#totals ⇒ Object
Retrieve the totals header string.
-
#totals=(totals) ⇒ Object
Set the totals hash.
Constructor Details
#initialize(sort = '', expand = [], page = 1, totals = {}) ⇒ RequestParams
Returns a new instance of RequestParams.
4 5 6 7 8 9 |
# File 'lib/payrix/http/request_params.rb', line 4 def initialize(sort = '', = [], page = 1, totals = {}) self.sort = sort self. = self.page = page self.totals = totals end |
Instance Method Details
#expand ⇒ Object
23 24 25 26 27 28 |
# File 'lib/payrix/http/request_params.rb', line 23 def @expand.map do |s| fields = s.split(',').map { |field| "[#{field.strip}]" } "expand#{fields.join}[]" end.join('&') end |
#expand=(expand) ⇒ Object
30 31 32 33 34 |
# File 'lib/payrix/http/request_params.rb', line 30 def () if .is_a?(Array) @expand = end end |
#go_next_page ⇒ Object
62 63 64 |
# File 'lib/payrix/http/request_params.rb', line 62 def go_next_page @page = @page.nil? || @page == 0 ? 1 : @page + 1 end |
#page ⇒ Object
54 55 56 |
# File 'lib/payrix/http/request_params.rb', line 54 def page @page.nil? || @page == 0 ? "" : "page[number]=#{@page}" end |
#page=(page) ⇒ Object
58 59 60 |
# File 'lib/payrix/http/request_params.rb', line 58 def page=(page) @page = page end |
#sort ⇒ Object
11 12 13 |
# File 'lib/payrix/http/request_params.rb', line 11 def sort @sort end |
#sort=(sort) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/payrix/http/request_params.rb', line 15 def sort=(sort) if sort.is_a?(Array) && sort.size == 2 @sort = "#{sort[0]}[sort]=#{sort[1]}" else @sort = sort end end |
#totals ⇒ Object
Retrieve the totals header string
37 38 39 40 41 42 43 44 45 |
# File 'lib/payrix/http/request_params.rb', line 37 def totals @totals.map do |action, values| if values.is_a?(Array) && !values.empty? values.map do |value| "#{action}[]=#{value}" end end end.join('&') end |
#totals=(totals) ⇒ Object
Set the totals hash
48 49 50 51 52 |
# File 'lib/payrix/http/request_params.rb', line 48 def totals=(totals) if totals.is_a?(Hash) @totals = totals end end |