/
room.rb
82 lines (65 loc) · 1.46 KB
/
room.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'hash_utils'
class Room < Hash
include HashUtils
class << self
def ff_id(arg)
auth = arg[:auth]
room = arg[:room]
ff_profile(auth, room)['id']
end
def ff_name(arg)
auth = arg[:auth]
room = arg[:room]
ff_profile(auth, room)['name']
end
def ff_url(arg)
auth = arg[:auth]
room = arg[:room]
ff_profile(auth, room)['url']
end
def status(arg)
auth = arg[:auth]
room = arg[:room]
ff_profile(auth, room)['status']
end
def description(arg)
auth = arg[:auth]
room = arg[:room]
ff_profile(auth, room)['description']
end
def picture_url(arg)
room = arg[:room]
size = arg[:size] || 'small'
ff_picture_url(room, size)
end
def members(arg)
auth = arg[:auth]
room = arg[:room]
sort_by_name(ff_profile(auth, room)['members'] || [])
end
private
def ff_picture_url(room, size = 'small')
(@picture_url_cache ||= {})[room] ||=
ff_client.get_room_picture_url(room, size)
end
def ff_profile(auth, room)
(@profile_cache ||= {})[[auth.name, room]] ||=
ff_client.get_room_profile(auth.name, auth.remote_key, room)
end
def sort_by_name(lists)
lists.sort_by { |e| e['name'] }
end
def ff_client
ApplicationController.ff_client
end
end
def id
v('id')
end
def nickname
v('nickname')
end
def name
v('name')
end
end