class Newznab::Api::SearchResults

Enumerable list for multiple {Newznab::Api::Item} results. Including pagination, and methods to navigate them

Attributes

function[R]
query[R]
raw_resp[R]

Public Class Methods

new(resp, function, query) click to toggle source

@param resp [Hash] Response hash from {Newznab::Api} @param function [Symbol] Function from {Newznab::Api::API_FUNCTIONS} @param query [Hash] Query parameters from search @since 0.1.0

Calls superclass method Newznab::Api::List::new
# File lib/newznab/api/list.rb, line 104
def initialize(resp, function, query)
  super(resp, query)

  @function = function
  @raw_resp = resp
  @query = query

  # Check for multiple/single results
  if resp['channel']['item'].kind_of? Array
    @cvos = resp['channel']['item'].collect { |o| Newznab::Api::Item.new(o) }
  elsif resp['channel']['item'].kind_of? Hash
    @cvos = [Newznab::Api::Item.new(resp['channel']['item'])]
  end

end

Public Instance Methods

next_page!() click to toggle source

## Moves search to the next offset results @since 0.1.0

# File lib/newznab/api/list.rb, line 123
def next_page!
  return nil if (self.offset + self.total_pages) >= self.total_count
  @query[:offset] = self.offset + self.limit
  self.update_ivals(Newznab::Api.get(api_function: self.function, **self.query))
end
prev_page!() click to toggle source

Moves search to the previous offset results @since 0.1.0

# File lib/newznab/api/list.rb, line 132
def prev_page!
  return nil if @offset == 0
  @query[:offset] = self.offset - self.limit
  self.update_ivals(Newznab::Api.get(api_function: self.function, **self.query))
end