Class: RestFtpDaemon::Notification
- Defined in:
- lib/rest-ftp-daemon/notification.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#job ⇒ Object
Returns the value of attribute job.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#message ⇒ Object
Returns the value of attribute message.
-
#signal ⇒ Object
Returns the value of attribute signal.
-
#status ⇒ Object
Returns the value of attribute status.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize ⇒ Notification
constructor
A new instance of Notification.
-
#notify ⇒ Object
def status key, val @status = val end.
- #progname ⇒ Object
Constructor Details
#initialize ⇒ Notification
Returns a new instance of Notification.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rest-ftp-daemon/notification.rb', line 14 def initialize #def initialize(job, signal, error, status) # Grab params #@job = job # @signal = signal # @error = error # @status = status @status = {} @error = 0 @message = nil # Generate a random key @key = SecureRandom.hex(2) # Call super super end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
7 8 9 |
# File 'lib/rest-ftp-daemon/notification.rb', line 7 def error @error end |
#job ⇒ Object
Returns the value of attribute job.
11 12 13 |
# File 'lib/rest-ftp-daemon/notification.rb', line 11 def job @job end |
#job_id ⇒ Object
Returns the value of attribute job_id.
5 6 7 |
# File 'lib/rest-ftp-daemon/notification.rb', line 5 def job_id @job_id end |
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/rest-ftp-daemon/notification.rb', line 12 def key @key end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/rest-ftp-daemon/notification.rb', line 8 def @message end |
#signal ⇒ Object
Returns the value of attribute signal.
6 7 8 |
# File 'lib/rest-ftp-daemon/notification.rb', line 6 def signal @signal end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/rest-ftp-daemon/notification.rb', line 9 def status @status end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/rest-ftp-daemon/notification.rb', line 10 def url @url end |
Instance Method Details
#notify ⇒ Object
def status key, val
@status[key.to_s] = val
end
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rest-ftp-daemon/notification.rb', line 42 def notify # Check context raise NotificationMissingUrl unless @url raise NotificationMissingSignal unless @signal #sraise NotifImpossible unless @status # Params params = { id: @job_id, host: get_hostname, signal: @signal, error: @error, } # Add status only if present params["status"] = @status unless @status.empty? params["message"] = @message unless @message.to_s.blank? # Log this notification info "notify params: #{params.inspect}" # Prepare query uri = URI(@url) headers = {"Content-Type" => "application/json", "Accept" => "application/json"} # Post the notification http = Net::HTTP.new(uri.host, uri.port) response = http.post(uri.path, params.to_json, headers) info "notify reply: #{response.body.strip}" end |
#progname ⇒ Object
33 34 35 |
# File 'lib/rest-ftp-daemon/notification.rb', line 33 def progname "NOTIF #{@key}" end |