Commit c7579249024a119b56abcd2978a46a59ea0bb56a

Authored by Valeriy Sizov
2 parents 7dd27681 9912770c

Merge pull request #1184 from karuna/master

Hook url should be able to contain http basic authentication
Showing 1 changed file with 10 additions and 1 deletions   Show diff stats
app/models/web_hook.rb
... ... @@ -11,7 +11,16 @@ class WebHook < ActiveRecord::Base
11 11 message: "should be a valid url" }
12 12  
13 13 def execute(data)
14   - WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" })
  14 + parsed_url = URI.parse(url)
  15 + if parsed_url.userinfo.blank?
  16 + WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" })
  17 + else
  18 + post_url = url.gsub(parsed_url.userinfo+"@", "")
  19 + WebHook.post(post_url,
  20 + body: data.to_json,
  21 + headers: { "Content-Type" => "application/json" },
  22 + basic_auth: {username: parsed_url.user, password: parsed_url.password})
  23 + end
15 24 end
16 25  
17 26 end
... ...