Class: Telapi::ResourceCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/telapi/resource_collection.rb

Overview

This class wraps Resource objects and provides Enumerable functionality.

Note that TelAPI collections are automatically separated into pages of results, see www.telapi.com/docs/api/rest/overview/response/.

Currently this container class does not automatically handle the retrieving of a previous/next page of results. However, all of the Resource classes that provide a list method allow you to specify the current page and size.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, collection_node_name, resource_type) ⇒ ResourceCollection

Returns a new instance of ResourceCollection.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/telapi/resource_collection.rb', line 18

def initialize(attributes, collection_node_name, resource_type)
  @page      = attributes['page']
  @num_pages = attributes['num_pages']
  @page_size = attributes['page_size']
  @total     = attributes['total']
  @start     = attributes['start']
  @end       = attributes['end']
  @items     = []

  attributes[collection_node_name].each do |item|
    @items << resource_type.send(:new, item)
  end if attributes[collection_node_name]
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def end
  @end
end

#itemsObject (readonly)

Returns the value of attribute items.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def items
  @items
end

#num_pagesObject (readonly)

Returns the value of attribute num_pages.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def num_pages
  @num_pages
end

#pageObject (readonly)

Returns the value of attribute page.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def page
  @page
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def page_size
  @page_size
end

#startObject (readonly)

Returns the value of attribute start.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def start
  @start
end

#totalObject (readonly)

Returns the value of attribute total.



16
17
18
# File 'lib/telapi/resource_collection.rb', line 16

def total
  @total
end

Instance Method Details

#eachObject



34
35
36
# File 'lib/telapi/resource_collection.rb', line 34

def each
  @items.each { |i| yield i }
end