Class: Twitter::FriendCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/friend_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

#collectionObject

Returns the value of attribute collection.



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

def collection
  @collection
end

#limitObject

Returns the value of attribute limit.



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

def limit
  @limit
end

#pageObject

Returns the value of attribute page.



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

def page
  @page
end

#relationship_typeObject

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

#fetchObject



46
47
48
# File 'lib/friend_collection.rb', line 46

def fetch
  self.page = send(relationship_type, {:cursor => first_or_next_cursor})
end

#fetch_allObject



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_cursorObject



22
23
24
# File 'lib/friend_collection.rb', line 22

def first_cursor
  -1
end

#first_or_next_cursorObject



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_cursorObject



26
27
28
# File 'lib/friend_collection.rb', line 26

def next_cursor
  page['next_cursor']
end

#no_more_cursorsObject



38
39
40
# File 'lib/friend_collection.rb', line 38

def no_more_cursors
  first_or_next_cursor == 0
end

#over_limit?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/friend_collection.rb', line 42

def over_limit?
  collection.length >= limit
end