file-watcher 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/watcher +1 -0
- data/lib/file_watcher/watch_job.rb +38 -12
- metadata +2 -2
data/bin/watcher
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.join( File.dirname(__FILE__), 'watch_config')
|
2
2
|
require 'cgi'
|
3
3
|
require 'net/http'
|
4
|
+
require 'net/https'
|
4
5
|
require 'uri'
|
5
6
|
|
6
7
|
class WatchJob
|
@@ -15,24 +16,49 @@ class WatchJob
|
|
15
16
|
|
16
17
|
|
17
18
|
def do_post event
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
if watch_action[:http][:ssl]
|
20
|
+
protocol = 'https'
|
21
|
+
else
|
22
|
+
protocol = 'http'
|
23
|
+
end
|
24
|
+
|
25
|
+
url = "#{protocol}://#{watch_action[:http][:hostname]}:#{watch_action[:http][:port]}#{watch_action[:http][:uri]}"
|
26
|
+
uri = URI.parse(url)
|
27
|
+
|
28
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
if watch_action[:http][:ssl]
|
30
|
+
http.use_ssl = true
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
+
end
|
24
33
|
|
25
|
-
|
34
|
+
body = watch_action[:http][:body].merge({ :args => watch_action[:http][:body][:args].dup.push(event.name) } )
|
26
35
|
|
36
|
+
puts "URL: #{url}"
|
37
|
+
puts "body: #{body.to_json}"
|
27
38
|
|
28
|
-
|
39
|
+
puts "Path: #{uri.path}"
|
40
|
+
puts "URI: #{uri.inspect}"
|
41
|
+
puts "Port: #{uri.port}"
|
29
42
|
|
30
|
-
|
31
|
-
|
43
|
+
req = Net::HTTP::Post.new(uri.path)
|
44
|
+
if watch_action[:http][:auth_user]
|
45
|
+
puts "Setting auth..."
|
46
|
+
req.basic_auth watch_action[:http][:auth_user], watch_action[:http][:auth_pass]
|
47
|
+
end
|
32
48
|
|
33
|
-
|
34
|
-
|
49
|
+
req.set_form_data({'body' => body.to_json })
|
50
|
+
puts "SENDING: #{req.inspect}"
|
51
|
+
res = http.request(req)
|
52
|
+
puts "Res: #{res.inspect}"
|
53
|
+
case res
|
54
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
55
|
+
# OK
|
56
|
+
puts "Req was ok"
|
57
|
+
else
|
58
|
+
res.error!
|
35
59
|
end
|
60
|
+
|
61
|
+
puts "Response: #{res}"
|
36
62
|
end
|
37
63
|
|
38
64
|
def event_handler event
|