lib/moip2/order_api.rb in moip2-0.1.4 vs lib/moip2/order_api.rb in moip2-1.0.0
- old
+ new
@@ -1,9 +1,7 @@
module Moip2
-
class OrderApi
-
attr_reader :client
def initialize(client)
@client = client
end
@@ -18,8 +16,25 @@
def show(id)
Resource::Order.new client, client.get("#{base_path}/#{id}")
end
- end
+ def find_all(limit: nil, offset: nil, filters: nil)
+ encoded_filters = Moip2::Util::FiltersEncoder.encode(filters)
+ # `URI.encode...` will accept nil params, but they will pollute the URI
+ params = {
+ limit: limit,
+ offset: offset,
+ filters: encoded_filters,
+ }.reject { |_, value| value.nil? }
+
+ query_string = URI.encode_www_form(params)
+ path = "#{base_path}?#{query_string}"
+ response = client.get(path)
+
+ # We need to transform raw JSON in Order objects
+ response.orders.collect! { |order| Resource::Order.new client, order }
+ Resource::Order.new client, response
+ end
+ end
end