class PagSeguro::Search
Attributes
Set the errors from the report request.
Set the report options.
# per_page
: the page size. # starts_at
: the report’s starting date. Can’t be older than 6 months. # ends_at
: the report’s ending date. Can’t be greater than 30 days from the starting date.
Return the current page.
Public Class Methods
# File lib/pagseguro/transaction/search.rb, line 17 def initialize(path, options, page = 0) @path = path @options = options @page = page end
Public Instance Methods
The report’s creation date.
# File lib/pagseguro/transaction/search.rb, line 37 def created_at xml do |xml| @created_at ||= Time.parse xml.css("transactionSearchResult > date").text end end
Move the page pointer to the next page.
# File lib/pagseguro/transaction/search.rb, line 68 def next_page! return unless next_page? @page += 1 clear! end
Detect if the report has a next page.
# File lib/pagseguro/transaction/search.rb, line 58 def next_page? page.zero? || page < total_pages end
Move the page pointer to the previous page.
# File lib/pagseguro/transaction/search.rb, line 75 def previous_page! return unless previous_page? @page -= 1 clear! end
Detect if the report has a previous page.
# File lib/pagseguro/transaction/search.rb, line 63 def previous_page? page > 1 end
How many results the report returned on the given page.
# File lib/pagseguro/transaction/search.rb, line 44 def results xml do |xml| @results ||= xml.css("transactionSearchResult > resultsInThisPage").text.to_i end end
How many pages the report returned.
# File lib/pagseguro/transaction/search.rb, line 51 def total_pages xml do |xml| @total_pages ||= xml.css("transactionSearchResult > totalPages").text.to_i end end
Return the list of transactions. Each item will be wrapped in a PagSeguro::Transaction
instance. Notice that transactions instantiated by the report won’t have all attributes. If you need additional attributes, do a PagSeguro::Transaction.find_by_notification_code
call. Remember that this will perform an additional HTTP request.
# File lib/pagseguro/transaction/search.rb, line 28 def transactions xml do |xml| xml.css("transactionSearchResult > transactions > transaction").map do |node| Transaction.load_from_xml(node) end end end
Detect if the report request returned errors.
# File lib/pagseguro/transaction/search.rb, line 82 def valid? fetch { errors.empty? } end
Private Instance Methods
The default PagSeguro
API version
# File lib/pagseguro/transaction/search.rb, line 92 def api_version 'v3' end
# File lib/pagseguro/transaction/search.rb, line 104 def clear! @fetched = false end
# File lib/pagseguro/transaction/search.rb, line 108 def fetch(&block) unless fetched? perform_request_and_serialize fetched! end instance_eval(&block) end
# File lib/pagseguro/transaction/search.rb, line 100 def fetched! @fetched = true end
# File lib/pagseguro/transaction/search.rb, line 96 def fetched? @fetched end
# File lib/pagseguro/transaction/search.rb, line 87 def perform_request_and_serialize raise NotImplementedError.new("'.perform_request_and_serialize' must be implemented in specific search class") end
# File lib/pagseguro/transaction/search.rb, line 117 def xml(&block) valid? && block.call(@response.data) end