Class: TraqWebhook::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



10
11
12
# File 'lib/traq_webhook.rb', line 10

def initialize
  yield self if block_given?
end

Instance Attribute Details

#channel_idObject

Returns the value of attribute channel_id.



8
9
10
# File 'lib/traq_webhook.rb', line 8

def channel_id
  @channel_id
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/traq_webhook.rb', line 8

def id
  @id
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/traq_webhook.rb', line 8

def token
  @token
end

Instance Method Details

#post(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/traq_webhook.rb', line 14

def post(message)
  signature = calc_hmacsha1(self.token, message)
  uri = URI.parse('https://q.trap.jp/api/1.0/webhooks/' + self.id)
  req = Net::HTTP::Post.new(uri.path)
  req['Content-Type'] = 'text/plain; charset=utf-8'
  req['X-TRAQ-Signature'] = signature
  req['X-TRAQ-Channel-Id'] = self.channel_id unless self.channel_id.nil?
  req.body = message
  option = {
    use_ssl: uri.scheme = "https" 
   }
  res = Net::HTTP.start(uri.hostname, uri.port, option) do |http|
    http.request(req)
  end
end