Class: TwistCapistrano::Client
- Inherits:
-
Object
- Object
- TwistCapistrano::Client
- Defined in:
- lib/twist_capistrano.rb
Instance Method Summary collapse
-
#initialize(twist_secret) ⇒ Client
constructor
A new instance of Client.
- #send(message, twist_msg_id) ⇒ Object
Constructor Details
#initialize(twist_secret) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/twist_capistrano.rb', line 8 def initialize(twist_secret) @twist_secret = twist_secret end |
Instance Method Details
#send(message, twist_msg_id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/twist_capistrano.rb', line 12 def send(, twist_msg_id) return if @twist_secret.nil? || @twist_secret.empty? uri = URI.parse("https://api.twist.io/api/v1/hook/capistrano?secret=#{@twist_secret}") req = Net::HTTP::Post.new(uri.request_uri) req.body = { 'message' => "#{}", 'parent_id' => twist_msg_id.to_s }.to_json http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true res = http.start {|http| http.request(req) } response = JSON.parse(res.body) response['id'] rescue puts "Sending message to Twist failed." end |