Class: Cb::Clients::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/cb/clients/job.rb

Class Method Summary collapse

Class Method Details

.find_by_criteria(criteria) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cb/clients/job.rb', line 26

def self.find_by_criteria(criteria)
  my_api = Cb::Utils::Api.new
  params = my_api.class.criteria_to_hash(criteria)
  json_hash = my_api.cb_get(Cb.configuration.uri_job_find, :query => params)

  if json_hash.has_key?('ResponseJob')
    if json_hash['ResponseJob'].has_key?('Job')
      job = Models::Job.new(json_hash['ResponseJob']['Job'])
    end
    my_api.append_api_responses(job, json_hash['ResponseJob'])
  end
  my_api.append_api_responses(job, json_hash)
end

.find_by_did(did) ⇒ Object



40
41
42
43
44
45
# File 'lib/cb/clients/job.rb', line 40

def self.find_by_did(did)
  criteria = Cb::Criteria::Job::Details.new
  criteria.did = did
  criteria.show_custom_values = true
  return find_by_criteria(criteria)
end

.response_has_search_metadata?(response_hash) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/cb/clients/job.rb', line 49

def self.response_has_search_metadata?(response_hash)
  response_hash['SearchMetaData'] &&
  response_hash['SearchMetaData']['SearchLocations'] &&
  response_hash['SearchMetaData']['SearchLocations']['SearchLocation']
end

.search(api_args_hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cb/clients/job.rb', line 7

def self.search(api_args_hash)
  my_api = Cb::Utils::Api.new
  json_hash = my_api.cb_get(Cb.configuration.uri_job_search, :query => api_args_hash)

  jobs = Array.new
  if !json_hash['ResponseJobSearch'].nil? && !json_hash['ResponseJobSearch']['Results'].nil?
    job_results = json_hash['ResponseJobSearch']['Results']['JobSearchResult']
    job_results = [job_results] unless job_results.is_a?(Array)
    job_results.each { |job_hash| jobs.push(Models::Job.new(job_hash)) }
    my_api.append_api_responses(jobs, json_hash['ResponseJobSearch'])

    if response_has_search_metadata?(json_hash['ResponseJobSearch'])
      my_api.append_api_responses(jobs, json_hash['ResponseJobSearch']['SearchMetaData']['SearchLocations']['SearchLocation'])
    end
  end

  my_api.append_api_responses(jobs, json_hash)
end