Class: TorgMailruApi::Listing
- Inherits:
-
Object
- Object
- TorgMailruApi::Listing
- Includes:
- Enumerable, TorgMailruApi
- Defined in:
- lib/torg_mailru_api.rb
Constant Summary
Constants included from TorgMailruApi
API_VERSION, ENDPOINT_URI, VERSION
Instance Attribute Summary
Attributes included from Configuration
#access_token, #adapter, #cache, #logger, #proxy
Instance Method Summary collapse
- #each ⇒ Object
- #fetch_next_page ⇒ Object
-
#initialize(resource, params = nil) ⇒ Listing
constructor
A new instance of Listing.
Methods included from Configuration
Methods included from Connection
Methods included from APIRequest
#decamelize_hash_keys, #get, #listing
Methods included from APIMethods
#categories, #category, #category_children, #category_filter, #category_hits, #category_models, #category_newmodels, #category_offers, #category_parameters, #model, #model_offers, #model_outlets, #model_parameters, #offer, #region, #region_children, #region_suggest, #regions, #search, #seller, #seller_outlets, #seller_reviews, #vendor, #vendors
Constructor Details
#initialize(resource, params = nil) ⇒ Listing
Returns a new instance of Listing.
129 130 131 132 133 134 135 |
# File 'lib/torg_mailru_api.rb', line 129 def initialize resource, params=nil @resource = resource @params = params.nil? ? {} : params @params[:page] = @params.fetch(:page, 1) @items = [] @more = true end |
Instance Method Details
#each ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/torg_mailru_api.rb', line 137 def each return to_enum(:each) unless block_given? while true break unless fetch_next_page if @items.empty? yield @items.shift end end |
#fetch_next_page ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/torg_mailru_api.rb', line 145 def fetch_next_page if @more r = TorgMailruApi.get @resource, @params @more = (r.results_total-r.results_per_page*r.page) > 0 @items = r.listing @params[:page] += 1 true end end |