Class: TheCity::ApiList

Inherits:
Object
  • Object
show all
Defined in:
lib/api/api_list.rb

Overview

This class is the base class for all TheCity objects and is meant to be inherited.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



7
8
9
# File 'lib/api/api_list.rb', line 7

def current_page
  @current_page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



7
8
9
# File 'lib/api/api_list.rb', line 7

def per_page
  @per_page
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



7
8
9
# File 'lib/api/api_list.rb', line 7

def total_entries
  @total_entries
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



7
8
9
# File 'lib/api/api_list.rb', line 7

def total_pages
  @total_pages
end

Class Method Details

.load(options = {}) ⇒ Object



9
10
11
# File 'lib/api/api_list.rb', line 9

def self.load(options = {}) 
  self.new(options)
end

Instance Method Details

#next_pageUserList

Gets the next page of results.

Returns:

  • (UserList)

    or nil if there are no more pages.



23
24
25
26
# File 'lib/api/api_list.rb', line 23

def next_page
  return nil unless next_page?
  self.class.new( @options.merge({:page => @options[:page]+1}) )
end

#next_page!Object

Loads the next page of results and replaces self with the results.

Returns:

  • true on success or otherwise false.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/api/api_list.rb', line 31

def next_page!
  return false unless next_page?

  @options[:page] += 1
  @options[:reader] = @options[:reader].class.new(@options)
  @json_data = @options[:reader].load_feed

  @total_entries = @json_data['total_entries']
  @total_pages = @json_data['total_pages']
  @per_page = @json_data['per_page']
  @current_page = @json_data['current_page'] 

  return true
end

#next_page?Boolean

Checks if there is a next page.

Returns:

  • (Boolean)

    true for yes, false for no.



16
17
18
# File 'lib/api/api_list.rb', line 16

def next_page?
  @current_page < @total_pages
end