Class: Twitter::FriendCollection
- Inherits:
-
Object
- Object
- Twitter::FriendCollection
- Extended by:
- Forwardable
- Defined in:
- lib/friend_collection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#page ⇒ Object
Returns the value of attribute page.
-
#relationship_type ⇒ Object
Returns the value of attribute relationship_type.
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetch_all ⇒ Object
- #first_cursor ⇒ Object
- #first_or_next_cursor ⇒ Object
-
#initialize(client, relationship_type = :friends, limit = 500) ⇒ FriendCollection
constructor
A new instance of FriendCollection.
- #next_cursor ⇒ Object
- #no_more_cursors ⇒ Object
- #over_limit? ⇒ Boolean
Constructor Details
#initialize(client, relationship_type = :friends, limit = 500) ⇒ FriendCollection
Returns a new instance of FriendCollection.
15 16 17 18 19 20 |
# File 'lib/friend_collection.rb', line 15 def initialize(client, relationship_type = :friends, limit = 500) @client = client @relationship_type = relationship_type.to_sym @collection = [] @limit = limit end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/friend_collection.rb', line 7 def client @client end |
#collection ⇒ Object
Returns the value of attribute collection.
7 8 9 |
# File 'lib/friend_collection.rb', line 7 def collection @collection end |
#limit ⇒ Object
Returns the value of attribute limit.
7 8 9 |
# File 'lib/friend_collection.rb', line 7 def limit @limit end |
#page ⇒ Object
Returns the value of attribute page.
7 8 9 |
# File 'lib/friend_collection.rb', line 7 def page @page end |
#relationship_type ⇒ Object
Returns the value of attribute relationship_type.
7 8 9 |
# File 'lib/friend_collection.rb', line 7 def relationship_type @relationship_type end |
Instance Method Details
#fetch ⇒ Object
46 47 48 |
# File 'lib/friend_collection.rb', line 46 def fetch self.page = send(relationship_type, {:cursor => first_or_next_cursor}) end |
#fetch_all ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/friend_collection.rb', line 50 def fetch_all until no_more_cursors || over_limit? fetch collection << page['users'] end collection.flatten! end |
#first_cursor ⇒ Object
22 23 24 |
# File 'lib/friend_collection.rb', line 22 def first_cursor -1 end |
#first_or_next_cursor ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/friend_collection.rb', line 30 def first_or_next_cursor if page.nil? first_cursor else next_cursor end end |
#next_cursor ⇒ Object
26 27 28 |
# File 'lib/friend_collection.rb', line 26 def next_cursor page['next_cursor'] end |
#no_more_cursors ⇒ Object
38 39 40 |
# File 'lib/friend_collection.rb', line 38 def no_more_cursors first_or_next_cursor == 0 end |
#over_limit? ⇒ Boolean
42 43 44 |
# File 'lib/friend_collection.rb', line 42 def over_limit? collection.length >= limit end |