lib/braintree/subscription.rb in braintree-2.1.0 vs lib/braintree/subscription.rb in braintree-2.2.0
- old
+ new
@@ -95,17 +95,22 @@
# Subscription.search do |s|
# s.plan_id.starts_with "abc"
# s.days_past_due.is "30"
# s.status.in [Subscription::Status::PastDue]
# end
- def self.search(page=1, &block)
+ def self.search(&block)
search = SubscriptionSearch.new
- block.call(search)
+ block.call(search) if block
- response = Http.post "/subscriptions/advanced_search?page=#{page}", {:search => search.to_hash}
+ response = Http.post "/subscriptions/advanced_search_ids", {:search => search.to_hash}
+ ResourceCollection.new(response) { |ids| _fetch_subscriptions(search, ids) }
+ end
+
+ def self._fetch_subscriptions(search, ids)
+ search.ids.in ids
+ response = Http.post "/subscriptions/advanced_search", {:search => search.to_hash}
attributes = response[:subscriptions]
- attributes[:items] = Util.extract_attribute_as_array(attributes, :subscription).map { |attrs| _new(attrs) }
- ResourceCollection.new(attributes) { |page_number| Subscription.search(page_number, &block) }
+ Util.extract_attribute_as_array(attributes, :subscription).map { |attrs| _new(attrs) }
end
def self.update(subscription_id, attributes)
Util.verify_keys(_update_signature, attributes)
response = Http.put "/subscriptions/#{subscription_id}", :subscription => attributes