Class: Passport::Thrift::ThriftPassportService

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

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ ThriftPassportService

Returns a new instance of ThriftPassportService.



260
261
262
263
264
265
266
267
268
269
# File 'lib/passport_thrift_client.rb', line 260

def initialize(config = {})
  if config['servers'].nil? 
    raise 'servers must be determined!'
    return
  end
  config = DEFAULT_CONFIG.merge(config)
  config['client_class'] = 'Passport::Thrift::RemotePassportService::Client'
  @thriftClient = ThriftClient.new(config)
  @@logger = LoggerFactory.getLogger("ThriftPassportService")
end

Instance Method Details

#convert_passport_to_hash(passport) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/passport_thrift_client.rb', line 337

def convert_passport_to_hash(passport)
  unless passport.nil? || passport.isNull
    passport = passport.to_hash
    if passport['createTime'] > 0
      passport['createTime'] = Time.at(passport['createTime'] / 1000).to_s
    else 
      passport['createTime'] = nil
    end
    return passport
  end  
  return nil
end

#destroyObject



271
272
273
274
275
276
277
278
279
# File 'lib/passport_thrift_client.rb', line 271

def destroy
  @@logger.error("before ThriftPassportService destroy")
  begin
    @thriftClient.destroy
  rescue Exception => e
    @@logger.error("ThriftPassportService destroy error !! #{e.message}" + "\n" + e.backtrace.join("\n"))
  end
  @@logger.error("ThriftPassportService destroyed!")
end

#getMultiNickNameByUids(uidList) ⇒ Object



297
298
299
# File 'lib/passport_thrift_client.rb', line 297

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

#getMultiPassportByMobiles(mobiles) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
# File 'lib/passport_thrift_client.rb', line 325

def getMultiPassportByMobiles(mobiles)
  passport_map = @thriftClient.getMultiPassportByMobiles(mobiles)
  unless passport_map.nil?
    hash_passport_map = {}
    passport_map.each do |k, v|
      hash_passport_map[k] = convert_passport_to_hash(v)
    end
    return hash_passport_map
  end
  return {}
end

#getNickNameByUid(uid) ⇒ Object



293
294
295
# File 'lib/passport_thrift_client.rb', line 293

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

#getPassportByLoginName(loginName) ⇒ Object



313
314
315
# File 'lib/passport_thrift_client.rb', line 313

def getPassportByLoginName(loginName)
  convert_passport_to_hash(@thriftClient.getPassportByLoginName(loginName))
end

#modifyPasswordDirectly(uid, password) ⇒ Object



317
318
319
# File 'lib/passport_thrift_client.rb', line 317

def modifyPasswordDirectly(uid, password)
  @thriftClient.modifyPasswordDirectly(uid, password)
end

#queryByMobile(mobile) ⇒ Object



321
322
323
# File 'lib/passport_thrift_client.rb', line 321

def queryByMobile(mobile)
  convert_passport_to_hash(@thriftClient.queryByMobile(mobile))
end

#queryPassportByEmail(email) ⇒ Object



281
282
283
# File 'lib/passport_thrift_client.rb', line 281

def queryPassportByEmail(email)
  convert_passport_to_hash(@thriftClient.queryPassportByEmail(email))
end

#queryPassportByUid(uid) ⇒ Object



285
286
287
# File 'lib/passport_thrift_client.rb', line 285

def queryPassportByUid(uid)
  convert_passport_to_hash(@thriftClient.queryPassportByUid(uid))
end

#queryPassportUidMap(uidList) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
# File 'lib/passport_thrift_client.rb', line 301

def queryPassportUidMap(uidList)
  passport_map = @thriftClient.queryPassportUidMap(uidList)
  unless passport_map.nil?
    hash_passport_map = {}
    passport_map.each do |k, v|
      hash_passport_map[k] = convert_passport_to_hash(v)
    end
    return hash_passport_map
  end
  return {}
end

#validatePassword(uid, password) ⇒ Object



289
290
291
# File 'lib/passport_thrift_client.rb', line 289

def validatePassword(uid, password)
  @thriftClient.validatePassword(uid, password)
end