Class: Cb::Clients::Recommendation

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

Class Method Summary collapse

Class Method Details

.create_jobs(json_hash, type) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/cb/clients/recommendation.rb', line 101

def self.create_jobs(json_hash, type)
  jobs = []

  [json_hash["ResponseRecommend#{type}"]['RecommendJobResults']['RecommendJobResult']].flatten.each do |api_job|
    jobs << Models::Job.new(api_job)
  end

  jobs
end

.for_company(company_did) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cb/clients/recommendation.rb', line 65

def self.for_company(company_did)
  my_api = Cb::Utils::Api.instance
  json_hash = my_api.cb_get(Cb.configuration.uri_recommendation_for_company, query: { CompanyDID: company_did })
  jobs = []
  if json_hash
    api_jobs = json_hash.fetch('Results', {}).fetch('JobRecommendation', {}).fetch('Jobs', {})
    if api_jobs
      api_jobs.fetch('CompanyJob', []).each do |cur_job|
        jobs << Models::Job.new(cur_job)
      end
    end
    my_api.append_api_responses(jobs, json_hash.fetch('Results', {}).fetch('JobRecommendation', {}))
    my_api.append_api_responses(jobs, json_hash.fetch('Results', {}))
    my_api.append_api_responses(jobs, json_hash)
  end
end

.for_job(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cb/clients/recommendation.rb', line 16

def self.for_job(*args)
  my_api = Cb::Utils::Api.instance
  hash = normalize_args(args)
  hash = set_hash_defaults(hash)
  json_hash = my_api.cb_get(Cb.configuration.uri_recommendation_for_job,
                            query: hash)

  jobs = []

  if json_hash.key?('ResponseRecommendJob')
    if json_hash['ResponseRecommendJob'].key?('RecommendJobResults') &&
       !json_hash['ResponseRecommendJob']['RecommendJobResults'].nil?

      jobs = create_jobs json_hash, 'Job'

      my_api.append_api_responses(jobs, json_hash['ResponseRecommendJob']['Request'])
    end

    my_api.append_api_responses(jobs, json_hash['ResponseRecommendJob'])
  end

  my_api.append_api_responses(jobs, json_hash)
end

.for_user(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cb/clients/recommendation.rb', line 40

def self.for_user(*args)
  my_api = Cb::Utils::Api.instance
  hash = normalize_args(args)
  hash = set_hash_defaults(hash)
  json_hash = my_api.cb_get(Cb.configuration.uri_recommendation_for_user,
                            query: hash)

  jobs = []

  if json_hash.key?('ResponseRecommendUser')

    if json_hash['ResponseRecommendUser'].key?('RecommendJobResults') &&
       !json_hash['ResponseRecommendUser']['RecommendJobResults'].nil?

      jobs = create_jobs json_hash, 'User'

      my_api.append_api_responses(jobs, json_hash['ResponseRecommendUser']['Request'])
    end

    my_api.append_api_responses(jobs, json_hash['ResponseRecommendUser'])
  end

  my_api.append_api_responses(jobs, json_hash)
end

.normalize_args(args) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/cb/clients/recommendation.rb', line 84

def self.normalize_args(args)
  return args[0] if args[0].class == Hash
  {
    ExternalID: args[0],
    JobDID: args[0],
    CountLimit: args[1] || '25',
    SiteID: args[2] || '',
    CoBrand: args[3] || ''
  }
end

.set_hash_defaults(hash) ⇒ Object



95
96
97
98
99
# File 'lib/cb/clients/recommendation.rb', line 95

def self.set_hash_defaults(hash)
  hash[:CountLimit] ||= '25'
  hash[:HostSite] ||= Cb.configuration.host_site
  hash
end