Class: Joey::User

Inherits:
Profile show all
Includes:
ParserHelpers
Defined in:
lib/joey/user.rb

Instance Attribute Summary

Attributes inherited from Model

#client, #errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ParserHelpers

#boolianize

Methods inherited from Profile

#to_s

Methods inherited from Model

define_properties, find, has_association, hash_populating_accessor, #initialize

Constructor Details

This class inherits a constructor from Joey::Model

Class Method Details

.recognize?(hash) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/joey/user.rb', line 13

def self.recognize?(hash)
  !hash.has_key?("category")
end

Instance Method Details

#friends!(ids) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/joey/user.rb', line 45

def friends!(ids)
  data = self.client.rest_call('users.getInfo', :uids => ids, :fields =>
                               'about_me,activities,affiliations,books,birthday,birthday_date,current_location,education_history,
                                             email,family,first_name,hometown_location,hs_info,interests,is_app_user,is_blocked,last_name,
                                             locale,meeting_for,meeting_sex,movies,music,name,notes_count,pic,pic_big,pic_small,pic_square,
                                             pic_with_logo,pic_big_with_logo,pic_small_with_logo,pic_square_with_logo,
                                             political,profile_blurb,profile_update_time,profile_url,quotes,relationship_status,religion,sex,
                                             significant_other_id,status,timezone,tv,username,wall_count,website,work_history')
 self.client.map_data(data, self.class)
end

#has_app_permission?(ext_perm) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/joey/user.rb', line 41

def has_app_permission?(ext_perm)
  boolianize(client.rest_call("users.hasAppPermission", :ext_perm => ext_perm.to_s))
end

#info(args) ⇒ Object



56
57
58
59
60
61
# File 'lib/joey/user.rb', line 56

def info(args)
  data = self.client.rest_call('users.getInfo', :uids => self.id, :fields => args.join(','))
  user = self.client.map_data(data, self.class).first
  user.id = user.uid
  user
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  self.validate
  self.errors.empty?
end

#validateObject



63
64
65
66
67
68
69
70
# File 'lib/joey/user.rb', line 63

def validate
  errors << { :message => 'id should not be nil' } if id.nil?
  errors << { :message => "name should be string but is #{name.inspect}" } unless name.is_a?(String)
  errors << { :message => "gender should be 'male' or 'female' but is #{gender.inspect}" } unless ['male', 'female'].include?(gender)
  errors << { :message => "pic big is neither string nor nil but is #{pic_big.inspect}" } unless pic_big.is_a?(String) || pic_big.nil?
  errors << { :message => "current location is neither Joey::Location nor nil but is #{current_location.inspect}" } unless current_location.is_a?(Joey::Location) || current_location.nil?
  updated_time.to_time rescue errors << { :message => 'updated_time is not compatible' }
end