Class: Vk::User
Constant Summary
collapse
- RELATION_MAPPING =
{
0 => nil,
1 => :single,
2 => :friendship,
3 => :plight,
4 => :married,
5 => :complicated,
6 => :looking,
7 => :love
}
Instance Attribute Summary collapse
Attributes inherited from Base
#attributes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#fields, find, #id, #id=, #identity_map, inherited, #initialize, #inspect, #key_field, #loader, #logger, method_missing, #method_missing, #read_attribute, #respond_to_missing?, #to_hash
Constructor Details
This class inherits a constructor from Vk::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Vk::Base
Instance Attribute Details
#posts_count ⇒ Fixnum
140
141
142
|
# File 'lib/vk/user.rb', line 140
def posts_count
@posts_count
end
|
Class Method Details
.find_all(ids, options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/vk/user.rb', line 19
def self.find_all(ids, options = {})
loaded_ids = ids & identity_map.keys
ids_to_load = ids - loaded_ids
identity_map.values_at(*loaded_ids).tap do |results|
if ids_to_load.any?
results += loader.get_users(ids_to_load, options).map do |profile|
new(profile['id'], data: profile)
end
end
end
end
|
Instance Method Details
113
114
115
|
# File 'lib/vk/user.rb', line 113
def audio_albums
@audio_albums ||= loader.get_audio_albums(id).all
end
|
118
119
120
|
# File 'lib/vk/user.rb', line 118
def audios
@audios ||= loader.get_audios(id).all
end
|
#born_on ⇒ Date
39
40
41
|
# File 'lib/vk/user.rb', line 39
def born_on
@born_on ||= Date.strptime(bdate, '%d.%m.%Y') if born_on?
end
|
#born_on? ⇒ Boolean
43
44
45
|
# File 'lib/vk/user.rb', line 43
def born_on?
read_attribute(:bdate).to_s.split(/\./).size == 3
end
|
62
63
64
|
# File 'lib/vk/user.rb', line 62
def city
@city ||= Vk::City.find(city_id)
end
|
#city_id ⇒ Fixnum
57
58
59
|
# File 'lib/vk/user.rb', line 57
def city_id
read_attribute(:city)
end
|
72
73
74
|
# File 'lib/vk/user.rb', line 72
def country
@country ||= Vk::Country.find(country_id)
end
|
#country_id ⇒ Fixnum
67
68
69
|
# File 'lib/vk/user.rb', line 67
def country_id
read_attribute(:country)
end
|
#deactivated? ⇒ Boolean
98
99
100
|
# File 'lib/vk/user.rb', line 98
def deactivated?
read_attribute(:deactivated)
end
|
#friend_ids(options = {}) ⇒ <Fixnum>
77
78
79
|
# File 'lib/vk/user.rb', line 77
def friend_ids(options = {})
@friend_ids ||= loader.get_friends(id, options = {})
end
|
#friends(options = {}) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/vk/user.rb', line 82
def friends(options = {})
@friends ||= {}
@friends[options] ||=
if options[:fields]
loader.get_friends(id, options).all
else
User.find_all(friend_ids)
end
end
|
#gender ⇒ :unknown, ...
48
49
50
51
52
53
54
|
# File 'lib/vk/user.rb', line 48
def gender
{
0 => :unknown,
1 => :female,
2 => :male
}[sex]
end
|
#groups(options = {}) ⇒ <Vk::Group>
147
148
149
150
151
152
153
|
# File 'lib/vk/user.rb', line 147
def groups(options = {})
@groups ||= {}
options[:extended] = true
index = options.hash
@groups[index] ||= loader.get_groups(id, options)
@groups[index].all
end
|
#name ⇒ String
34
35
36
|
# File 'lib/vk/user.rb', line 34
def name
@name ||= "#{first_name} #{last_name}"
end
|
#profile_photos ⇒ <Vk::Photo>
93
94
95
|
# File 'lib/vk/user.rb', line 93
def profile_photos
@profile_photos ||= loader.get_photos(id, 'profile').all
end
|
#relation_partner ⇒ Vk::User
107
108
109
110
|
# File 'lib/vk/user.rb', line 107
def relation_partner
partner = read_attribute(:relation_partner)
Vk::User.new(partner) if partner
end
|
#relation_type ⇒ Object
102
103
104
|
# File 'lib/vk/user.rb', line 102
def relation_type
RELATION_MAPPING[relation]
end
|
#to_s ⇒ String
123
124
125
|
# File 'lib/vk/user.rb', line 123
def to_s
name
end
|
#wall(options = {}) ⇒ Object
Also known as:
posts
128
129
130
131
132
133
134
135
|
# File 'lib/vk/user.rb', line 128
def wall(options = {})
@wall ||= {}
@wall[options] ||=
begin
count, *posts = loader.get_wall(id, options)
Vk::Post::Wall.new(id, count, posts)
end
end
|