cb-api 0.0.9 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cb/clients/application_api.rb +31 -35
- data/lib/cb/clients/job_api.rb +2 -1
- data/lib/cb/config.rb +4 -4
- data/lib/cb/models/cb_app.rb +59 -25
- data/lib/cb/models/cb_job.rb +2 -1
- data/lib/cb/utils/api.rb +11 -8
- data/lib/cb/utils/country.rb +16 -14
- data/lib/cb/utils/fluid_attributes.rb +20 -18
- data/lib/cb/version.rb +2 -2
- metadata +2 -2
@@ -1,22 +1,24 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'nokogiri'
|
3
2
|
|
4
3
|
module Cb
|
5
4
|
class ApplicationApi
|
6
|
-
|
5
|
+
#############################################################
|
7
6
|
## Get an application for a job
|
7
|
+
## Takes in either a Cb::CbJob, or a string (which should contain a did)
|
8
8
|
##
|
9
9
|
## For detailed information around this API please visit:
|
10
10
|
## http://api.careerbuilder.com/ApplicationInfo.aspx
|
11
11
|
#############################################################
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
def self.for_job(job)
|
13
|
+
did = job.did if job.is_a?(Cb::CbJob) else did = job
|
14
|
+
my_api = Cb::Utils::Api.new()
|
15
|
+
cb_response = my_api.cb_get(Cb.configuration.uri_application, :query => {:JobDID => did})
|
16
|
+
json_hash = JSON.parse(cb_response.response.body)
|
17
|
+
app_info = CbApp.new(json_hash['ResponseBlankApplication']['BlankApplication'])
|
18
|
+
my_api.append_api_responses(app_info, json_hash['ResponseBlankApplication'])
|
19
|
+
|
20
|
+
return app_info
|
21
|
+
end
|
20
22
|
|
21
23
|
#############################################################
|
22
24
|
## Submit a job application for a registered user
|
@@ -24,24 +26,20 @@ module Cb
|
|
24
26
|
## For detailed information around this API please visit:
|
25
27
|
## http://api.careerbuilder.com/ApplicationInfo.aspx
|
26
28
|
#############################################################
|
29
|
+
def self.submit_registered_app(app)
|
30
|
+
my_api = Cb::Utils::Api.new()
|
31
|
+
cb_response = my_api.cb_post(Cb.configuration.uri_application_registered, :body => application_xml)
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
rescue
|
40
|
-
status = false
|
41
|
-
end
|
42
|
-
|
43
|
-
return status
|
44
|
-
end
|
33
|
+
json_hash = JSON.parse(cb_response.response.body)
|
34
|
+
begin
|
35
|
+
json_hash = JSON.parse(cb_response.response.body)
|
36
|
+
status = json_hash['ResponseApplication']['ApplicationStatus'] == 'Complete (Test)' unless json_hash.empty?
|
37
|
+
rescue
|
38
|
+
status = false
|
39
|
+
end
|
40
|
+
|
41
|
+
return status
|
42
|
+
end
|
45
43
|
|
46
44
|
#############################################################
|
47
45
|
## Submit a job application
|
@@ -49,13 +47,11 @@ module Cb
|
|
49
47
|
## For detailed information around this API please visit:
|
50
48
|
## http://api.careerbuilder.com/ApplicationInfo.aspx
|
51
49
|
#############################################################
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
status = json_hash['ResponseApplication']['ApplicationStatus'] == 'Complete (Test)'
|
58
|
-
|
59
|
-
end
|
50
|
+
def self.submit_app(app)
|
51
|
+
my_api = Cb::Utils::Api.new()
|
52
|
+
cb_response = my_api.cb_post(Cb.configuration.uri_application_submit, :body => application_xml)
|
53
|
+
json_hash = cb_response.parsed_response
|
54
|
+
status = json_hash['ResponseApplication']['ApplicationStatus'] == 'Complete (Test)'
|
60
55
|
end
|
56
|
+
end
|
61
57
|
end
|
data/lib/cb/clients/job_api.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'cb/Utils/fluid_attributes.rb'
|
2
3
|
|
3
4
|
module Cb
|
4
5
|
class JobApi
|
@@ -55,7 +56,7 @@ module Cb
|
|
55
56
|
class JobDetailsCriteria
|
56
57
|
extend Cb::Utils::FluidAttributes
|
57
58
|
|
58
|
-
fluid_attr_accessor :did, :show_job_skin, :site_id, :cobrand, :show_apply_requirements
|
59
|
+
fluid_attr_accessor :did, :show_job_skin, :site_id, :lhs, :cobrand, :show_apply_requirements
|
59
60
|
|
60
61
|
def find
|
61
62
|
Cb.job.find_by_did(self.did, self)
|
data/lib/cb/config.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Cb
|
2
2
|
class Config
|
3
|
-
attr_accessor :dev_key, :time_out, :use_json, :host_site,
|
3
|
+
attr_accessor :dev_key, :debug_api, :time_out, :use_json, :host_site,
|
4
4
|
:uri_job_search, :uri_job_find,
|
5
5
|
:uri_company_find, :uri_job_category_search,
|
6
6
|
:uri_education_code, :uri_employee_types,
|
7
7
|
:uri_recommendation_for_job, :uri_recommendation_for_user,
|
8
8
|
:uri_recommendation_for_company,
|
9
9
|
:uri_application, :uri_application_submit,
|
10
|
-
:uri_application_registered
|
10
|
+
:uri_application_registered
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
Cb::Utils::Country.inject_convenience_methods
|
@@ -46,8 +46,7 @@ module Cb
|
|
46
46
|
:uri_recommendation_for_company => @uri_recommendation_for_company,
|
47
47
|
:uri_application => @uri_application,
|
48
48
|
:uri_application_submit => @uri_application_submit,
|
49
|
-
:uri_application_registered => @uri_application_registered
|
50
|
-
:job_did => @job_did
|
49
|
+
:uri_application_registered => @uri_application_registered
|
51
50
|
}
|
52
51
|
end
|
53
52
|
|
@@ -57,6 +56,7 @@ module Cb
|
|
57
56
|
def set_defaults
|
58
57
|
|
59
58
|
@dev_key = 'ruby-cb-api' # Get a developer key at http://api.careerbuilder.com
|
59
|
+
@debug_api = false
|
60
60
|
@time_out = 5
|
61
61
|
@use_json = true
|
62
62
|
@host_site = Cb.country.US
|
data/lib/cb/models/cb_app.rb
CHANGED
@@ -1,39 +1,73 @@
|
|
1
1
|
module Cb
|
2
2
|
class CbApp
|
3
|
-
attr_accessor
|
4
|
-
|
5
|
-
|
6
|
-
:question_id, :is_required, :question_type, :expected_response_format,
|
7
|
-
:question_text
|
3
|
+
attr_accessor :did, :title, :requirements,
|
4
|
+
:apply_url, :submit_service_url, :is_shared_apply,
|
5
|
+
:total_questions, :total_required_questions, :questions
|
8
6
|
#################################################################
|
9
7
|
## This general purpose object stores anything having to do with
|
10
|
-
|
11
|
-
|
8
|
+
## an application. The API objects dealing with application,
|
9
|
+
## will populate one or many of this object.
|
12
10
|
#################################################################
|
13
11
|
|
14
12
|
def initialize(args = {})
|
15
|
-
|
16
|
-
# App related
|
17
|
-
@response_blank_app = args['ResponseBlankApplication'] || ''
|
18
|
-
@blank_app = args['BlankApplication'] || ''
|
13
|
+
return if args.nil?
|
19
14
|
|
20
15
|
# Job Info related
|
21
|
-
@did
|
22
|
-
@title
|
16
|
+
@did = args['JobDID'] || ''
|
17
|
+
@title = args['JobTitle'] || ''
|
18
|
+
@requirements = args['Requirements'] || ''
|
23
19
|
|
24
|
-
#
|
25
|
-
@submit_service_url
|
26
|
-
@apply_url
|
27
|
-
|
20
|
+
# Apply URL related
|
21
|
+
@submit_service_url = args['ApplicationSubmitServiceURL'] || ''
|
22
|
+
@apply_url = (args['ApplyURL'].downcase == 'true')
|
23
|
+
@is_shared_apply = args['IsSharedApply'] || ''
|
28
24
|
|
29
25
|
# Question related
|
30
26
|
@total_questions = args['TotalQuestions'] || ''
|
31
27
|
@total_required_questions = args['TotalRequiredQuestions'] || ''
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
@total_questions = @total_questions.to_i if Cb::Utils::Api.is_numeric? @total_questions
|
29
|
+
@total_required_questions = @total_required_questions.to_i if Cb::Utils::Api.is_numeric? @total_required_questions
|
30
|
+
|
31
|
+
@questions = []
|
32
|
+
if args.has_key?('Questions')
|
33
|
+
unless args['Questions'].empty?
|
34
|
+
args['Questions']['Question'].each do | qq |
|
35
|
+
@questions << CbApp::CbQuestion.new(qq)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end # Initialize
|
40
|
+
end # CbApp
|
41
|
+
|
42
|
+
class CbApp::CbQuestion
|
43
|
+
attr_accessor :id, :type, :required, :format, :text
|
44
|
+
|
45
|
+
def initialize(args = {})
|
46
|
+
return if args.nil?
|
47
|
+
|
48
|
+
@id = args['QuestionID'] || ''
|
49
|
+
@type = args['QuestionType'] || ''
|
50
|
+
@required = (args['IsRequired'].downcase == 'true')
|
51
|
+
@format = args['ExpectedResponseFormat'] || ''
|
52
|
+
@text = args['QuestionText'] || ''
|
53
|
+
end
|
54
|
+
end # CbQuestion
|
55
|
+
|
56
|
+
class CbApp::CbAnswer
|
57
|
+
|
58
|
+
|
59
|
+
end # CbAnswer
|
60
|
+
end
|
61
|
+
#
|
62
|
+
#<Answers>
|
63
|
+
#<Answer>
|
64
|
+
#<QuestionID>MeetsRequirements</QuestionID>
|
65
|
+
# <AnswerID>Yes</AnswerID>
|
66
|
+
#<AnswerText>Yes</AnswerText>
|
67
|
+
# </Answer>
|
68
|
+
#<Answer>
|
69
|
+
#<QuestionID>MeetsRequirements</QuestionID>
|
70
|
+
# <AnswerID>No</AnswerID>
|
71
|
+
#<AnswerText>No</AnswerText>
|
72
|
+
# </Answer>
|
73
|
+
#</Answers>
|
data/lib/cb/models/cb_job.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Cb
|
2
2
|
class CbJob
|
3
|
-
attr_accessor :did, :title, :pay,
|
3
|
+
attr_accessor :did, :title, :pay, :job_skin,
|
4
4
|
:company_name, :company_did, :company_details_url, :company_image_url, :company,
|
5
5
|
:description_teaser, :location, :distance, :latitude, :longitude,
|
6
6
|
:description, :requirements, :employment_type,
|
@@ -23,6 +23,7 @@ module Cb
|
|
23
23
|
@latitude = args['LocationLatitude'] || ''
|
24
24
|
@longitude = args['LocationLongitude'] || ''
|
25
25
|
@pay = args['Pay'] || ''
|
26
|
+
@job_skin = args['JobSkin'] || ''
|
26
27
|
|
27
28
|
# Job Search related
|
28
29
|
@description_teaser = args['DescriptionTeaser'] || ''
|
data/lib/cb/utils/api.rb
CHANGED
@@ -4,9 +4,9 @@ module Cb::Utils
|
|
4
4
|
class Api
|
5
5
|
include HTTParty
|
6
6
|
base_uri 'http://api.careerbuilder.com'
|
7
|
-
#debug_output $stderr
|
8
7
|
|
9
8
|
def initialize
|
9
|
+
self.class.debug_output $stderr if Cb.configuration.debug_api
|
10
10
|
self.class.default_params :developerkey => Cb.configuration.dev_key,
|
11
11
|
:outputjson => Cb.configuration.use_json.to_s
|
12
12
|
|
@@ -14,6 +14,7 @@ module Cb::Utils
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def cb_get(*args, &block)
|
17
|
+
self.class.base_uri 'http://api.careerbuilder.com'
|
17
18
|
self.class.get(*args, &block)
|
18
19
|
end
|
19
20
|
|
@@ -35,10 +36,9 @@ module Cb::Utils
|
|
35
36
|
unless meta_name.empty?
|
36
37
|
if meta_name == 'errors' && api_value.is_a?(Hash)
|
37
38
|
api_value = api_value.values
|
38
|
-
elsif is_numeric?(api_value)
|
39
|
+
elsif self.class.is_numeric?(api_value)
|
39
40
|
api_value = api_value.to_i
|
40
41
|
end
|
41
|
-
|
42
42
|
meta_class.class.send(:attr_reader, meta_name)
|
43
43
|
meta_class.instance_variable_set(:"@#{meta_name}", api_value)
|
44
44
|
end
|
@@ -54,19 +54,22 @@ module Cb::Utils
|
|
54
54
|
criteria.instance_variables.each do |var|
|
55
55
|
var_name = var.to_s
|
56
56
|
var_name.slice!(0)
|
57
|
-
|
58
|
-
var_name_hash_safe = var_name
|
57
|
+
var_name_hash_safe = camelize(var_name)
|
59
58
|
params["#{var_name_hash_safe}"] = criteria.instance_variable_get(var)
|
60
59
|
end
|
61
60
|
end
|
62
61
|
return params
|
63
62
|
end
|
64
63
|
|
64
|
+
def self.is_numeric?(obj)
|
65
|
+
true if Float(obj) rescue false
|
66
|
+
end
|
67
|
+
|
65
68
|
private
|
66
69
|
#############################################################################
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
def self.camelize(input)
|
71
|
+
input.sub!(/^[a-z\d]*/) { $&.capitalize }
|
72
|
+
input.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$2.capitalize}" }.gsub('/', '::')
|
70
73
|
end
|
71
74
|
|
72
75
|
def get_meta_name_for(api_key)
|
data/lib/cb/utils/country.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
module Cb::Utils
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Cb::Utils
|
2
|
+
class Country
|
3
|
+
# These aren't all country codes. We get it. Our naming scheme didn't hold up over time.
|
4
|
+
def self.get_supported
|
5
|
+
%w(AH BE CA CC CE CH CN CP CS CY DE DK E1 ER ES EU F1
|
6
|
+
FR GC GR I1 IE IN IT J1 JC JS LJ M1 MY NL NO PD PI
|
6
7
|
PL RM RO RX S1 SE SF SG T1 T2 UK US WH WM WR)
|
7
|
-
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.is_valid?(country)
|
11
|
+
get_supported.include? country
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def self.inject_convenience_methods
|
15
|
+
get_supported.each do |country|
|
16
|
+
unless self.respond_to? "#{country}"
|
17
|
+
self.define_singleton_method "#{country}" do
|
18
|
+
return country
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
module Cb::Utils
|
1
|
+
module Cb::Utils
|
2
|
+
module FluidAttributes
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
def fluid_attr_accessor(*names)
|
5
|
+
names.each do |name|
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
define_method :"#{name}" do |*args|
|
8
|
+
return instance_variable_get(:"@#{name}") if args.length == 0
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
if args.length == 1
|
11
|
+
instance_variable_set(:"@#{name}", args[0])
|
12
|
+
return self
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
raise ArgumentError.new("Wrong number of arguments (#{args.length} for 1)")
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
define_method :"#{name}=" do |*args|
|
19
|
+
instance_variable_set(:"@#{name}", args[0]) if args.length == 1
|
20
|
+
return self
|
21
|
+
raise ArgumentError, "Wrong number of arguments (#{args.length} for 1)"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
24
26
|
end
|
data/lib/cb/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Cb
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
2
|
+
VERSION = '0.0.14'
|
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.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-05-
|
14
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|