Class: Lita::Adapters::Glip::UserCreator
- Inherits:
-
Object
- Object
- Lita::Adapters::Glip::UserCreator
- Defined in:
- lib/lita/adapters/glip/user_creator.rb
Class Method Summary collapse
- .create_user(user_id, glip_sdk) ⇒ Object
- .find_or_create_user(user_id, glip_sdk) ⇒ Object
- .real_name(glip_user) ⇒ Object
Class Method Details
.create_user(user_id, glip_sdk) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lita/adapters/glip/user_creator.rb', line 12 def create_user(user_id, glip_sdk) res = glip_sdk.persons.get personId: user_id Lita.logger.debug("Glip API Response Status: #{res.status}.") if res.status == 200 glip_user_name = real_name res.body Lita.logger.debug("Glip API Response: User Name: #{glip_user_name}/#{res.body['id']}.") user = Lita::User.create( res.body['id'], name: glip_user_name, mention_name: glip_user_name ) Lita.logger.debug("Created New User With User Name [#{glip_user['id']}][#{glip_user_name}]") return user end Lita.logger.debug("Create New User [#{user_id}]") User.create user_id end |
.find_or_create_user(user_id, glip_sdk) ⇒ Object
8 9 10 |
# File 'lib/lita/adapters/glip/user_creator.rb', line 8 def find_or_create_user(user_id, glip_sdk) Lita::User.find_by_id(user_id) || create_user(user_id, glip_sdk) end |
.real_name(glip_user) ⇒ Object
31 32 33 |
# File 'lib/lita/adapters/glip/user_creator.rb', line 31 def real_name(glip_user) "#{glip_user['firstName']} #{glip_user['lastName']}".gsub(/\s+/, ' ').strip end |