Class: Passport::Thrift::ThriftUserProfileService
- Inherits:
-
Object
- Object
- Passport::Thrift::ThriftUserProfileService
- Defined in:
- lib/passport_thrift_client.rb
Instance Method Summary collapse
- #checkNickname(oldNickname, nickname) ⇒ Object
- #checkNicknameDuplicate(oldNickname, nickname) ⇒ Object
- #checkNicknameFormat(nickname) ⇒ Object
- #convert_profile_to_hash(profile) ⇒ Object
- #convert_user_basicinfo_to_hash(profile) ⇒ Object
- #destroy ⇒ Object
- #getMultiNickNameByUids(uidList) ⇒ Object
- #getMultiUserBasicInfos(uids) ⇒ Object
- #getNicknameByUid(uid) ⇒ Object
- #getProfielByEmail(email) ⇒ Object
- #getProfileByNickname(nickname) ⇒ Object
- #getProfileByUid(uid) ⇒ Object
- #getProfileByUids(uids) ⇒ Object
-
#initialize(config = {}) ⇒ ThriftUserProfileService
constructor
A new instance of ThriftUserProfileService.
- #queryUserBasicInfo(uid) ⇒ Object
- #save(profile = {}) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ ThriftUserProfileService
Returns a new instance of ThriftUserProfileService.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/passport_thrift_client.rb', line 42 def initialize(config = {}) if config['servers'].nil? raise 'servers must be determined!' return end config = DEFAULT_CONFIG.merge(config) config['client_class'] = 'Passport::Thrift::RemoteUserProfileService::Client' @thriftClient = ThriftClient.new(config) @@logger = LoggerFactory.getLogger("ThriftUserProfileService") end |
Instance Method Details
#checkNickname(oldNickname, nickname) ⇒ Object
138 139 140 |
# File 'lib/passport_thrift_client.rb', line 138 def checkNickname(oldNickname, nickname) @thriftClient.checkNickname(oldNickname, nickname) end |
#checkNicknameDuplicate(oldNickname, nickname) ⇒ Object
146 147 148 |
# File 'lib/passport_thrift_client.rb', line 146 def checkNicknameDuplicate(oldNickname, nickname) @thriftClient.checkNicknameDuplicate(oldNickname, nickname) end |
#checkNicknameFormat(nickname) ⇒ Object
142 143 144 |
# File 'lib/passport_thrift_client.rb', line 142 def checkNicknameFormat(nickname) @thriftClient.checkNicknameFormat(nickname) end |
#convert_profile_to_hash(profile) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/passport_thrift_client.rb', line 154 def convert_profile_to_hash(profile) unless profile.nil? || profile.isNull profile = profile.to_hash if profile['createTime'] > 0 profile['createTime'] = Time.at(profile['createTime'] / 1000).to_s else profile['createTime'] = nil end if profile['lastModifyTime'] > 0 profile['lastModifyTime'] = Time.at(profile['lastModifyTime'] / 1000).to_s else profile['lastModifyTime'] = nil end if profile['loginBanStart'] > 0 profile['loginBanStart'] = Time.at(profile['loginBanStart'] / 1000).to_s else profile['loginBanStart'] = nil end if profile['loginBanEnd'] > 0 profile['loginBanEnd'] = Time.at(profile['loginBanEnd'] / 1000).to_s else profile['loginBanEnd'] = nil end return profile end return nil end |
#convert_user_basicinfo_to_hash(profile) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/passport_thrift_client.rb', line 185 def convert_user_basicinfo_to_hash(profile) unless profile.nil? || profile.isNull profile = profile.to_hash if profile['createdTime'] > 0 profile['createdTime'] = Time.at(profile['createdTime'] / 1000).to_s else profile['createdTime'] = nil end if profile['loginBanStart'] > 0 profile['loginBanStart'] = Time.at(profile['loginBanStart'] / 1000).to_s else profile['loginBanStart'] = nil end if profile['loginBanEnd'] > 0 profile['loginBanEnd'] = Time.at(profile['loginBanEnd'] / 1000).to_s else profile['loginBanEnd'] = nil end if profile['vCategoryId'] <= 0 profile['vCategoryId'] = nil end return profile end return nil end |
#destroy ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/passport_thrift_client.rb', line 53 def destroy @@logger.error("before ThriftUserProfileService destroy") begin @thriftClient.destroy rescue Exception => e @@logger.error("ThriftUserProfileService destroy error !! #{e.}" + "\n" + e.backtrace.join("\n")) end @@logger.error("thriftUserProfileService destroyed!") end |
#getMultiNickNameByUids(uidList) ⇒ Object
92 93 94 |
# File 'lib/passport_thrift_client.rb', line 92 def getMultiNickNameByUids(uidList) @thriftClient.getMultiNickNameByUids(uidList) end |
#getMultiUserBasicInfos(uids) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/passport_thrift_client.rb', line 114 def getMultiUserBasicInfos(uids) info_map = @thriftClient.getMultiUserBasicInfos(uids) unless info_map.nil? hash_info_map = {} info_map.each do |k, v| hash_info_map[k] = convert_user_basicinfo_to_hash(v) end return hash_info_map end return nil end |
#getNicknameByUid(uid) ⇒ Object
88 89 90 |
# File 'lib/passport_thrift_client.rb', line 88 def getNicknameByUid(uid) @thriftClient.getNicknameByUid(uid) end |
#getProfielByEmail(email) ⇒ Object
150 151 152 |
# File 'lib/passport_thrift_client.rb', line 150 def getProfielByEmail(email) convert_profile_to_hash(@thriftClient.getProfielByEmail(email)) end |
#getProfileByNickname(nickname) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/passport_thrift_client.rb', line 126 def getProfileByNickname(nickname) profile_list = @thriftClient.getProfileByNickname(nickname) unless profile_list.nil? hash_profile_list = [] profile_list.each do |p| hash_profile_list << convert_profile_to_hash(p) end return hash_profile_list end return nil end |
#getProfileByUid(uid) ⇒ Object
71 72 73 74 |
# File 'lib/passport_thrift_client.rb', line 71 def getProfileByUid(uid) profile = @thriftClient.getProfileByUid(uid) return convert_profile_to_hash(profile) end |
#getProfileByUids(uids) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/passport_thrift_client.rb', line 76 def getProfileByUids(uids) profile_map = @thriftClient.getProfileByUids(uids) unless profile_map.nil? hash_profile_map = {} profile_map.each do |k, v| hash_profile_map[k] = convert_profile_to_hash(v) end return hash_profile_map end return nil end |
#queryUserBasicInfo(uid) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/passport_thrift_client.rb', line 96 def queryUserBasicInfo(uid) begin if uid && uid.to_i > 0 info = @thriftClient.queryUserBasicInfo(uid) info = convert_user_basicinfo_to_hash(info) end unless info @@logger.error("query user basic info return nil , uid: #{uid}") end return info rescue Exception => e @@logger.error("query user basic info error, uid: #{uid},cause by :#{e.}," + " \n" + e.backtrace.join("\n")) if info @@logger.error("info : #{info.inspect}") end end end |
#save(profile = {}) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/passport_thrift_client.rb', line 63 def save(profile = {}) if (profile['uid'].nil?) return end profile = Passport::Thrift::Profile.new(profile) @thriftClient.save(profile) end |