cb-api 0.0.3 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,48 @@
1
- cb-api
1
+ First things first. You're going to need to get a developer key from Careerbuilder. You can obtain a key at http://api.careerbuilder.com/RequestDevKey.aspx.
2
+
3
+ Now that you have a key, lets get to the good stuff.
4
+
5
+ You can find an example rails site that uses the gem here:
6
+ https://github.com/cbdr/ruby-cb-api-demo
7
+
8
+ Configuration
2
9
  ================
10
+ Set your dev key, and any other configuration settings in a place that will run prior to your API calls.
11
+
12
+ Cb.configure do | config |
13
+ config.dev_key = 'your-dev-key-goes-here'
14
+ config.time_out = 5
15
+ end
16
+
17
+ Job Search
18
+ ================
19
+ There's a couple ways to go about conducting a job search.
20
+
21
+ Option 1:
3
22
 
4
- A gem that's going to house our internal API interactions.
23
+ search = Cb.job_search_criteria.location('Atlanta, GA').radius(10).search()
5
24
 
25
+ Option 2:
6
26
 
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)
27
+ crit = Cb.job_search_criteria
28
+ crit.location = 'Atlanta, GA'
29
+ crit.radius = 10
30
+ search = crit.search()
31
+
32
+ Either way, you will get back an array of CbJob.
33
+
34
+ search.each | job | do
35
+ puts job.title
36
+ puts job.company_name
37
+ puts job.instance_variables
38
+ end
39
+
40
+ You will also get meta data regarding the search itself (helpful for pagination).
41
+
42
+ puts search.cb_response.total_pages
43
+ puts search.cb_response.total_count
44
+ puts search.cb_response.errors # Hopefully this is nil! If it's not nil, it will be an array of error messages.
45
+
46
+ Coming Soon
47
+ ================
48
+ More documentation!
data/lib/cb.rb CHANGED
@@ -26,6 +26,10 @@ module Cb
26
26
  Cb::JobSearchCriteria.new()
27
27
  end
28
28
 
29
+ def self.job_detail_criteria
30
+ Cb::JobApi::DetailsCriteria.new()
31
+ end
32
+
29
33
  def self.category
30
34
  Cb::CategoryApi
31
35
  end
@@ -2,6 +2,7 @@ require 'json'
2
2
 
3
3
  module Cb
4
4
  class JobApi
5
+
5
6
  #############################################################
6
7
  ## Run a job search against the given criteria
7
8
  ##
@@ -10,7 +11,6 @@ module Cb
10
11
  #############################################################
11
12
  def self.search(*args)
12
13
  args = args[0] if args.is_a?(Array) && args.count == 1
13
-
14
14
  my_api = Cb::Utils::Api.new()
15
15
  cb_response = my_api.cb_get(Cb.configuration.uri_job_search, :query => args)
16
16
  json_hash = JSON.parse(cb_response.response.body)
@@ -32,12 +32,10 @@ module Cb
32
32
  ## For detailed information around this API please visit:
33
33
  ## http://api.careerbuilder.com/JobInfo.aspx
34
34
  #############################################################
35
- def self.find_by_did(did, params = {})
35
+ def self.find_by_criteria(criteria)
36
36
  my_api = Cb::Utils::Api.new()
37
- params[:did] = did
38
- if params["showjobskin"].nil?
39
- params["showjobskin"] = "Full"
40
- end
37
+ params = my_api.class.criteria_to_hash(criteria)
38
+
41
39
  cb_response = my_api.cb_get(Cb.configuration.uri_job_find, :query => params)
42
40
  json_hash = JSON.parse(cb_response.response.body)
43
41
 
@@ -46,5 +44,22 @@ module Cb
46
44
 
47
45
  return job
48
46
  end
47
+
48
+ def self.find_by_did(did)
49
+ criteria = Cb::JobDetailsCriteria.new()
50
+ criteria.did = did
51
+ return find_by_criteria(criteria)
52
+ end
49
53
  end # JobApi
54
+
55
+ class JobDetailsCriteria
56
+ extend Cb::Utils::FluidAttributes
57
+
58
+ fluid_attr_accessor :did, :show_job_skin, :site_id, :cobrand, :show_apply_requirements
59
+
60
+ def find
61
+ Cb.job.find_by_did(self.did, self)
62
+ end
63
+ end
64
+
50
65
  end # Cb
@@ -6,97 +6,24 @@ module Cb
6
6
  class JobSearchCriteria
7
7
  extend Cb::Utils::FluidAttributes
