Class: PagSeguro::SubscriptionSearch
- Inherits:
-
Object
- Object
- PagSeguro::SubscriptionSearch
- Defined in:
- lib/pagseguro/subscription/subscription_search.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Set the errors from the report request.
-
#options ⇒ Object
readonly
Set the report options.
-
#page ⇒ Object
readonly
Return the current page.
Instance Method Summary collapse
-
#created_at ⇒ Object
The report’s creation date.
-
#initialize(path, options) ⇒ SubscriptionSearch
constructor
A new instance of SubscriptionSearch.
-
#next_page! ⇒ Object
Move the page pointer to the next page.
-
#next_page? ⇒ Boolean
Detect if the report has a next page.
-
#previous_page! ⇒ Object
Move the page pointer to the previous page.
-
#previous_page? ⇒ Boolean
Detect if the report has a previous page.
-
#results ⇒ Object
How many results the report returned on the given page.
-
#subscriptions ⇒ Object
Return the list of subscriptions.
-
#total_pages ⇒ Object
How many pages the report returned.
-
#valid? ⇒ Boolean
Detect if the report request returned errors.
Constructor Details
#initialize(path, options) ⇒ SubscriptionSearch
Returns a new instance of SubscriptionSearch.
17 18 19 20 21 22 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 17 def initialize(path, ) @path = path @page = .delete(:page) || 0 @options = @errors = Errors.new end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Set the errors from the report request.
12 13 14 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 12 def errors @errors end |
#options ⇒ Object (readonly)
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.
9 10 11 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 9 def @options end |
#page ⇒ Object (readonly)
Return the current page.
15 16 17 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 15 def page @page end |
Instance Method Details
#created_at ⇒ Object
The report’s creation date.
38 39 40 41 42 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 38 def created_at xml do |xml| @created_at ||= Time.parse xml.css("preApprovalSearchResult > date").text end end |
#next_page! ⇒ Object
Move the page pointer to the next page.
69 70 71 72 73 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 69 def next_page! return unless next_page? @page += 1 clear! end |
#next_page? ⇒ Boolean
Detect if the report has a next page.
59 60 61 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 59 def next_page? page.zero? || page < total_pages end |
#previous_page! ⇒ Object
Move the page pointer to the previous page.
76 77 78 79 80 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 76 def previous_page! return unless previous_page? @page -= 1 clear! end |
#previous_page? ⇒ Boolean
Detect if the report has a previous page.
64 65 66 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 64 def previous_page? page > 1 end |
#results ⇒ Object
How many results the report returned on the given page.
45 46 47 48 49 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 45 def results xml do |xml| @results = xml.css("preApprovalSearchResult > resultsInThisPage").text.to_i end end |
#subscriptions ⇒ Object
Return the list of subscriptions. Each item will be wrapped in a PagSeguro::Subscription instance. Notice that subscriptions instantiated by the report won’t have all attributes. If you need additional attributes, do a PagSeguro::Subscription.find_by_code call. Remember that this will perform an additional HTTP request.
29 30 31 32 33 34 35 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 29 def subscriptions xml do |xml| xml.css("preApprovalSearchResult > preApprovals > preApproval").map do |node| Subscription.load_from_xml(node) end end end |
#total_pages ⇒ Object
How many pages the report returned.
52 53 54 55 56 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 52 def total_pages xml do |xml| @total_pages ||= xml.css("preApprovalSearchResult > totalPages").text.to_i end end |
#valid? ⇒ Boolean
Detect if the report request returned errors.
83 84 85 |
# File 'lib/pagseguro/subscription/subscription_search.rb', line 83 def valid? fetch { errors.empty? } end |