Module: Paymill::Restful::All

Included in:
Base
Defined in:
lib/paymill/restful/methods.rb

Instance Method Summary collapse

Instance Method Details

#all(arguments = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/paymill/restful/methods.rb', line 5

def all( arguments = {} )
  unless arguments.empty?
    order = "#{arguments[:order].map{ |e| "order=#{e.id2name}" }.join( '&' )}" if arguments[:order]
    filters = arguments[:filters].map{ |hash| hash.map{ |key, value| "#{key.id2name}=#{value.gsub( ' ', '+' ) }" }.join( '&' ) } if arguments[:filters]
    count = "count=#{arguments[:count]}" if arguments[:count]
    offset = "offset=#{arguments[:offset]}" if arguments[:offset]
    arguments = "?#{[order, filters, offset, count].reject { |e| e.nil? }.join( '&' )}"
  else
    arguments = ''
  end

  response = Paymill.request( Http.all( Restful.demodulize_and_tableize( name ), arguments ) )
  enrich_array_with_data_count( response['data'].map!{ |element| new( element ) }, response['data_count'] )
end