Class: Cb::Clients::Job

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJob

Returns a new instance of Job.



9
10
11
# File 'lib/cb/clients/job.rb', line 9

def initialize
  @cb_client ||= Cb.api_client.new
end

Instance Attribute Details

#cb_clientObject

Returns the value of attribute cb_client.



7
8
9
# File 'lib/cb/clients/job.rb', line 7

def cb_client
  @cb_client
end

Class Method Details

.find_by_criteria(criteria) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cb/clients/job.rb', line 32

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



52
53
54
55
56
57
# File 'lib/cb/clients/job.rb', line 52

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

.search(api_args_hash) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cb/clients/job.rb', line 13

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

Instance Method Details

#find_by_criteria(criteria) ⇒ Object



46
47
48
49
50
# File 'lib/cb/clients/job.rb', line 46

def find_by_criteria(criteria)
  query = cb_client.class.criteria_to_hash(criteria)
  json_response = cb_client.cb_get(Cb.configuration.uri_job_find, :query => query)
  singular_model_response(json_response, criteria.did)
end