cb-api 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ cb-api
2
+ ================
3
+
4
+ A gem that's going to house our internal API interactions.
5
+
6
+
7
+ TODO
8
+ ==================
9
+ 1. Error handling
10
+ 2. Figure out base CbApi internactions with child classes
11
+ 2.1 CbApi should handle errors, and setting standard fields (response time, errors, etc)
12
+ 2.2 CbApi should extract the base fields from the json packet (meaning sub classes don't have to parse them)
data/lib/cb.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'cb/config'
2
+ Dir[File.dirname(__FILE__) + '/cb/utils/*.rb'].each {| file| require file }
3
+ Dir[File.dirname(__FILE__) + '/cb/clients/*.rb'].each {| file| require file }
4
+ Dir[File.dirname(__FILE__) + '/cb/models/*.rb'].each {| file| require file }
5
+ require 'cb/job_search_criteria'
6
+
7
+ module Cb
8
+ def self.configure
9
+ yield configuration
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Cb::Config.new
14
+ @configuration.set_default_api_uris
15
+
16
+ return @configuration
17
+ end
18
+
19
+ # Convenience methods, in case you're lazy... like me :)
20
+ ###############################################################
21
+ def self.job
22
+ Cb::JobApi
23
+ end
24
+
25
+ def self.job_search_criteria
26
+ Cb::JobSearchCriteria.new()
27
+ end
28
+
29
+ def self.category
30
+ Cb::CategoryApi
31
+ end
32
+
33
+ def self.company
34
+ Cb::CompanyApi
35
+ end
36
+
37
+ def self.education_code
38
+ Cb::EducationApi
39
+ end
40
+
41
+ def self.recommendation
42
+ Cb::RecommendationApi
43
+ end
44
+
45
+ def self.job_application
46
+ Cb::JobApplicationApi
47
+ end
48
+
49
+ def self.country
50
+ Cb::Utils::Country
51
+ end
52
+ end
@@ -0,0 +1,36 @@
1
+ require "json"
2
+
3
+ module Cb
4
+ class CategoryApi
5
+ def self.search
6
+ my_api = Cb::Utils::Api.new()
7
+ cb_response = my_api.cb_get(Cb.configuration.uri_job_category_search)
8
+ json_hash = JSON.parse(cb_response.response.body)
9
+
10
+ categoryList = []
11
+ json_hash["ResponseCategories"]["Categories"]["Category"].each do |cat|
12
+ categoryList << CbCategory.new(cat)
13
+ end
14
+ return categoryList
15
+ end
16
+
17
+ def self.search_by_host_site(host_site)
18
+ my_api = Cb::Utils::Api.new()
19
+ cb_response = my_api.cb_get(Cb.configuration.uri_job_category_search, :query => {:CountryCode => host_site})
20
+ json_hash = JSON.parse(cb_response.response.body)
21
+
22
+ categoryList = []
23
+ unless json_hash.empty?
24
+ if json_hash["ResponseCategories"]["Categories"]["Category"].is_a?(Array)
25
+ json_hash["ResponseCategories"]["Categories"]["Category"].each do |cat|
26
+ categoryList << CbCategory.new(cat)
27
+ end
28
+ elsif json_hash["ResponseCategories"]["Categories"]["Category"].is_a?(Hash) && json_hash.length < 2
29
+ categoryList << CbCategory.new(json_hash["ResponseCategories"]["Categories"]["Category"])
30
+ end
31
+ end
32
+
33
+ return categoryList
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module Cb
4
+ class CompanyApi
5
+ #############################################################
6
+ ## Retrieve a company by did
7
+ ##
8
+ ## For detailed information around this API please visit:
9
+ ## http://api.careerbuilder.com/CompanyDetailsInfo.aspx
10
+ #############################################################
11
+ def self.find_by_did(did)
12
+ my_api = Cb::Utils::Api.new()
13
+ cb_response = my_api.cb_get(Cb.configuration.uri_company_find, :query => {:CompanyDID => did})
14
+ json_hash = JSON.parse(cb_response.response.body)
15
+
16
+ company = CbCompany.new(json_hash['Results']['CompanyProfileDetail'])
17
+ my_api.append_api_responses(company, json_hash['Results'])
18
+
19
+ return company
20
+ end
21
+
22
+ def self.find_for(obj)
23
+ if obj.is_a?(String)
24
+ did = obj
25
+ elsif obj.is_a?(Cb::CbJob)
26
+ did = obj.company_did
27
+ end
28
+ did ||= ''
29
+
30
+ find_by_did did unless did.empty?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ module Cb
4
+ class EducationApi
5
+ #############################################################
6
+ ## Retrieve Education codes by country code
7
+ ##
8
+ ## For detailed information around this API please visit:
9
+ ## http://api.careerbuilder.com/EducationCodes.aspx
10
+ #############################################################
11
+ def self.get_for(country)
12
+ Cb::Utils::Country.is_valid? country ? country : 'US'
13
+
14
+ my_api = Cb::Utils::Api.new()
15
+ cb_response = my_api.cb_get(Cb.configuration.uri_education_code, :query => {:countrycode => country})
16
+ json_hash = JSON.parse(cb_response.response.body)
17
+
18
+ codes = []
19
+ json_hash['ResponseEducationCodes']['EducationCodes']['Education'].each do | education |
20
+ codes << Cb::CbEducation.new(education)
21
+ end
22
+ my_api.append_api_responses(codes, json_hash['ResponseEducationCodes'])
23
+
24
+ return codes
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ require "json"
2
+
3
+ module Cb
4
+ class EmployeeTypesApi
5
+
6
+ def self.search
7
+ my_api = Cb::Utils::Api.new()
8
+ cb_response = my_api.cb_get(Cb.configuration.uri_employee_types)
9
+
10
+ return array_of_objects_from_hash(cb_response)
11
+ end
12
+
13
+ def self.search_by_host_site(hostsite)
14
+ my_api = Cb::Utils::Api.new()
15
+ cb_response = my_api.cb_get(Cb.configuration.uri_employee_types, :query => {:CountryCode => hostsite})
16
+
17
+ return array_of_objects_from_hash(cb_response)
18
+ end
19
+
20
+ private
21
+ def self.array_of_objects_from_hash(cb_response)
22
+ json_hash = JSON.parse(cb_response.response.body)
23
+
24
+ employee_types = []
25
+ unless json_hash.empty?
26
+ if json_hash["ResponseEmployeeTypes"]["EmployeeTypes"]["EmployeeType"].is_a?(Array)
27
+ json_hash["ResponseEmployeeTypes"]["EmployeeTypes"]["EmployeeType"].each do |et|
28
+ employee_types << CbEmployeeType.new(et)
29
+ end
30
+ elsif json_hash["ResponseEmployeeTypes"]["EmployeeTypes"]["EmployeeType"].is_a?(Hash) && json_hash.length < 2
31
+ employee_types << CbEmployeeType.new(json_hash["ResponseEmployeeTypes"]["EmployeeTypes"]["EmployeeType"])
32
+ end
33
+ end
34
+
35
+ return employee_types
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ require 'json'
2
+
3
+ module Cb
4
+ class JobApi
5
+ #############################################################
6
+ ## Run a job search against the given criteria
7
+ ##
8
+ ## For detailed information around this API please visit:
9
+ ## http://api.careerbuilder.com/JobSearchInfo.aspx
10
+ #############################################################
11
+ def self.search(*args)
12
+ args = args[0] if args.is_a?(Array) && args.count == 1
13
+
14
+ my_api = Cb::Utils::Api.new()
15
+ cb_response = my_api.cb_get(Cb.configuration.uri_job_search, :query => args)
16
+ json_hash = JSON.parse(cb_response.response.body)
17
+
18
+ jobs = []
19
+ unless json_hash['ResponseJobSearch']['Results'].nil?
20
+ json_hash['ResponseJobSearch']['Results']['JobSearchResult'].each do | cur_job |
21
+ jobs << CbJob.new(cur_job)
22
+ end
23
+ end
24
+ my_api.append_api_responses(jobs, json_hash['ResponseJobSearch'])
25
+
26
+ return jobs
27
+ end
28
+
29
+ #############################################################
30
+ ## Retrieve a job by did
31
+ ##
32
+ ## For detailed information around this API please visit:
33
+ ## http://api.careerbuilder.com/JobInfo.aspx
34
+ #############################################################
35
+ def self.find_by_did(did, params = {})
36
+ my_api = Cb::Utils::Api.new()
37
+ params[:did] = did
38
+ if params["showjobskin"].nil?
39
+ params["showjobskin"] = "Full"
40
+ end
41
+ cb_response = my_api.cb_get(Cb.configuration.uri_job_find, :query => params)
42
+ json_hash = JSON.parse(cb_response.response.body)
43
+
44
+ job = CbJob.new(json_hash['ResponseJob']['Job'])
45
+ my_api.append_api_responses(job, json_hash['ResponseJob'])
46
+
47
+ return job
48
+ end
49
+ end # JobApi
50
+ end # Cb
@@ -0,0 +1,35 @@
1
+ require 'json'
2
+
3
+ module Cb
4
+ class JobApplicationApi
5
+ #############################################################
6
+ ## Get job application information
7
+ ##
8
+ ## For detailed information around this API please visit:
9
+ ## http://api.careerbuilder.com/ApplicationInfo.aspx
10
+ #############################################################
11
+
12
+ def self.get_for(job_did, site_id = '', co_brand = '')
13
+ my_api = Cb::Utils::Api.new()
14
+ cb_response = my_api.cb_get(Cb.configuration.uri_job_application, :query => {:JobDID => job_did, :SiteID => site_id, :CoBrand => co_brand})
15
+ json_hash = JSON.parse(cb_response.response.body)
16
+
17
+ job_application = CbJobApplication.new(json_hash['ResponseBlankApplication']['BlankApplication'])
18
+ my_api.append_api_responses(job_application, json_hash['ResponseBlankApplication'])
19
+
20
+ return job_application
21
+ end
22
+
23
+ #############################################################
24
+ ## Submit a job application
25
+ ##
26
+ ## For detailed information around this API please visit:
27
+ ## http://api.careerbuilder.com/ApplicationInfo.aspx
28
+ #############################################################
29
+
30
+ # def self.submit(did)
31
+
32
+ # end
33
+
34
+ end # JobApplicationApi
35
+ end # Cb
@@ -0,0 +1,78 @@
1
+ require 'json'
2
+
3
+ module Cb
4
+ class RecommendationApi
5
+ #############################################################
6
+ ## Get recommendations for a job
7
+ ##
8
+ ## For detailed information around this API please visit:
9
+ ## http://api.careerbuilder.com/Recommendations.aspx
10
+ #############################################################
11
+ def self.for_job(did, site_id = '', co_brand = '')
12
+ my_api = Cb::Utils::Api.new()
13
+ cb_response = my_api.cb_get(Cb.configuration.uri_recommendation_for_job,
14
+ :query => {:JobDID => did, :SiteID => site_id, :CoBrand => co_brand})
15
+ json_hash = JSON.parse(cb_response.response.body)
16
+
17
+ jobs = []
18
+ unless json_hash['ResponseRecommendJob']['RecommendJobResults'].nil?
19
+ json_hash['ResponseRecommendJob']['RecommendJobResults']['RecommendJobResult'].each do |cur_job|
20
+ jobs << CbJob.new(cur_job)
21
+ end
22
+ end
23
+ my_api.append_api_responses(jobs, json_hash['ResponseRecommendJob'])
24
+ my_api.append_api_responses(jobs, json_hash['ResponseRecommendJob']['Request'])
25
+
26
+ return jobs
27
+ end
28
+
29
+ #############################################################
30
+ ## Get recommendations for a user
31
+ ##
32
+ ## For detailed information around this API please visit:
33
+ ## http://api.careerbuilder.com/Recommendations.aspx
34
+ #############################################################
35
+ def self.for_user(external_id, site_id = '', co_brand = '')
36
+ my_api = Cb::Utils::Api.new()
37
+ cb_response = my_api.cb_get(Cb.configuration.uri_recommendation_for_user,
38
+ :query => {:ExternalID => external_id, :SiteID => site_id, :CoBrand => co_brand,
39
+ :HostSite => Cb.configuration.host_site})
40
+ json_hash = JSON.parse(cb_response.response.body)
41
+
42
+ jobs = []
43
+ unless json_hash['ResponseRecommendUser']['RecommendJobResults'].nil?
44
+ json_hash['ResponseRecommendUser']['RecommendJobResults']['RecommendJobResult'].each do |cur_job|
45
+ jobs << CbJob.new(cur_job)
46
+ end
47
+ end
48
+ my_api.append_api_responses(jobs, json_hash['ResponseRecommendUser'])
49
+ my_api.append_api_responses(jobs, json_hash['ResponseRecommendUser']['Request'])
50
+
51
+ return jobs
52
+ end
53
+
54
+ #############################################################
55
+ ## Get recommendations for a company
56
+ ##
57
+ ## For detailed information around this API please visit:
58
+ ## http://api.careerbuilder.com/Recommendations.aspx
59
+ #############################################################
60
+ def self.for_company(company_did)
61
+ my_api = Cb::Utils::Api.new()
62
+ cb_response = my_api.cb_get(Cb.configuration.uri_recommendation_for_company,
63
+ :query => {:CompanyDID => company_did})
64
+ json_hash = JSON.parse(cb_response.response.body)
65
+
66
+ jobs = []
67
+ unless json_hash['Results']['JobRecommendation'].nil?
68
+ json_hash['Results']['JobRecommendation']['Jobs'].each do |cur_job|
69
+ jobs << CbJob.new(cur_job)
70
+ end
71
+ end
72
+ my_api.append_api_responses(jobs, json_hash['Results'])
73
+ my_api.append_api_responses(jobs, json_hash['Results']['JobRecommendation'])
74
+
75
+ return jobs
76
+ end
77
+ end
78
+ end
data/lib/cb/config.rb ADDED
@@ -0,0 +1,64 @@
1
+ module Cb
2
+ class Config
3
+ attr_accessor :dev_key, :time_out, :use_json, :host_site,
4
+ :uri_job_search, :uri_job_find,
5
+ :uri_company_find, :uri_job_category_search,
6
+ :uri_education_code, :uri_employee_types,
7
+ :uri_recommendation_for_job, :uri_recommendation_for_user,
8
+ :uri_recommendation_for_company,
9
+ :uri_job_application
10
+ #:uri_job_application_submit
11
+
12
+ def initialize
13
+ Cb::Utils::Country.inject_convenience_methods
14
+ set_defaults
15
+ end
16
+
17
+ def set_default_api_uris
18
+ @uri_job_category_search ||= '/v1/categories'
19
+ @uri_employee_types ||= '/v1/employeetypes'
20
+ @uri_company_find ||= '/Employer/CompanyDetails'
21
+ @uri_job_search ||= '/v1/JobSearch'
22
+ @uri_job_find ||= '/v1/Job'
23
+ @uri_education_code ||= '/v1/EducationCodes'
24
+ @uri_recommendation_for_job ||= '/v1/Recommendations/ForJob'
25
+ @uri_recommendation_for_user ||= '/v1/Recommendations/ForUser'
26
+ @uri_recommendation_for_company ||= '/Employer/JobRecommendation'
27
+ @uri_job_application ||= '/v1/application/blank'
28
+ #@uri_job_application_submit ||= '/v1/application/submit'
29
+ end
30
+
31
+ def to_hash
32
+ {
33
+ :uri_job_category_search => @uri_job_category_search,
34
+ :uri_employee_types => @uri_employee_types,
35
+ :dev_key => @dev_key,
36
+ :host_site => @host_site,
37
+ :time_out => @time_out,
38
+ :use_json => @use_json,
39
+ :uri_job_search => @uri_job_search,
40
+ :uri_job_find => @uri_job_find,
41
+ :uri_company_find => @uri_company_find,
42
+ :uri_education_code => @uri_education_code,
43
+ :uri_recommendation_for_job => @uri_recommendation_for_job,
44
+ :uri_recommendation_for_user => @uri_recommendation_for_user,
45
+ :uri_recommendation_for_company => @uri_recommendation_for_company,
46
+ :uri_job_application => @uri_job_application
47
+ # :uri_job_application_submit => @uri_job_application_submit
48
+ }
49
+ end
50
+
51
+ private
52
+ #################################################################
53
+
54
+ def set_defaults
55
+
56
+ @dev_key = 'ruby-cb-api' # Get a developer key at http://api.careerbuilder.com
57
+ @time_out = 5
58
+ @use_json = true
59
+ @host_site = Cb.country.US
60
+
61
+ set_default_api_uris
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,102 @@
1
+ module Cb
2
+ # Trying to simplify the large number of inputs our job search api accepts
3
+ # For indepth information around all of the different inputs, please visit:
4
+ # http://api.careerbuilder.com/JobSearchInfo.aspx
5
+ ####################################################################################
6
+ class JobSearchCriteria
7
+ extend Cb::Utils::FluidAttributes
8
+
9
+ fluid_attr_accessor :advanced_grouping, :boolean_operator, :category, :co_brand, :company_did,
10
+ :company_did_csv, :company_name, :company_name_boost, :country_code,
11
+ :education_code, :employer_type, :enable_company_collapse, :exclude_company_names,
12
+ :exclude_job_titles, :exclude_keywords, :exclude_national, :exclude_mlms,
13
+ :exclude_product, :facet_category, :facet_company, :facet_city, :facet_state,
14
+ :facet_city_state, :facet_pay, :facet_normalized_company_did, :host_site,
15
+ :include_company_children, :industry_codes, :job_title, :keywords, :location,
16
+ :normalized_company_did, :normalized_company_did_boost_params,
17
+ :normalized_company_name, :onet, :order_by, :order_direction, :page_number,
18
+ :partner_id, :pay_high, :pay_info_only, :pay_low, :per_page, :posted_within,
19
+ :product, :radius, :records_per_group, :relocate_jobs, :soc, :school_id,
20
+ :search_all_countries, :search_view, :show_categories, :show_apply_requirements,
21
+ :apply_requirements, :single_onet, :site_entity, :site_id, :skills, :specific_education,
22
+ :spoken_language, :tags, :talent_network_did, :url_compression_service, :use_facets,
23
+ :str_crit
24
+
25
+ def search
26
+ Cb::JobApi.search(self.to_hash)
27
+ end
28
+
29
+ def to_hash
30
+ ret = {}
31
+
32
+ ret.merge!(:AdvancedGroupingMode => @advanced_grouping) unless @advanced_grouping.nil?
33
+ ret.merge!(:BooleanOperator => @boolean_operator) unless @boolean_operator.nil?
34
+ ret.merge!(:Category => @category) unless @category.nil?
35
+ ret.merge!(:CoBrand => @co_brand) unless @co_brand.nil?
36
+ ret.merge!(:CompanyDID => @company_did) unless @company_did.nil?
37
+ ret.merge!(:CompanyDIDCSV => @company_did_csv) unless @company_did_csv.nil?
38
+ ret.merge!(:CompanyName => @company_name) unless @company_name.nil?
39
+ ret.merge!(:CompanyNameBoostParams => @company_name_boost) unless @company_name_boost.nil?
40
+ ret.merge!(:CountryCode => @country_code) unless @country_code.nil?
41
+ ret.merge!(:EducationCode => @education_code) unless @education_code.nil?
42
+ ret.merge!(:EmpType => @employer_type) unless @employer_type.nil?
43
+ ret.merge!(:EnableCompanyCollapse => @enable_company_collapse) unless @enable_company_collapse.nil?
44
+ ret.merge!(:ExcludeCompanyNames => @exclude_company_names) unless @exclude_company_names.nil?
45
+ ret.merge!(:ExcludeJobTitles => @exclude_job_titles) unless @exclude_job_titles.nil?
46
+ ret.merge!(:ExcludeKeywords => @exclude_keywords) unless @exclude_keywords.nil?
47
+ ret.merge!(:ExcludeNational => @exclude_national) unless @exclude_national.nil?
48
+ ret.merge!(:ExcludeNonTraditionalJobs => @exclude_mlms) unless @exclude_mlms.nil?
49
+ ret.merge!(:ExcludeProductID => @exclude_product) unless @exclude_product.nil?
50
+ ret.merge!(:FacetCategory => @facet_category) unless @facet_category.nil?
51
+ ret.merge!(:FacetCompany => @facet_company) unless @facet_company.nil?
52
+ ret.merge!(:FacetCity => @facet_city) unless @facet_city.nil?
53
+ ret.merge!(:FacetState => @facet_state) unless @facet_state.nil?
54
+ ret.merge!(:FacetCityState => @facet_city_state) unless @facet_city_state.nil?
55
+ ret.merge!(:FacetPay => @facet_pay) unless @facet_pay.nil?
56
+ ret.merge!(:FacetNormalizedCompanyDID => @facet_normalized_company_did) unless @facet_normalized_company_did.nil?
57
+ ret.merge!(:HostSite => @host_site) unless @host_site.nil?
58
+ ret.merge!(:IncludeCompanyChildren => @include_company_children) unless @include_company_children.nil?
59
+ ret.merge!(:IndustryCodes => @industry_codes) unless @industry_codes.nil?
60
+ ret.merge!(:JobTitle => @job_title) unless @job_title.nil?
61
+ ret.merge!(:Keywords => @keywords) unless @keywords.nil?
62
+ ret.merge!(:Location => @location) unless @location.nil?
63
+ ret.merge!(:NormalizedCompanyDID => @normalized_company_did) unless @normalized_company_did.nil?
64
+ ret.merge!(:NormalizedCompanyDIDBoostParams => @normalized_company_did_boost_params) unless @normalized_company_did_boost_params.nil?
65
+ ret.merge!(:NormalizedCompanyName => @normalized_company_name) unless @normalized_company_name.nil?
66
+ ret.merge!(:ONetCode => @onet) unless @onet.nil?
67
+ ret.merge!(:OrderBy => @order_by) unless @order_by.nil?
68
+ ret.merge!(:OrderDirection => @order_direction) unless @order_direction.nil?
69
+ ret.merge!(:PageNumber => @page_number) unless @page_number.nil?
70
+ ret.merge!(:PartnerID => @partner_id) unless @partner_id.nil?
71
+ ret.merge!(:PayHigh => @pay_high) unless @pay_high.nil?
72
+ ret.merge!(:PayInfoOnly => @pay_info_only) unless @pay_info_only.nil?
73
+ ret.merge!(:PayLow => @pay_low) unless @pay_low.nil?
74
+ ret.merge!(:PerPage => @per_page) unless @per_page.nil?
75
+ ret.merge!(:PostedWithin => @posted_within) unless @posted_within.nil?
76
+ ret.merge!(:ProductID => @product) unless @product.nil?
77
+ ret.merge!(:Radius => @radius) unless @radius.nil?
78
+ ret.merge!(:RecordsPerGroup => @records_per_group) unless @records_per_group.nil?
79
+ ret.merge!(:RelocateJobs => @relocate_jobs) unless @relocate_jobs.nil?
80
+ ret.merge!(:SOCCode => @soc) unless @soc.nil?
81
+ ret.merge!(:SchoolSiteID => @school_id) unless @school_id.nil?
82
+ ret.merge!(:SearchAllCountries => @search_all_countries) unless @search_all_countries.nil?
83
+ ret.merge!(:SearchView => @search_view) unless @search_view.nil?
84
+ ret.merge!(:ShowCategories => @show_categories) unless @show_categories.nil?
85
+ ret.merge!(:ShowApplyRequirements => @show_apply_requirements) unless @show_apply_requirements.nil?
86
+ ret.merge!(:ApplyRequirements => @apply_requirements) unless @apply_requirements.nil?
87
+ ret.merge!(:SingleONetSearch => @single_onet) unless @single_onet.nil?
88
+ ret.merge!(:SiteEntity => @site_entity) unless @site_entity.nil?
89
+ ret.merge!(:SiteID => @site_id) unless @site_id.nil?
90
+ ret.merge!(:Skills => @skills) unless @skills.nil?
91
+ ret.merge!(:SpecificEducation => @specific_education) unless @specific_education.nil?
92
+ ret.merge!(:SpokenLanguage => @spoken_language) unless @spoken_language.nil?
93
+ ret.merge!(:Tags => @tags) unless @tags.nil?
94
+ ret.merge!(:TalentNetworkDID => @talent_network_did) unless @talent_network_did.nil?
95
+ ret.merge!(:UrlCompressionService => @url_compression_service) unless @url_compression_service.nil?
96
+ ret.merge!(:UseFacets => @use_facets) unless @use_facets.nil?
97
+ ret.merge!(:strcrit => @str_crit) unless @str_crit.nil?
98
+
99
+ return ret
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,22 @@
1
+ module Cb
2
+ class CbCategory
3
+ attr_accessor :code, :name, :language
4
+ def initialize(args={})
5
+ @code = args["Code"] || ""
6
+ @name = args["Name"]["#text"] || ""
7
+ @language = args["Name"]["@language"] || ""
8
+ end
9
+
10
+ def CategoryName()
11
+ return @name if @name.present?
12
+ end
13
+
14
+ def CategoryCode()
15
+ return @code if @code.present?
16
+ end
17
+
18
+ def CategoryLanguage()
19
+ return @language if @language.present?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,133 @@
1
+ module Cb
2
+ class CbCompany
3
+ attr_accessor :did, :name, :hh_name, :url, :size, :type, :year_founded,
4
+ :news_feed, :overview, :total_jobs, :headquarters, :host_sites, :s_drive,
5
+ :industry,
6
+
7
+ :image_file, :header_image, :footer_image, :logo, :photos, :my_photos,
8
+ :bright_cove_video,
9
+
10
+ :twitter_url, :linked_in_url, :facebook_url, :facebook_widget,
11
+ :linked_in_widget, :twitter_widget,
12
+
13
+ :benefits, :benefits_label, :history, :contact, :contact_label, :links,
14
+ :vision, :vision_label, :products, :products_label, :career_opps, :career_opps_label,
15
+ :culture, :culture_label, :addresses, :bulletin_board, :testimonials,
16
+ :college, :college_label, :diversity, :diversity_label, :people, :people_label,
17
+
18
+ :extra_custom_tab, :tab_header_bg_color, :tab_header_text_color, :tab_header_hover_color,
19
+ :side_bar_header_color, :button_color, :button_text_color, :gutter_bg_color,
20
+ :my_content_tabs, :info_tabs, :is_enhance, :is_military, :is_premium
21
+
22
+ def initialize(args = {})
23
+ return if args.nil?
24
+
25
+ # General
26
+ ################################################################
27
+ @did = args['CompanyDID'] || ''
28
+ @name = args['CompanyName'] || ''
29
+ @hh_name = args['HHName'] || ''
30
+ @url = args['URL'] || ''
31
+ @size = args['CompanySize'] || ''
32
+ @type = args['CompanyType'] || ''
33
+ @year_founded = args['YearFounded'] || ''
34
+ @news_feed = args['NewsFeed'] || ''
35
+ @overview = args['Overview'] || ''
36
+ @total_jobs = args['TotalNumberJobs'] || ''
37
+ @headquarters = args['Headquarter'] || ''
38
+ @host_sites = args['HostSites'] || ''
39
+ @s_drive = args['SDrive'] || ''
40
+ @industry = args['IndustryType'] || ''
41
+
42
+ # Images
43
+ ################################################################
44
+ @logo = args['CompanyLogo'] || ''
45
+ @header_image = args['HeaderImage'] || ''
46
+ @footer_image = args['FooterImage'] || ''
47
+ @image_file = args['ImageFile'] || ''
48
+
49
+ @photos = args['CompanyPhotos']['PhotoList'] || ''
50
+ @my_photos = args['MyPhotos'] || ''
51
+
52
+ # Videos
53
+ ################################################################
54
+ @bright_cove_video = args['BrightcoveVideo'] || ''
55
+
56
+ # Social sites
57
+ ################################################################
58
+ @facebook_url = args['FBPageURL'] || args['FacebookURL'] || ''
59
+ @facebook_widget = args['FacebookWidget'] || ''
60
+ @twitter_url = args['TwitterURL'] || ''
61
+ @twitter_widget = args['TwitterWidget'] || ''
62
+ @linked_in_url = args['LinkedURL'] || ''
63
+ @linked_in_widget = args['LinkedInWidget'] || ''
64
+
65
+ # Detailed information (blobs)
66
+ ################################################################
67
+ @history = args['HistoryBody'] || ''
68
+ @people = args['PeopleBody'] || ''
69
+ @people_label = args['PeopleLabel'] || ''
70
+ @contact = args['ContactBody'] || ''
71
+ @contact_label = args['ContactLabel'] || ''
72
+ @benefits = args['BenefitsBody'] || ''
73
+ @benefits_label = args['BenefitsLabel'] || ''
74
+ @vision = args['VisionBody'] || ''
75
+ @vision_label = args['VisionLabel'] || ''
76
+ @products = args['ProductsBody'] || ''
77
+ @products_label = args['ProductsLabel'] || ''
78
+ @career_opps = args['CareerOpportunitiesBody'] || ''
79
+ @career_opps_label = args['CareerOpportunitiesLabel'] || ''
80
+ @culture = args['CultureBody'] || ''
81
+ @culture_label = args['CultureLabel'] || ''
82
+ @bulletin_board = args['CompanyBulletinBoard']['bulletinboards'] || ''
83
+ @testimonials = args['Testimonials']['Testimonials'] || ''
84
+ @addresses = []
85
+ if args.has_key?('CompanyAddress')
86
+ unless args['CompanyAddress'].empty? || args['CompanyAddress']['AddressList'].nil?
87
+ args['CompanyAddress']['AddressList']['Address'].each do |cur_addr|
88
+ @addresses << CbCompany::CbAddress.new(cur_addr)
89
+ end
90
+ end
91
+ end
92
+ @college = args['CollegeBody'] || ''
93
+ @college_label = args['CollegeLabel'] || ''
94
+ @diversity = args['DiversityBody'] || ''
95
+ @diversity_label = args['DiversityLabel'] || ''
96
+ @links = args['CompanyLinksCollection']['companylinks'] || ''
97
+
98
+ # tabs, colors, buttons, headers, etc
99
+ ################################################################
100
+ @extra_custom_tab = args['ExtraCustomTab'] || ''
101
+ @tab_header_bg_color = args['TabHeaderBGColor'] || ''
102
+ @tab_header_text_color = args['TabHeaderTextColor'] || ''
103
+ @tab_header_hover_color = args['TabHeaderHoverColor'] || ''
104
+ @side_bar_header_color = args['SidebarHeaderColor'] || ''
105
+ @button_color = args['ButtonColor'] || ''
106
+ @button_text_color = args['ButtonTextColor'] || ''
107
+ @gutter_bg_color = args['GutterBGColor'] || ''
108
+ @my_content_tabs = args['MyContent']['MyContentTabs'] || ''
109
+ @info_tabs = args['InfoTabs']['InfoTabs'] || ''
110
+ @is_enhance = args['isEnhance'] || ''
111
+ @is_military = args['MilitaryIcon'] || ''
112
+ @is_premium = args['PremiumProfile'] || ''
113
+ end
114
+
115
+ # CbAddress # CbCompany has a collection of these
116
+ ################################################################
117
+ class CbAddress
118
+ attr_accessor :street, :city, :state, :country, :zip
119
+
120
+ def initialize(args = {})
121
+ begin
122
+ @street = args['Street'] || ''
123
+ @city = args['City'] || ''
124
+ @state = args['State'] || ''
125
+ @country = args['Country'] || ''
126
+ @zip = args['ZIPCode'] || ''
127
+ rescue
128
+ # failed to load address
129
+ end
130
+ end
131
+ end #CbAddress
132
+ end #CbCompany
133
+ end #Cb
@@ -0,0 +1,25 @@
1
+ module Cb
2
+ class CbEducation
3
+ attr_accessor :code, :text, :language
4
+
5
+ ##############################################################
6
+ ## This object stores Education Codes having to do with a
7
+ ## country. The API objects dealing with job, will populate
8
+ ## one or many of this object.
9
+ ##
10
+ ## For more information, please visit:
11
+ ## http://api.careerbuilder.com/v1/educationcodes
12
+ ##############################################################
13
+ def initialize(args = {})
14
+ return if args.nil?
15
+
16
+ @code = args['Code'] || ''
17
+ @language = args['Name']['@language'] unless args['Name'].nil?
18
+ @text = args['Name']['#text'] unless args['Name'].nil?
19
+
20
+ # I have got to find a better way to do this
21
+ @language ||= ''
22
+ @text ||= ''
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ module Cb
2
+ class CbEmployeeType
3
+
4
+ attr_accessor :code, :name, :language
5
+
6
+ def initialize(args={})
7
+ @code ||= args['Code'] || ''
8
+ @name ||= args['Name']["#text"] || ''
9
+ @language ||= args['Name']["@language"] || ''
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,67 @@
1
+ module Cb
2
+ class CbJob
3
+ attr_accessor :did, :title, :pay,
4
+ :company_name, :company_did, :company_details_url, :company_image_url, :company,
5
+ :description_teaser, :location, :distance, :latitude, :longitude,
6
+ :description, :requirements, :employment_type,
7
+ :details_url, :service_url, :similar_jobs_url, :apply_url,
8
+ :begin_date, :end_date, :posted_date,
9
+ :relevancy, :state, :city
10
+
11
+ ##############################################################
12
+ ## This general purpose object stores anything having to do
13
+ ## with a job. The API objects dealing with job, will populate
14
+ ## one or many of this object.
15
+ ##############################################################
16
+ def initialize(args = {})
17
+ return if args.nil?
18
+
19
+ # General
20
+ @did = args['DID'] || args['JobDID'] || ''
21
+ @title = args['JobTitle'] || args['Title'] || ''
22
+ @employment_type = args['EmploymentType'] || ''
23
+ @latitude = args['LocationLatitude'] || ''
24
+ @longitude = args['LocationLongitude'] || ''
25
+ @pay = args['Pay'] || ''
26
+
27
+ # Job Search related
28
+ @description_teaser = args['DescriptionTeaser'] || ''
29
+ @posted_date = args['PostedDate'] || ''
30
+ @distance = args['Distance'] || ''
31
+ @details_url = args['JobDetailsURL'] || ''
32
+ @service_url = args['JobServiceURL'] || ''
33
+ @location = args['Location'] || ''
34
+ @similar_jobs_url = args['SimilarJobsURL'] || ''
35
+
36
+ # Job Details related
37
+ @description = args['Description'] || args['JobDescription'] || ''
38
+ @requirements = args['JobRequirements'] || ''
39
+ @begin_date = args['BeginDate'] || ''
40
+ @end_date = args['EndDate'] || ''
41
+ @apply_url = args['ApplyURL'] || ''
42
+
43
+ # Company related
44
+ @company_name = args['Company'] || ''
45
+ @company_did = args['CompanyDID'] || ''
46
+ @company_details_url = args['CompanyDetailsURL'] || ''
47
+ @company_image_url = args['CompanyImageURL'] || ''
48
+
49
+ # Recommendations related
50
+ @relevancy = args['Relevancy'] || ''
51
+ @state = args['Location']['State'] unless args['Location'].nil? || args['Location']['State'].nil?
52
+ @city = args['Location']['City'] unless args['Location'].nil? || args['Location']['City'].nil?
53
+ @company_name = args['Company']['CompanyName'] unless args['Company'].nil? || args['Company']['CompanyName'].nil?
54
+ @company_details_url = args['Company']['CompanyDetailsURL'] unless args['Company'].nil? || args['Company']['CompanyDetailsURL'].nil?
55
+ end
56
+
57
+ def find_company
58
+ if @company
59
+ return @company
60
+ else
61
+ @company = Cb::CompanyApi.find_for self
62
+
63
+ return @company
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ module Cb
2
+ class CbJobApplication
3
+ attr_accessor :job_did, :site_id, :co_brand, :apply_url, :title, :total_questions,
4
+ :total_required_questions, :questions, :submit_service_url
5
+
6
+ ##############################################################
7
+ ## This general purpose object stores anything having to do
8
+ ## with an application. The API objects dealing with application,
9
+ ## will populate this object.
10
+ ##############################################################
11
+ def initialize(args = {})
12
+ return if args.nil?
13
+
14
+ @job_did = args['JobDID'] || ''
15
+ @site_id = args['SiteID'] || ''
16
+ @co_brand = args['CoBrand'] || ''
17
+ @apply_url = args['ApplyURL'] || ''
18
+ @title = args['JobTitle'] || ''
19
+ @total_questions = args['TotalQuestions'] || ''
20
+ @total_required_questions = args['TotalRequiredQuestions'] || ''
21
+ @questions = args['Questions'] || ''
22
+ @submit_service_url = args['ApplicationSubmitServiceURL'] || ''
23
+
24
+ #TODO
25
+ # Questions needs to be an array of data containers (of question)
26
+
27
+ end
28
+ end # CbJobApplication
29
+ end # Cb
@@ -0,0 +1,74 @@
1
+ require 'HTTParty'
2
+
3
+ module Cb::Utils
4
+ class Api
5
+ include HTTParty
6
+ base_uri 'http://api.careerbuilder.com'
7
+ #debug_output $stderr
8
+
9
+ def initialize
10
+ self.class.default_params :developerkey => Cb.configuration.dev_key,
11
+ :outputjson => Cb.configuration.use_json.to_s
12
+
13
+ self.class.default_timeout Cb.configuration.time_out
14
+ end
15
+
16
+ def cb_get(*args, &block)
17
+ self.class.get(*args, &block)
18
+ end
19
+
20
+ def append_api_responses(obj, resp)
21
+ if obj.respond_to?('cb_response')
22
+ meta_class = obj.cb_response
23
+ else
24
+ meta_class = Cb::Utils::MetaValues.new()
25
+ end
26
+
27
+ resp.each do | api_key, api_value |
28
+ meta_name = get_meta_name_for api_key
29
+
30
+ unless meta_name.empty?
31
+ if meta_name == 'errors' && api_value.is_a?(Hash)
32
+ api_value = api_value.values
33
+ elsif is_numeric?(api_value)
34
+ api_value = api_value.to_i
35
+ end
36
+
37
+ meta_class.class.send(:attr_reader, meta_name)
38
+ meta_class.instance_variable_set(:"@#{meta_name}", api_value)
39
+ end
40
+ end
41
+
42
+ obj.class.send(:attr_reader, 'cb_response')
43
+ obj.instance_variable_set(:@cb_response, meta_class)
44
+ end
45
+
46
+ private
47
+ #############################################################################
48
+
49
+ def is_numeric?(obj)
50
+ true if Float(obj) rescue false
51
+ end
52
+
53
+ def get_meta_name_for(api_key)
54
+ key_map = {
55
+ 'Errors' => 'errors',
56
+ 'TimeResponseSent' => 'time_sent',
57
+ 'TimeElapsed' => 'time_elapsed',
58
+ 'TotalPages' => 'total_pages',
59
+ 'TotalCount' => 'total_count',
60
+ 'FirstItemIndex' => 'first_item_index',
61
+ 'LastItemIndex' => 'last_item_index',
62
+ 'CountryCode' => 'country_code',
63
+ 'DeveloperKey' => 'developer_key',
64
+ 'SiteID' => 'site_id',
65
+ 'CoBrand' => 'co_brand',
66
+ 'CountLimit' => 'count_limit',
67
+ 'MinQualityLimit' => 'min_quality',
68
+ 'RecommendationsAvailable' => 'recs_available'
69
+ }
70
+
71
+ key_map["#{api_key}"] ||= ''
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,22 @@
1
+ module Cb::Utils::Country
2
+ # These aren't all country codes. We get it. Our naming scheme didn't hold up over time.
3
+ def self.get_supported
4
+ %w(AH BE CA CC CE CH CN CP CS CY DE DK E1 ER ES EU F1
5
+ FR GC GR I1 IE IN IT J1 JC JS LJ M1 MY NL NO PD PI
6
+ PL RM RO RX S1 SE SF SG T1 T2 UK US WH WM WR)
7
+ end
8
+
9
+ def self.is_valid?(country)
10
+ get_supported.include? country
11
+ end
12
+
13
+ def self.inject_convenience_methods
14
+ get_supported.each do | country |
15
+ unless self.respond_to? "#{country}"
16
+ self.define_singleton_method "#{country}" do
17
+ return country
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Cb::Utils::FluidAttributes
2
+ def fluid_attr_accessor(*names)
3
+ names.each do |name|
4
+ define_method :"#{name}" do | *args |
5
+ return instance_variable_get(:"@#{name}") if args.length == 0
6
+
7
+ if args.length == 1
8
+ instance_variable_set(:"@#{name}", args[0])
9
+ return self
10
+ end
11
+
12
+ raise ArgumentError.new("Wrong number of arguments (#{args.length} for 1)")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Cb::Utils
2
+ class MetaValues
3
+ # This class will be dynamically constructed at run time.
4
+ # I don't want values that don't make sense to the API call you made to be accessible
5
+ # I'm not dynamically creating the class because we may want to add functionality at some point
6
+
7
+ # This class, with its dynamically created attr_accr's will be dynamically appended to api
8
+ # entities, like job and company. It will contain things like errors, time elapsed, and
9
+ # any other meta values that the API may return.
10
+
11
+ # The mapping for allowed values, and what they translate to on this object live in Cb::Utils::Api
12
+ end
13
+ end
data/lib/cb/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Cb
2
+ VERSION = '0.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cb-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jesse Retchko
9
+ - Chris Little
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.8.1
31
+ - !ruby/object:Gem::Dependency
32
+ name: json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.7.6
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.7.6
47
+ description: Ruby wrapper for Careerbuilder Public API.
48
+ email:
49
+ - Jesse.Retchko@Careerbuilder.com
50
+ - Chris.Little@Careerbuilder.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - lib/cb/clients/category_api.rb
56
+ - lib/cb/clients/company_api.rb
57
+ - lib/cb/clients/education_api.rb
58
+ - lib/cb/clients/employee_types_api.rb
59
+ - lib/cb/clients/job_api.rb
60
+ - lib/cb/clients/job_application_api.rb
61
+ - lib/cb/clients/recommendation_api.rb
62
+ - lib/cb/config.rb
63
+ - lib/cb/job_search_criteria.rb
64
+ - lib/cb/models/cb_category.rb
65
+ - lib/cb/models/cb_company.rb
66
+ - lib/cb/models/cb_education.rb
67
+ - lib/cb/models/cb_employee_type.rb
68
+ - lib/cb/models/cb_job.rb
69
+ - lib/cb/models/cb_job_application.rb
70
+ - lib/cb/utils/api.rb
71
+ - lib/cb/utils/country.rb
72
+ - lib/cb/utils/fluid_attributes.rb
73
+ - lib/cb/utils/meta_values.rb
74
+ - lib/cb/version.rb
75
+ - lib/cb.rb
76
+ - README.md
77
+ homepage: http://api.careerbuilder.com
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.24
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Ruby wrapper around Careerbuilder Public API.
101
+ test_files: []