Class: JobClient

Inherits:
BaseClient show all
Defined in:
lib/dal/job_client.rb

Constant Summary collapse

JOBS_BY_DEVICE_IDS =
'/api/v1/jobs/_search-by-devices'
JOB_BY_ID_URL =
'/api/v1/jobs/%{job_id}'
JOBS_LIST_BY_ID_URL =
'/api/v1/jobs/_search-by-jobs'

Class Method Summary collapse

Class Method Details

.get_job_by_id(job_id) ⇒ Object



18
19
20
21
22
# File 'lib/dal/job_client.rb', line 18

def self.get_job_by_id(job_id)
  url = JOB_BY_ID_URL % {job_id: job_id}
  res_hash = api_request 'GET', url, {}
  res_hash.present? ? res_hash[:data] : nil
end

.get_jobs(device_ids, start_day, end_day) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dal/job_client.rb', line 6

def self.get_jobs(device_ids, start_day, end_day)
  device_ids = [device_ids] unless device_ids.is_a?(Array)
  url = JOBS_BY_DEVICE_IDS
  post_body = {
      "aaa-device-ids": device_ids,
      "start": start_day.iso8601(3),
      "end": end_day.iso8601(3)
  }.to_json
  res_hash = api_request 'POST', url, {}, post_body
  res_hash.present? ? res_hash[:data] : nil
end

.get_jobs_by_id(job_ids) ⇒ Object



24
25
26
27
28
29
# File 'lib/dal/job_client.rb', line 24

def self.get_jobs_by_id(job_ids)
  job_ids = [job_ids] unless job_ids.is_a?(Array)
  post_body = {'job-ids': job_ids}.to_json
  res_hash = api_request 'POST', JOBS_LIST_BY_ID_URL, {}, post_body
  res_hash.present? ? res_hash[:data] : nil
end