Class: RoboPigeon::Slack::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/robopigeon/slack/client.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject



12
13
14
15
16
# File 'lib/robopigeon/slack/client.rb', line 12

def client
  raise 'client requires API key be set' unless @client

  @client
end

.emojiObject

Returns the value of attribute emoji.



10
11
12
# File 'lib/robopigeon/slack/client.rb', line 10

def emoji
  @emoji
end

.enabledObject

Returns the value of attribute enabled.



10
11
12
# File 'lib/robopigeon/slack/client.rb', line 10

def enabled
  @enabled
end

.nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/robopigeon/slack/client.rb', line 10

def name
  @name
end

Class Method Details

.api_keyObject



20
21
22
23
24
# File 'lib/robopigeon/slack/client.rb', line 20

def api_key
  raise 'api_key requires API key be set' unless client.token

  client.token
end

.api_key=(api_key) ⇒ Object



26
27
28
# File 'lib/robopigeon/slack/client.rb', line 26

def api_key=(api_key)
  @client = Slack::Web::Client.new(token: api_key)
end

.get_user(search) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/robopigeon/slack/client.rb', line 30

def get_user(search)
  lookup = search.shift
  begin
    users = client.users_search(user: lookup.downcase).try(:members) unless lookup.nil?
  rescue ::Faraday::Error => e
    puts "Giving up on slack user lookup because the slack client raised a #{e.class}:\n#{e.message}"
    users = nil
  end

  if users.nil? || users.empty? || users.length != 1
    return nil if search.empty?

    get_user(search)
  else
    users.try(:first)
  end
end