class Handiv::Tasks::Reporter

Attributes

client[R]
options[R]
task_id[R]

Public Class Methods

new(client, task_id, options = {}) click to toggle source
# File lib/handiv/tasks/reporter.rb, line 6
def initialize(client, task_id, options = {})
  @client = client
  @task_id = task_id
  @options = options.is_a?(String) ? { message: options } : options
end

Public Instance Methods

report() click to toggle source
# File lib/handiv/tasks/reporter.rb, line 12
def report
  client.logger.debug "Sending event about task #{task_id}"

  status = client.connection.send_data("tasks/#{task_id}", options)
  log_status(status)

  status >= 200 && status < 300 # Return success
end

Private Instance Methods

log_status(status) click to toggle source
# File lib/handiv/tasks/reporter.rb, line 23
def log_status(status)
  if status >= 200 && status < 300 # Return success
    client.logger.debug "Successfully sent event about task #{task_id}"
  elsif status == 404
    client.logger.error(
      "Task #{task_id} was not found with these credentials."
    )
  else
    client.logger.error "Failed to send event about task #{task_id}"
  end
end