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.
Files changed (3) hide show
  1. data/bin/watcher +1 -0
  2. data/lib/file_watcher/watch_job.rb +38 -12
  3. metadata +2 -2
data/bin/watcher CHANGED
@@ -64,6 +64,7 @@ class Watcher < BaseApp
64
64
 
65
65
  WatchJob.registered_jobs.each do |job|
66
66
  @notifier.watch(job.watch_criteria[:target_dir], *job.watch_criteria[:events]) do |event|
67
+ puts "got event: #{event}"
67
68
  job.event_handler event
68
69
  end
69
70
  end
@@ -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
- Net::HTTP.start(watch_action[:http][:hostname]) do |http|
19
- if watch_action[:http][:ssl]
20
- protocol = 'https'
21
- else
22
- protocol = 'http'
23
- end
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
- url = "#{protocol}://#{watch_action[:http][:auth_user]}:#{watch_action[:http][:auth_pass]}@#{watch_action[:http][:hostname]}:#{watch_action[:http][:port]}#{watch_action[:http][:uri]}"
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
- body = watch_action[:http][:body].merge({ :args => watch_action[:http][:body][:args].dup.push(event.name) } )
39
+ puts "Path: #{uri.path}"
40
+ puts "URI: #{uri.inspect}"
41
+ puts "Port: #{uri.port}"
29
42
 
30
- puts "URL: #{url}"
31
- puts "body: #{body}"
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
- res = Net::HTTP.post_form(URI.parse(url), {'body' => body.to_json } )
34
- puts "Response: #{res}"
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 3
9
- version: 1.0.3
8
+ - 4
9
+ version: 1.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Santa Clara