Class: Slackdraft::Base

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

Direct Known Subclasses

Message

Instance Method Summary collapse

Constructor Details

#initialize(token, &block) ⇒ Base

Init the class



7
8
9
10
11
12
13
14
15
# File 'lib/slackdraft/base.rb', line 7

def initialize(token, &block)
  if /^https?/.match(token)
    @target = token
  else 
    @target = "#{self.endpoint}#{@token}"
  end

  instance_eval(&block) if block_given?
end

Instance Method Details

#send!Object

Send the message!



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/slackdraft/base.rb', line 22

def send!

  # Send the request
  request = HTTParty.post(self.target, :body => {
    :payload => generate_payload.to_json
  })

  unless request.code.eql? 200
    false
  end

  true

end

#targetObject



17
18
19
# File 'lib/slackdraft/base.rb', line 17

def target
  @target
end