Class: Handiv::Tasks::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/handiv/tasks/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, task_id, options = {}) ⇒ Reporter

Returns a new instance of Reporter.



6
7
8
9
10
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/handiv/tasks/reporter.rb', line 4

def client
  @client
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/handiv/tasks/reporter.rb', line 4

def options
  @options
end

#task_idObject (readonly)

Returns the value of attribute task_id.



4
5
6
# File 'lib/handiv/tasks/reporter.rb', line 4

def task_id
  @task_id
end

Instance Method Details

#reportObject



12
13
14
15
16
17
18
19
# 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