Class: Vk::User

Inherits:
Base
  • Object
show all
Defined in:
lib/vk/user.rb

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_countFixnum

Returns:

  • (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

#audio_albums<Vk::Audio::Album>

Returns:



113
114
115
# File 'lib/vk/user.rb', line 113

def audio_albums
  @audio_albums ||= loader.get_audio_albums(id).all
end

#audios<Vk::Audio>

Returns:



118
119
120
# File 'lib/vk/user.rb', line 118

def audios
  @audios ||= loader.get_audios(id).all
end

#born_onDate

Returns:

  • (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

Returns:

  • (Boolean)


43
44
45
# File 'lib/vk/user.rb', line 43

def born_on?
  read_attribute(:bdate).to_s.split(/\./).size == 3
end

#cityVk::City

Returns:



62
63
64
# File 'lib/vk/user.rb', line 62

def city
  @city ||= Vk::City.find(city_id)
end

#city_idFixnum

Returns:

  • (Fixnum)


57
58
59
# File 'lib/vk/user.rb', line 57

def city_id
  read_attribute(:city)
end

#countryVk::Country

Returns:



72
73
74
# File 'lib/vk/user.rb', line 72

def country
  @country ||= Vk::Country.find(country_id)
end

#country_idFixnum

Returns:

  • (Fixnum)


67
68
69
# File 'lib/vk/user.rb', line 67

def country_id
  read_attribute(:country)
end

#deactivated?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/vk/user.rb', line 98

def deactivated?
  read_attribute(:deactivated)
end

#friend_ids(options = {}) ⇒ <Fixnum>

Returns:

  • (<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

Parameters:

  • options (<Vk::User>) (defaults to: {})


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, ...

Returns:

  • (:unknown, :female, :male)


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>

Parameters:

  • options (Hash) (defaults to: {})

Returns:

See Also:

  • Request.get_groups


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

#nameString

Returns:

  • (String)


34
35
36
# File 'lib/vk/user.rb', line 34

def name
  @name ||= "#{first_name} #{last_name}"
end

#profile_photos<Vk::Photo>

Returns:



93
94
95
# File 'lib/vk/user.rb', line 93

def profile_photos
  @profile_photos ||= loader.get_photos(id, 'profile').all
end

#relation_partnerVk::User

Returns:



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_typeObject



102
103
104
# File 'lib/vk/user.rb', line 102

def relation_type
  RELATION_MAPPING[relation]
end

#to_sString

Returns:

  • (String)


123
124
125
# File 'lib/vk/user.rb', line 123

def to_s
  name
end

#wall(options = {}) ⇒ Object Also known as: posts

Parameters:

  • options (Vk::Wall) (defaults to: {})


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