Class: Twitter::Cache::Wrapper
- Inherits:
-
Object
- Object
- Twitter::Cache::Wrapper
show all
- Includes:
- Helpers
- Defined in:
- lib/twitter/cache/wrapper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#cache, #config, #friends_cache, #user_cache
Constructor Details
#initialize(twitter) ⇒ Wrapper
Returns a new instance of Wrapper.
7
8
9
|
# File 'lib/twitter/cache/wrapper.rb', line 7
def initialize()
=
end
|
Instance Attribute Details
Returns the value of attribute twitter.
5
6
7
|
# File 'lib/twitter/cache/wrapper.rb', line 5
def
end
|
Instance Method Details
#current_id ⇒ Object
46
47
48
|
# File 'lib/twitter/cache/wrapper.rb', line 46
def current_id
current_user.id
end
|
#current_user ⇒ Object
42
43
44
|
# File 'lib/twitter/cache/wrapper.rb', line 42
def current_user
@current_user ||= .current_user
end
|
#friend_ids(id = current_id) ⇒ Object
17
18
19
20
21
|
# File 'lib/twitter/cache/wrapper.rb', line 17
def friend_ids(id = current_id)
friends_cache.get(id, ttl: config.ttl) do
.friend_ids(id).to_a
end
end
|
#friends(id = current_id, per: 100, page: 0) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/twitter/cache/wrapper.rb', line 23
def friends(id = current_id, per: 100, page: 0)
per = per.to_i
ids = friend_ids(id)
case page
when :rand, :random, 'rand', 'random'
users(ids.sample(per))
else
start = per * page.to_i
users(ids[start, per])
end
end
|
#user(id = current_id) ⇒ Object
11
12
13
14
15
|
# File 'lib/twitter/cache/wrapper.rb', line 11
def user(id = current_id)
user_cache.get(id, ttl: config.ttl) do
config.convert_user(.user(id))
end
end
|
#users(ids) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/twitter/cache/wrapper.rb', line 35
def users(ids)
known_ids(ids).tap do |known_ids|
fetch_users(ids - known_ids) unless known_ids == ids
end
ids.map { |id| user_cache.get(id) }
end
|