Permalink
Browse files

Added find_name to cash_book_proxy

  • Loading branch information...
1 parent 5e8e5f7 commit f3f4fa7fbf88804239d5d264bb60bdc9864d68ef @jespr committed Sep 22, 2011
Showing with 29 additions and 11 deletions.
  1. +29 −11 lib/economic/proxies/cash_book_proxy.rb
@@ -8,22 +8,40 @@ def find_by_name(name)
'name' => name
}
end
-
- handles = [response[:cash_book_handle]].flatten.reject(&:blank?)
- # Create partial Debtor entities
- handles.collect do |handle|
- cash_book = build
- cash_book.partial = true
- cash_book.persisted = true
- cash_book.handle = handle
- cash_book.number = handle[:number]
- cash_book
- end
+ cash_book = build
+ cash_book.partial = true
+ cash_book.persisted = true
+ cash_book.number = response[:number]
+ cash_book
+
end
def all
response = session.request entity_class.soap_action('GetAll')
+
+ handles = [response[:cash_book_handle]].flatten.reject(&:blank?)
+ cash_books = []
+ handles.each do |handle|
+ cash_books << find_name(handle[:number])
@koppen

koppen Oct 26, 2011

Why is this necessary? Can .all really safely assume that it's okay to send a myriad of extra SOAP requests. I'd assume this should be up to the user.

@jespr

jespr Oct 26, 2011

Owner

Guess I should move this out in to it´s own method called all_with_names or something like that. Im really having trouble with finding a way to get the api to return all of the cash books with name. It seems it only returns a list of the handles, which I really don't care about without a name..

Any suggestions on this?

@koppen

koppen Oct 26, 2011

The E-conomic API doesn't support returning any useful data in *_GetAll operations so I'm afraid we're stuck with working around it somehow.

Depending on your use case, your application should be able to do

cash_books = economic.cash_books.all
cash_books.each do |cash_book|
  puts cash_book.name if cash_book.number > 1000
end

and have Rconomic transparently handling getting the data from the API when necessary. I don't think it's up to Rconomic to fetch the name for each CashBook.

In any case, it makes little sense to only fetch the name. We should probably fetch all the data (ie Economic::Entity#get_data) if anything - not that there is anything other than a name right now in CashBook, but there might be in the future, and there definitely are in other entities.

If we do support this in the Rconomic API, it should probably be a toggleable option so you don't inadvertently send unnecessary requests.

+ end
+
+ cash_books
+ end
+
+ def find_name(id)
@koppen

koppen Oct 26, 2011

This should probably be get_name to reflect the SOAP method name

@jespr

jespr Oct 26, 2011

Owner

I agree

+ response = session.request entity_class.soap_action("GetName") do
+ soap.body = {
+ 'cashBookHandle' => {
+ 'Number' => id
+ }
+ }
+ end
+
+ cash_book = build
+ cash_book.number = id
+ cash_book.name = response
+ cash_book
end
end
end

0 comments on commit f3f4fa7

Please sign in to comment.