Class: Passport::Thrift::ThriftUserProfileService

Inherits:
Object
  • Object
show all
Defined in:
lib/passport_thrift_client.rb

Instance Method Summary collapse

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



130
131
132
# File 'lib/passport_thrift_client.rb', line 130

def checkNickname(oldNickname, nickname)
	@thriftClient.checkNickname(oldNickname, nickname)
end

#checkNicknameDuplicate(oldNickname, nickname) ⇒ Object



138
139
140
# File 'lib/passport_thrift_client.rb', line 138

def checkNicknameDuplicate(oldNickname, nickname)
	@thriftClient.checkNicknameDuplicate(oldNickname, nickname)
end

#checkNicknameFormat(nickname) ⇒ Object



134
135
136
# File 'lib/passport_thrift_client.rb', line 134

def checkNicknameFormat(nickname)
	@thriftClient.checkNicknameFormat(nickname)
end

#convert_profile_to_hash(profile) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/passport_thrift_client.rb', line 146

def convert_profile_to_hash(profile)
	unless profile.nil?
		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



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/passport_thrift_client.rb', line 177

def convert_user_basicinfo_to_hash(profile)
	unless profile.nil?
		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

#destroyObject



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.message}" + "\n" + e.backtrace.join("\n"))
	end
	@@logger.error("thriftUserProfileService destroyed!")
end

#getMultiNickNameByUids(uidList) ⇒ Object



84
85
86
# File 'lib/passport_thrift_client.rb', line 84

def getMultiNickNameByUids(uidList)
	@thriftClient.getMultiNickNameByUids(uidList)
end

#getMultiUserBasicInfos(uids) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/passport_thrift_client.rb', line 106

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



80
81
82
# File 'lib/passport_thrift_client.rb', line 80

def getNicknameByUid(uid)
	@thriftClient.getNicknameByUid(uid)
end

#getProfielByEmail(email) ⇒ Object



142
143
144
# File 'lib/passport_thrift_client.rb', line 142

def getProfielByEmail(email)
	convert_profile_to_hash(@thriftClient.getProfielByEmail(email))
end

#getProfileByNickname(nickname) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/passport_thrift_client.rb', line 118

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



63
64
65
66
# File 'lib/passport_thrift_client.rb', line 63

def getProfileByUid(uid)
	profile = @thriftClient.getProfileByUid(uid)
	return convert_profile_to_hash(profile)
end

#getProfileByUids(uids) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/passport_thrift_client.rb', line 68

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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/passport_thrift_client.rb', line 88

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.message}," + " \n" + e.backtrace.join("\n"))
		if info
			@@logger.error("info : #{info.inspect}")
		end
	end
end