Class: Slack::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-notifier.rb,
lib/slack-notifier/version.rb,
lib/slack-notifier/link_formatter.rb,
lib/slack-notifier/default_http_client.rb

Defined Under Namespace

Classes: DefaultHTTPClient, LinkFormatter

Constant Summary collapse

VERSION =
"0.6.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team, token, options = {}) ⇒ Notifier

hook_name=default_hook_name, default_payload={}


13
14
15
16
17
18
19
# File 'lib/slack-notifier.rb', line 13

def initialize team, token, options={} # hook_name=default_hook_name, default_payload={}
  @team      = team
  @token     = token
  @http_client = options.delete(:http_client) || DefaultHTTPClient
  @hook_name   = options.delete(:hook_name) || default_hook_name
  @default_payload = options
end

Instance Attribute Details

#default_payloadObject (readonly)

Returns the value of attribute default_payload.


10
11
12
# File 'lib/slack-notifier.rb', line 10

def default_payload
  @default_payload
end

#hook_nameObject (readonly)

Returns the value of attribute hook_name.


10
11
12
# File 'lib/slack-notifier.rb', line 10

def hook_name
  @hook_name
end

#http_clientObject (readonly)

Returns the value of attribute http_client.


10
11
12
# File 'lib/slack-notifier.rb', line 10

def http_client
  @http_client
end

#teamObject (readonly)

Returns the value of attribute team.


10
11
12
# File 'lib/slack-notifier.rb', line 10

def team
  @team
end

#tokenObject (readonly)

Returns the value of attribute token.


10
11
12
# File 'lib/slack-notifier.rb', line 10

def token
  @token
end

Instance Method Details

#channelObject


29
30
31
# File 'lib/slack-notifier.rb', line 29

def channel
  default_payload[:channel]
end

#channel=(channel) ⇒ Object


33
34
35
# File 'lib/slack-notifier.rb', line 33

def channel= channel
  default_payload[:channel] = channel
end

#ping(message, options = {}) ⇒ Object


21
22
23
24
25
26
27
# File 'lib/slack-notifier.rb', line 21

def ping message, options={}
  message = LinkFormatter.format(message)
  payload = { text: message }.merge(default_payload).merge(options)


  http_client.post endpoint, payload: payload.to_json
end

#usernameObject


37
38
39
# File 'lib/slack-notifier.rb', line 37

def username
  default_payload[:username]
end

#username=(username) ⇒ Object


41
42
43
# File 'lib/slack-notifier.rb', line 41

def username= username
  default_payload[:username] = username
end