Class: SocialProfile::People::Vkontakte

Inherits:
SocialProfile::Person show all
Defined in:
lib/social_profile/people/vkontakte.rb

Instance Attribute Summary

Attributes inherited from SocialProfile::Person

#access_token, #options, #uid

Instance Method Summary collapse

Methods inherited from SocialProfile::Person

#find_album, #find_or_create_album, #followers_count, get, #initialize, #share_photo!, #tag_object!

Constructor Details

This class inherits a constructor from SocialProfile::Person

Instance Method Details

#album!(options = {}) ⇒ Object

Create new album id



15
16
17
18
# File 'lib/social_profile/people/vkontakte.rb', line 15

def album!(options = {})
  response = user.photos.createAlbum(:title => options[:name], :description => options[:message])
  Album.new(response, user)
end

#fetch_album(album_id) ⇒ Object

Find album by id



9
10
11
12
# File 'lib/social_profile/people/vkontakte.rb', line 9

def fetch_album(album_id)
  response = user.photos.getAlbums(:aids => album_id)
  Album.new(response, user)
end

#fetch_friends_countObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/social_profile/people/vkontakte.rb', line 25

def fetch_friends_count
  response = user.fetch(:fields => "counters")
  response = response.first if response.is_a?(Array)

  return nil unless response.is_a?(Hash)

  counters = response["counters"] 
  return nil if counters["friends"].blank? && counters["followers"].blank?

  counters["friends"].to_i + counters["followers"].to_i
end

#followers(options = {}) ⇒ Object

Get all followers list



161
162
163
164
165
166
167
168
169
# File 'lib/social_profile/people/vkontakte.rb', line 161

def followers(options={})
  options = {
    :count => 1000,
    :offset => 0,
    :fields => "screen_name"
  }.merge(options)

  fetch_all_method_items(:fetch_followers, options)
end

#friends(options = {}) ⇒ Object

Get all friends list



149
150
151
152
153
154
155
156
157
# File 'lib/social_profile/people/vkontakte.rb', line 149

def friends(options={})
  options = {
    :count => 5000,
    :offset => 0,
    :fields => "domain"
  }.merge(options)

  fetch_all_method_items(:fetch_friends, options)
end

#friends_countObject

Get friends count



21
22
23
# File 'lib/social_profile/people/vkontakte.rb', line 21

def friends_count
  @friends_count ||= fetch_friends_count
end

#get_post(post_uid, options = {}) ⇒ Object

Get post by id



173
174
175
176
177
178
179
180
# File 'lib/social_profile/people/vkontakte.rb', line 173

def get_post(post_uid, options={})
  options = {
    :posts => post_uid,
    :extended => 1
  }.merge(options)

  user.wall.getById(options)
end

#last_post_by_days(days, options = {}) ⇒ Object

Get last posts by N days from user_timeline



54
55
56
57
58
# File 'lib/social_profile/people/vkontakte.rb', line 54

def last_post_by_days(days, options = {})
  options = { :days => days }.merge(options)

  last_posts(options)
end

#last_posts(options = {}) ⇒ Object

Get last limited posts from user_timeline, max 100 by query



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/social_profile/people/vkontakte.rb', line 39

def last_posts(options = {})
  params = { 
    :owner_id => user.identifier,
    :count => 100, 
    :filter => "owner", 
    :offset => 0
  }

  params.merge!(options)

  fetch_all_method_items_with_days("wall.get", params)
end

#mutual_friends(options = {}) ⇒ Object

Get mutual friends (options target_uids is required)



184
185
186
187
188
189
190
# File 'lib/social_profile/people/vkontakte.rb', line 184

def mutual_friends(options={})
  response = user.friends.getMutual(options)

  return {} unless response.is_a?(Array)
  
  response.inject({}) {|h, a| h.merge!(a["id"].to_s => a["common_count"]) }
end

#object_likes(uid, options = {}) ⇒ Object

Get object likes (post, comment, photo, audio, video, note, photo_comment, video_comment, topic_comment, sitepage)



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/social_profile/people/vkontakte.rb', line 62

def object_likes(uid, options = {})
  fetch_all = options.delete(:fetch_all)

  params = { 
    :owner_id => user.identifier,
    :count => 1000, 
    :type => "post", 
    :item_id => uid,
    :offset => 0
  }
  params.merge!(options)
  
  if fetch_all
    return fetch_all_method_items("likes.getList", params)
  end


  user.likes.getList(params)
end

#photos_comments(options = {}) ⇒ Object

Get all photos comments



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/social_profile/people/vkontakte.rb', line 126

def photos_comments(options = {})
  params = { 
    :owner_id => user.identifier,
    :count => 100, 
    :need_likes => 1,
    :offset => 0
  }

  params.merge!(options)

  fetch_all_method_items_with_days("photos.getAllComments", params)
end

#photos_comments_by_days(days, options = {}) ⇒ Object

Get all photos comments by days



141
142
143
144
145
# File 'lib/social_profile/people/vkontakte.rb', line 141

def photos_comments_by_days(days, options = {})
  options = { :days => days }.merge(options)

  photos_comments(options)
end

#post_comments(uid, options = {}) ⇒ Object

Get post comments



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/social_profile/people/vkontakte.rb', line 84

def post_comments(uid, options = {})
  fetch_all = options.delete(:fetch_all)

  params = { 
    :owner_id => user.identifier,
    :count => 100, 
    :preview_length => 0, 
    :need_likes => 1,
    :post_id => uid,
    :offset => 0
  }
  params.merge!(options)

  if fetch_all
    return fetch_all_method_items("wall.getComments", params)
  end

  user.wall.getComments(params)  
end

#post_shares(uid, options = {}) ⇒ Object

Get post shares



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/social_profile/people/vkontakte.rb', line 106

def post_shares(uid, options = {})
  fetch_all = options.delete(:fetch_all)

  params = { 
    :owner_id => user.identifier,
    :count => 1000, 
    :post_id => uid,
    :offset => 0
  }
  params.merge!(options)

  if fetch_all
    return fetch_all_method_items("wall.getReposts", params)
  end

  user.wall.getReposts(params)  
end