lib/braintree/customer.rb in braintree-2.1.0 vs lib/braintree/customer.rb in braintree-2.2.0
- old
+ new
@@ -6,29 +6,25 @@
include BaseModule
attr_reader :addresses, :company, :created_at, :credit_cards, :email, :fax, :first_name, :id, :last_name,
:phone, :updated_at, :website, :custom_fields
- # Returns a ResourceCollection of all customers stored in the vault. Due to race conditions, this method
- # may not reliably return all customers stored in the vault.
+ # Returns a ResourceCollection of all customers stored in the vault.
#
- # page = Braintree::Customer.all
- # loop do
- # page.each do |customer|
- # puts "Customer #{customer.id} email is #{customer.email}"
- # end
- # break if page.last_page?
- # page = page.next_page
+ # customers = Braintree::Customer.all
+ # customers.each do |customer|
+ # puts "Customer #{customer.id} email is #{customer.email}"
# end
- def self.all(options = {})
- page_number = options[:page] || 1
- response = Http.get("/customers?page=#{page_number}")
+ def self.all
+ response = Http.post "/customers/advanced_search_ids"
+ ResourceCollection.new(response) { |ids| _fetch_customers(ids) }
+ end
+
+ def self._fetch_customers(ids)
+ response = Http.post "/customers/advanced_search", {:search => {:ids => ids}}
attributes = response[:customers]
- attributes[:items] = Util.extract_attribute_as_array(attributes, :customer).map do |customer_attributes|
- new customer_attributes
- end
- ResourceCollection.new(attributes) { |page_number| Customer.all(:page => page_number) }
+ Util.extract_attribute_as_array(attributes, :customer).map { |attrs| _new(attrs) }
end
# Creates a customer using the given +attributes+. If <tt>:id</tt> is not passed,
# the gateway will generate it.
#
@@ -98,16 +94,19 @@
return_object_or_raise(:transaction){ sale(customer_id, transaction_attributes) }
end
# Returns a ResourceCollection of transactions for the customer with the given +customer_id+.
def self.transactions(customer_id, options = {})
- page_number = options[:page] || 1
- response = Http.get "/customers/#{customer_id}/transactions?page=#{page_number}"
+ response = Http.post "/customers/#{customer_id}/transaction_ids"
+ ResourceCollection.new(response) { |ids| _fetch_transactions(customer_id, ids) }
+ end
+
+ def self._fetch_transactions(customer_id, ids)
+ response = Http.post "/customers/#{customer_id}/transactions", :search => {:ids => ids}
attributes = response[:credit_card_transactions]
- attributes[:items] = Util.extract_attribute_as_array(attributes, :transaction).map do |transaction_attributes|
+ Util.extract_attribute_as_array(attributes, :transaction).map do |transaction_attributes|
Transaction._new transaction_attributes
end
- ResourceCollection.new(attributes) { |page_number| Customer.transactions(customer_id, :page => page_number) }
end
def self.update(customer_id, attributes)
Util.verify_keys(_update_signature, attributes)
_do_update(:put, "/customers/#{customer_id}", :customer => attributes)