8
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,
9
+ fluid_attr_accessor :advanced_grouping_mode, :boolean_operator, :category, :co_brand, :company_did,
10
+ :company_did_csv, :company_name, :company_name_boost_params, :country_code,
11
+ :education_code, :emp_type, :enable_company_collapse, :exclude_company_names,
12
+ :exclude_job_titles, :exclude_keywords, :exclude_national, :exclude_non_traditional_jobs,
13
+ :exclude_product_id, :facet_category, :facet_company, :facet_city, :facet_state,
14
14
  :facet_city_state, :facet_pay, :facet_normalized_company_did, :host_site,
15
15
  :include_company_children, :industry_codes, :job_title, :keywords, :location,
16
16
  :normalized_company_did, :normalized_company_did_boost_params,
17
- :normalized_company_name, :onet, :order_by, :order_direction, :page_number,
17
+ :normalized_company_name, :onet_code, :order_by, :order_direction, :page_number,
18
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,
19
+ :product_id, :radius, :records_per_group, :relocate_jobs, :soc_code, :school_site_id,
20
20
  :search_all_countries, :search_view, :show_categories, :show_apply_requirements,
21
- :apply_requirements, :single_onet, :site_entity, :site_id, :skills, :specific_education,
21
+ :apply_requirements, :single_onet_search, :site_entity, :site_id, :skills, :specific_education,
22
22
  :spoken_language, :tags, :talent_network_did, :url_compression_service, :use_facets,
23
23
  :str_crit
24
24
 
25
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
26
+ Cb::JobApi.search(Cb::Utils::Api.criteria_to_hash(self))
100
27
  end
101
28
  end
102
29
  end
@@ -1,4 +1,4 @@
1
- require 'HTTParty'
1
+ require 'httparty'
2
2
 
3
3
  module Cb::Utils
4
4
  class Api
@@ -43,6 +43,19 @@ module Cb::Utils
43
43
  obj.instance_variable_set(:@cb_response, meta_class)
44
44
  end
45
45
 
46
+ def self.criteria_to_hash(criteria)
47
+ params = Hash.new
48
+ if criteria.respond_to?(:instance_variables)
49
+ criteria.instance_variables.each do |var|
50
+ var_name = var.to_s
51
+ var_name.slice!(0)
52
+ var_name_hash_safe = var_name.camelize
53
+ params["#{var_name_hash_safe}"] = criteria.instance_variable_get(var)
54
+ end
55
+ end
56
+ return params
57
+ end
58
+
46
59
  private
47
60
  #############################################################################
48
61
 
@@ -1,7 +1,9 @@
1
1
  module Cb::Utils::FluidAttributes
2
+
2
3
  def fluid_attr_accessor(*names)
3
4
  names.each do |name|
4
- define_method :"#{name}" do | *args |
5
+
6
+ define_method :"#{name}" do | *args |
5
7
  return instance_variable_get(:"@#{name}") if args.length == 0
6
8
 
7
9
  if args.length == 1
@@ -11,6 +13,12 @@ module Cb::Utils::FluidAttributes
11
13
 
12
14
  raise ArgumentError.new("Wrong number of arguments (#{args.length} for 1)")
13
15
  end
16
+
17
+ define_method :"#{name}=" do |*args|
18
+ instance_variable_set(:"@#{name}", args[0]) if args.length == 1
19
+ return self
20
+ raise ArgumentError, "Wrong number of arguments (#{args.length} for 1)"
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -0,0 +1,10 @@
1
+ class String
2
+
3
+ # Modified from Rails ActiveSupport::Inflector
4
+ # Source: activesupport/lib/active_support/inflector/methods.rb, line 55
5
+ # Documentation: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize
6
+ def camelize()
7
+ self.sub!(/^[a-z\d]*/) { $&.capitalize }
8
+ self.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$2.capitalize}" }.gsub('/', '::')
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Cb
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cb-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,24 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-17 00:00:00.000000000 Z
13
+ date: 2013-05-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ! '>='
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.8.1
22
+ version: '0.10'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ! '>='
28
+ - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 0.8.1
30
+ version: '0.10'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: json
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -71,6 +71,7 @@ files:
71
71
  - lib/cb/utils/country.rb
72
72
  - lib/cb/utils/fluid_attributes.rb
73
73
  - lib/cb/utils/meta_values.rb
74
+ - lib/cb/utils/string.rb
74
75
  - lib/cb/version.rb
75
76
  - lib/cb.rb
76
77
  - README.md