Module: Cvprac::Api::Task

Included in:
CvpApi
Defined in:
lib/cvprac/api/task.rb

Overview

CVP Task api methods

Task Method Summary collapse

Instance Method Details

#add_note_to_task(task_id, note) ⇒ Hash

Add note to CVP task by taskID

Parameters:

  • The id of the task to execute

  • Content of the note

Returns:

  • request body



89
90
91
92
93
94
95
# File 'lib/cvprac/api/task.rb', line 89

def add_note_to_task(task_id, note)
  log(Logger::DEBUG) do
    "add_note_to_task: task_id: #{task_id}, note: [#{note}]"
  end
  @clnt.post('/task/addNoteToTask.do',
             data: { workOrderId: task_id, note: note })
end

#execute_task(task_id) ⇒ Hash

Execute CVP task by taskID

Parameters:

  • The id of the task to execute

Returns:

  • request body



102
103
104
105
# File 'lib/cvprac/api/task.rb', line 102

def execute_task(task_id)
  log(Logger::DEBUG) { "execute_task: task_id: #{task_id}" }
  @clnt.post('/task/executeTask.do', body: { data: [task_id] })
end

#get_pending_tasks_by_device(device) ⇒ Hash

Get task data by device name (FQDN)

rubocop:disable Metrics/MethodLength

Parameters:

  • Name (FQDN) of a device

Returns:

  • request body



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cvprac/api/task.rb', line 66

def get_pending_tasks_by_device(device)
  log(Logger::DEBUG) { "#{__method__}: device: #{device}" }
  begin
    task = @clnt.get('/task/getTasks.do', data: { queryparam: 'Pending',
                                                  startIndex: 0,
                                                  endIndex: 0 })
  rescue CvpApiError => e
    if e.to_s.include?('Invalid WorkOrderId') ||
       e.to_s.include?('Entity does not exist')
      return nil
    end
  end
  # TODO: filter tasks by device
  task['data']
end

#get_task_by_id(task_id) ⇒ Hash

Get task data by ID

Parameters:

  • The id of the task to execute

Returns:

  • request body



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cvprac/api/task.rb', line 47

def get_task_by_id(task_id)
  log(Logger::DEBUG) { "#{__method__}: task_id: #{task_id}" }
  begin
    task = @clnt.get('/task/getTaskById.do', data: { taskId: task_id })
  rescue CvpApiError => e
    if e.to_s.include?('Invalid WorkOrderId') ||
       e.to_s.include?('Entity does not exist')
      return nil
    end
  end
  task
end