Class: Social::Network::Graph::Ok::User

Inherits:
Base
  • Object
show all
Defined in:
lib/social/network/graph/ok/user.rb

Constant Summary collapse

FIELDS =
'uid,first_name,last_name,gender,birthday,pic_1,pic_2,pic_3,pic_4,url_profile,location,current_location,age,url_profile,current_status'

Instance Method Summary collapse

Methods inherited from Base

#build_request_params, #build_sig, #config, #deliver, #http_query, #normalize_msg

Methods included from Tail

#root=

Instance Method Details

#balance(uid) {|nil| ... } ⇒ Object

Yields:

  • (nil)


63
64
65
66
# File 'lib/social/network/graph/ok/user.rb', line 63

def balance(uid)
  return nil unless block_given?
  yield(nil) if block_given?
end

#charge_off_balance(uid, balance) {|[]| ... } ⇒ Object

Yields:

  • ([])


58
59
60
61
# File 'lib/social/network/graph/ok/user.rb', line 58

def charge_off_balance(uid, balance)
  return [] unless block_given?
  yield([]) if block_given?
end

#get_friends(uid, secret = nil) {|result| ... } ⇒ Object Also known as: get_friends_uids

Yields:

  • (result)


39
40
41
42
43
44
45
46
47
48
# File 'lib/social/network/graph/ok/user.rb', line 39

def get_friends(uid, secret = nil)
  params = { "method" => 'friends.get', :uid => uid, :session_secret_key => secret }
  response = self.send(:deliver, params)
  
  result = (response.present? && response != true) ? ActiveSupport::JSON.decode(response.body) : []
  result = (result.is_a?(Hash) && result['error_msg']) ? [] : result # if returned failure

  return result unless block_given?
  yield(result) if block_given?
end

#get_friends_profiles(uid, secret = nil, options = nil) {|friend_profiles| ... } ⇒ Object Also known as: get_friends_info

Yields:

  • (friend_profiles)


50
51
52
53
54
55
56
# File 'lib/social/network/graph/ok/user.rb', line 50

def get_friends_profiles(uid, secret = nil, options = nil)
  friend_uids = get_friends_uids(uid, secret)
  friend_profiles = friend_uids.map { |uid| get_info(uid, secret, options) }.flatten.compact
  
  return friend_profiles unless block_given?
  yield(friend_profiles) if block_given?
end

#get_info(*args) {|result| ... } ⇒ Object

Yields:

  • (result)


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
# File 'lib/social/network/graph/ok/user.rb', line 6

def get_info(*args)

  args.pop if args.last.nil?

  if args.last.kind_of?(Hash)
    options = args.pop #.with_indefferend_access
    secret = options[:secret]
    fields = options[:fields]
    
    fields = fields.join(',') if fields.kind_of?(Array)
    
    if fields
      avalible_fields = FIELDS.split(',')
      fields = fields.split(',').select { |field| 
        avalible_fields.include?(field)
      }.sort.join(',')
      fields = nil if fields.empty?
    end
  end

  uids = Array.wrap(args)
  params = { "method" => 'users.getInfo', "fields" => (fields || FIELDS), 
    :uids => uids.join(",") }
  params[:session_secret_key] = secret if secret

  code, response = self.deliver(params)
  result = response.present? ? JSON.load(response) : { 'error_msg' => 'Empty response' }
  result = result.is_a?(Hash) && result['error_msg'] ? [] : result
  
  return result unless block_given?
  yield(result) if block_given?
end