Method: Etapper::JournalEntryCollection#initialize
- Defined in:
- lib/etapper/classes/journal_entry_collection.rb
#initialize(account = nil, options = {}) ⇒ JournalEntryCollection
Returns a new collection of journal entries. Requires an Etapper::Account object as the first parameter. Also allows options (:type, :count, etc) to be passed to the journal entry request.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/etapper/classes/journal_entry_collection.rb', line 10 def initialize(account=nil, ={}) raise RequiredFieldError, "An account is required!" unless @account = account # Set up our request @request = API::PagedJournalEntriesRequest.new @request.accountRef = account.ref @request.count = [:count] || 100 # Default to the largest request we can make @request.startDate = [:startDate].to_date if [:startDate] @request.endDate = [:endDate].to_date if [:endDate] @request.baseQuery = [:baseQuery] @request.start = [:start] if [:type] @request.types = [JournalEntry::TYPES[[:type]]] elsif [:types] @request.types = [:types].collect {|t| JournalEntry::TYPES[t]} end # Make the request @response = Etapper.client.getJournalEntries(@request) @total = @response.total # Do we have all the records? @records = @response.data enum = Proc.new do |yielder| counter = 0 while counter < @total if counter == @records.length # Retrieve more records @request.start = counter more = Etapper.client.getJournalEntries(@request) @records += more.data end record = @records[counter] etapper_class = Etapper.etapper_class(record.class) yielder.yield etapper_class.new(record) counter += 1 end end super(&enum) end |