Sha256: 65c7bc2d1f40cbee14fd9bcf0112fd30227bdc8f767c6162d93f5c255eda3342

Contents?: true

Size: 843 Bytes

Versions: 2

Compression:

Stored size: 843 Bytes

Contents

module Lita
  module Adapters
    class Glip < Adapter
      class UserCreator
        class << self
          def find_or_create_user(user_id, glip_sdk)
            Lita::User.find_by_id(user_id) || create_user(user_id, glip_sdk)
          end

          def create_user(user_id, glip_sdk)
            res = glip_sdk.persons.get personId: user_id
            if res.status == 200
              glip_user_name = real_name res.body
              return Lita::User.create(
                glip_user['id'],
                name: glip_user_name,
                mention_name: glip_user_name
              )
            end
            User.create user_id
          end

          def real_name(glip_user)
            "#{glip_user['firstName']} #{glip_user['lastName']}".gsub(/\s+/, ' ').strip
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lita-glip-0.0.2 lib/lita/adapters/glip/user_creator.rb
lita-glip-0.0.1 lib/lita/adapters/glip/user_creator.rb