Class: TraqWebhook::Client
- Inherits:
-
Object
- Object
- TraqWebhook::Client
- Defined in:
- lib/traq_webhook.rb
Instance Attribute Summary collapse
-
#channel_id ⇒ Object
Returns the value of attribute channel_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #post(message) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/traq_webhook.rb', line 10 def initialize yield self if block_given? end |
Instance Attribute Details
#channel_id ⇒ Object
Returns the value of attribute channel_id.
8 9 10 |
# File 'lib/traq_webhook.rb', line 8 def channel_id @channel_id end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/traq_webhook.rb', line 8 def id @id end |
#token ⇒ Object
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() signature = calc_hmacsha1(self.token, ) 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 = option = { use_ssl: uri.scheme = "https" } res = Net::HTTP.start(uri.hostname, uri.port, option) do |http| http.request(req) end end |