class SocialProfile::People::Vkontakte
Public Instance Methods
album!(options = {})
click to toggle source
Create new album id
# 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)
click to toggle source
Find album by id
# 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_count()
click to toggle source
# 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={})
click to toggle source
Get all followers list
# 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={})
click to toggle source
Get all friends list
# 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_count()
click to toggle source
Get friends count
# File lib/social_profile/people/vkontakte.rb, line 21 def friends_count @friends_count ||= fetch_friends_count end
get_post(post_uid, options={})
click to toggle source
Get post by id
# 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 = {})
click to toggle source
Get last posts by N days from user_timeline
# 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 = {})
click to toggle source
Get last limited posts from user_timeline, max 100 by query
# 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={})
click to toggle source
Get mutual friends (options target_uids is required)
# 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 = {})
click to toggle source
Get object likes (post, comment, photo, audio, video, note, photo_comment, video_comment, topic_comment, sitepage)
# 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 = {})
click to toggle source
Get all photos comments
# 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 = {})
click to toggle source
Get all photos comments by days
# 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 = {})
click to toggle source
Get post comments
# 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
Protected Instance Methods
fetch_all_method_items(name, options)
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 198 def fetch_all_method_items(name, options) methods = name.to_s.split(".") response = methods.size == 2 ? user.send(methods[0]).send(methods[1], options) : user.send(name, options) _items = response["items"] return [] if _items.blank? iteration = (response["count"].to_i / _items.size.to_f).ceil iteration.times do |index| next if index == 0 options[:offset] += options[:count] _items += (methods.size == 2 ? user.send(methods[0]).send(methods[1], options) : user.send(name, options))["items"] end _items end
fetch_all_method_items_with_days(name, options)
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 217 def fetch_all_method_items_with_days(name, options) days = options.delete(:days) date_end = options.delete(:date_end) methods = name.to_s.split(".") response = methods.size == 2 ? user.send(methods[0]).send(methods[1], options) : user.send(name, options) return [] if response.blank? || !response.is_a?(Hash) _items = response["items"] return [] if _items.blank? if days date = (date_end || Time.now) - days.days iteration = (response["count"].to_i / _items.size.to_f).ceil last_date = _items.last ? Time.at(_items.last["date"].to_i).to_datetime : nil iteration.times do |index| next if index == 0 options[:offset] += options[:count] _items += (methods.size == 2 ? user.send(methods[0]).send(methods[1], options) : user.send(name, options))["items"] last_date = _items.last ? Time.at(_items.last["date"].to_i).to_datetime : nil break if last_date.blank? || last_date < date end if !last_date.blank? && last_date > date return _items.select { |item| Time.at(item["date"].to_i).to_datetime > date } end _items end
user()
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 194 def user @user ||= ::Vkontakte::App::User.new(uid, :access_token => access_token) end