spear-cb-api 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/spear.rb +3 -0
- data/lib/spear/configuration.rb +55 -51
- data/lib/spear/plugins/model/application.rb +15 -0
- data/lib/spear/plugins/save_apis.rb +5 -2
- data/lib/spear/request.rb +26 -31
- data/lib/spear/resource/application.rb +24 -5
- data/lib/spear/resource/job.rb +2 -2
- data/lib/spear/resource/resume.rb +10 -17
- data/lib/spear/resource/talent_network.rb +4 -4
- data/lib/spear/resource/user.rb +6 -4
- data/lib/spear/structure/application/blank.rb +55 -0
- data/lib/spear/structure/application/state.rb +14 -0
- data/lib/spear/structure/application/submit.rb +11 -0
- data/lib/spear/structure/base.rb +14 -7
- data/lib/spear/structure/job/retrieve.rb +1 -1
- data/lib/spear/structure/job/search.rb +1 -1
- data/lib/spear/structure/user/check_existing.rb +1 -1
- data/lib/spear/version.rb +1 -1
- data/spear-cb-api.gemspec +5 -1
- data/spec/spear_spec.rb +22 -3
- data/spec/spec_helper.rb +2 -0
- metadata +46 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e87624498835a51e4a275ae593bba7b34b39b38
|
4
|
+
data.tar.gz: 7c9e0297fa3def264fc0eea62d455b33b0b8cb8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63c56495871130cd2b07dbde445532ad6cd96839d7c8390351ef253484ed40a87065e846587be287d28aa7b2a2eb752a65675cb107c1da6a242693289ac2a02b
|
7
|
+
data.tar.gz: 44ff0d4f658b74bd9aab92144619cde84c4d09a44a76fc55dc046ae62f1fc6a9212f62641fae31dcd31729e31e17f7bbf0153accdf64efccde8f66aad7736e6a
|
data/lib/spear.rb
CHANGED
@@ -38,6 +38,9 @@ module Spear
|
|
38
38
|
module Application
|
39
39
|
autoload :Create, 'spear/structure/application/create'
|
40
40
|
autoload :History, 'spear/structure/application/history'
|
41
|
+
autoload :State, 'spear/structure/application/state'
|
42
|
+
autoload :Blank, 'spear/structure/application/blank'
|
43
|
+
autoload :Submit, 'spear/structure/application/submit'
|
41
44
|
end
|
42
45
|
|
43
46
|
module Job
|
data/lib/spear/configuration.rb
CHANGED
@@ -2,70 +2,74 @@ module Spear
|
|
2
2
|
module Configuration
|
3
3
|
@@options = {}
|
4
4
|
|
5
|
-
# use https or http
|
6
|
-
def ssh?
|
7
|
-
@@options[:use_ssh].nil? ? true : @@options[:use_ssh]
|
8
|
-
end
|
9
|
-
|
10
|
-
def hostname
|
11
|
-
@@options[:hostname] || 'api.careerbuilder.com'
|
12
|
-
end
|
13
|
-
|
14
|
-
def port
|
15
|
-
@@options[:port] || 443
|
16
|
-
end
|
17
|
-
|
18
|
-
def version
|
19
|
-
@@options[:version] || "v2"
|
20
|
-
end
|
21
|
-
|
22
|
-
def test?
|
23
|
-
@@options[:use_test].nil? ? false : @@options[:use_test]
|
24
|
-
end
|
25
|
-
|
26
|
-
def dev_key
|
27
|
-
@@options[:dev_key]
|
28
|
-
end
|
29
|
-
|
30
|
-
# need save api info
|
31
|
-
def save_api?
|
32
|
-
@@options[:saving_api].nil? ? false : @@options[:saving_api]
|
33
|
-
end
|
34
|
-
|
35
|
-
def use_model?
|
36
|
-
@@options[:using_model].nil? ? false : @@options[:using_model]
|
37
|
-
end
|
38
|
-
|
39
|
-
def project
|
40
|
-
@@options[:project]
|
41
|
-
end
|
42
|
-
|
43
|
-
# def use_dummy?
|
44
|
-
# @@options[:using_dummy] || false
|
45
|
-
# end
|
46
|
-
|
47
5
|
def config(options={})
|
48
|
-
|
6
|
+
set_defaults(options)
|
49
7
|
|
50
8
|
raise Spear::ParametersRequired.new('DeveloperKey') if dev_key.nil?
|
51
|
-
|
9
|
+
if save_api? and (!Options.instance_methods.include?(:project) or project.nil?)
|
10
|
+
raise Spear::ParametersNotValid.new('You must specify a project name, if you want save api info.')
|
11
|
+
end
|
52
12
|
|
53
13
|
# add plugins to request
|
54
14
|
include_plugins
|
55
15
|
end
|
56
16
|
|
17
|
+
module Options
|
18
|
+
end
|
19
|
+
|
57
20
|
private
|
58
21
|
def include_plugins
|
59
22
|
Request.include Plugins::SaveApis if save_api?
|
23
|
+
Spear.extend(use_model? ? Plugins::Models : Resources)
|
24
|
+
end
|
60
25
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
26
|
+
def set_defaults(options)
|
27
|
+
defaults = {
|
28
|
+
use_test: false,
|
29
|
+
save_api: false,
|
30
|
+
use_model: false,
|
31
|
+
base_uri: 'https://api.careerbuilder.com',
|
32
|
+
time_out: 5,
|
33
|
+
uri_application_history: '/v1/application/history',
|
34
|
+
uri_application_create: '/cbapi/application',
|
35
|
+
uri_application_status: '/cn/wechat/getapplicationstatus.aspx',
|
36
|
+
uri_application_blank: '/v1/application/blank',
|
37
|
+
uri_application_submit: '/v1/application/submit',
|
38
|
+
uri_job_search: '/v2/jobsearch',
|
39
|
+
uri_job_retrieve: '/v2/job',
|
40
|
+
uri_resume_parse: '/v2/resume/parse',
|
41
|
+
uri_resume_create: '/v2/resume/create',
|
42
|
+
uri_resume_edit: '/v2/resume/edit',
|
43
|
+
uri_resume_upload: '/v2/resume/upload',
|
44
|
+
uri_resume_ownall: '/v2/resume/ownall',
|
45
|
+
uri_resume_retrieve: '/v2/resume/retrieve',
|
46
|
+
# job_did and format
|
47
|
+
uri_tn_join_form_question: '/talentnetwork/config/join/questions/%s/%s',
|
48
|
+
# format
|
49
|
+
uri_tn_menber_create: '/talentnetwork/member/create/%s',
|
50
|
+
uri_user_checkexisting: '/v2/user/checkexisting',
|
51
|
+
uri_user_create: '/v2/user/create',
|
52
|
+
uri_user_retrieve: '/v2/user/retrieve'
|
53
|
+
}
|
54
|
+
|
55
|
+
@@options = defaults.merge(options)
|
56
|
+
@@options[:base_uri] = 'https://wwwtest.api.careerbuilder.com' if @@options[:use_test]
|
57
|
+
|
58
|
+
set_option_readers
|
68
59
|
end
|
69
60
|
|
61
|
+
def set_option_readers
|
62
|
+
@@options.each do |k, v|
|
63
|
+
Options.class_eval {
|
64
|
+
if v.kind_of?(FalseClass) or v.kind_of?(TrueClass)
|
65
|
+
define_method(k.to_s + '?') { return v }
|
66
|
+
else
|
67
|
+
define_method(k) { return v }
|
68
|
+
end
|
69
|
+
}
|
70
|
+
end
|
71
|
+
# add these option method into Spear module
|
72
|
+
Spear.extend Options
|
73
|
+
end
|
70
74
|
end
|
71
75
|
end
|
@@ -14,6 +14,21 @@ module Spear
|
|
14
14
|
response = super(host_site, data)
|
15
15
|
Structure::Application::Create.new(response)
|
16
16
|
end
|
17
|
+
|
18
|
+
def application_status(app_dids=[])
|
19
|
+
response = super(app_dids)
|
20
|
+
Structure::Application::State.new(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def application_blank(job_did)
|
24
|
+
response = super(job_did)
|
25
|
+
Structure::Application::Blank.new(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def application_submit(job_did, questions=[])
|
29
|
+
response = super(job_did, questions)
|
30
|
+
Structure::Application::Submit.new(response)
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
19
34
|
end
|
@@ -30,8 +30,11 @@ module Spear
|
|
30
30
|
|
31
31
|
params[:request] = self.api_response.request.options[:body]
|
32
32
|
if params[:request].kind_of?(String)
|
33
|
-
|
34
|
-
|
33
|
+
params[:request]
|
34
|
+
# parse file api
|
35
|
+
.gsub!(/<FileBytes>(.*?)<\/FileBytes>/m, '<FileBytes>...</FileBytes>')
|
36
|
+
# apply job api
|
37
|
+
.gsub!(/<ResumeData>(.*?)<\/ResumeData>/m, '<ResumeData>...</ResumeData>')
|
35
38
|
elsif params[:request].kind_of?(Hash)
|
36
39
|
# upload file api
|
37
40
|
params[:request][:FileBytes] = '...'
|
data/lib/spear/request.rb
CHANGED
@@ -3,19 +3,25 @@ require 'active_model/callbacks'
|
|
3
3
|
|
4
4
|
module Spear
|
5
5
|
class Request
|
6
|
+
include HTTParty
|
6
7
|
extend ActiveModel::Callbacks
|
8
|
+
|
9
|
+
# httparty perference
|
10
|
+
default_timeout Spear.time_out
|
11
|
+
|
12
|
+
# callback
|
7
13
|
define_model_callbacks :execute, :only => [:before, :after]
|
8
14
|
|
9
|
-
attr_accessor :method, :query, :body, :
|
15
|
+
attr_accessor :method, :query, :body, :url
|
10
16
|
|
11
|
-
# params: {:body => {}, :query => {}
|
12
|
-
# exp: api_options: {:path => "/v1"}
|
17
|
+
# params: {:body => {}, :query => {}}
|
13
18
|
def initialize(method, endpoint, params={})
|
14
19
|
@method = method
|
15
20
|
@query = params[:query] || {}
|
16
21
|
@body = params[:body] || {}
|
22
|
+
@header = params[:header] || {}
|
17
23
|
@api_options = params[:api_options] || {}
|
18
|
-
@url =
|
24
|
+
@url = Spear.base_uri + endpoint
|
19
25
|
end
|
20
26
|
|
21
27
|
def execute
|
@@ -34,15 +40,15 @@ module Spear
|
|
34
40
|
begin
|
35
41
|
case @method
|
36
42
|
when :get
|
37
|
-
|
43
|
+
self.class.get(@url, query: splice_query)
|
38
44
|
when :post
|
39
|
-
|
45
|
+
self.class.post(@url, body: splice_body, query: @query)
|
40
46
|
when :upload_file
|
41
|
-
|
47
|
+
self.class.post(@url, body: @body, query: splice_query)
|
42
48
|
when :parse_file
|
43
|
-
|
49
|
+
self.class.post(@url, body: splice_body)
|
44
50
|
when :apply
|
45
|
-
|
51
|
+
self.class.post(@url, body: to_xml(@body), headers: splice_header)
|
46
52
|
else
|
47
53
|
raise Spear::ParametersNotValid.new("#{method} is not support.")
|
48
54
|
end
|
@@ -51,44 +57,33 @@ module Spear
|
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
|
-
# generate cb api host and version
|
55
|
-
def generate_resource
|
56
|
-
uri = URI("")
|
57
|
-
uri.scheme = Spear.ssh? ? 'https' : 'http'
|
58
|
-
uri.host = Spear.hostname
|
59
|
-
uri.port = Spear.port
|
60
|
-
|
61
|
-
# Some api endpoint have no version and fixed pattern.
|
62
|
-
if @api_options[:path].nil?
|
63
|
-
uri.path = "/#{Spear.version}"
|
64
|
-
else
|
65
|
-
uri.path = "#{@api_options[:path]}"
|
66
|
-
end
|
67
|
-
|
68
|
-
uri.to_s
|
69
|
-
end
|
70
|
-
|
71
60
|
# splice request body
|
72
61
|
def splice_body
|
73
62
|
@body[:DeveloperKey] = Spear.dev_key
|
74
|
-
@body[:Test] = Spear.
|
63
|
+
@body[:Test] = Spear.use_test? if need_test_element?
|
75
64
|
to_xml(@body)
|
76
65
|
end
|
77
66
|
|
78
67
|
# parse body from hash to xml format
|
79
68
|
def to_xml(body)
|
80
|
-
|
69
|
+
root = @api_options[:root_element].nil? ? 'Request' : @api_options[:root_element]
|
70
|
+
body.to_xml(root: root, skip_instruct: true, skip_types: true)
|
81
71
|
end
|
82
72
|
|
83
73
|
# splice query(url params) {:query => {}} with DeveloperKey and Test
|
84
74
|
def splice_query
|
85
75
|
@query[:DeveloperKey] = Spear.dev_key
|
86
|
-
@query[:Test] = Spear.
|
76
|
+
@query[:Test] = Spear.use_test? if need_test_element?
|
87
77
|
@query
|
88
78
|
end
|
89
79
|
|
90
|
-
def
|
91
|
-
@
|
80
|
+
def splice_header
|
81
|
+
@header[:DeveloperKey] = Spear.dev_key
|
82
|
+
end
|
83
|
+
|
84
|
+
# some api need Test element.
|
85
|
+
def need_test_element?
|
86
|
+
@api_options[:need_test_element].nil? ? true : @api_options[:need_test_element]
|
92
87
|
end
|
93
88
|
|
94
89
|
end
|
@@ -4,17 +4,36 @@ module Spear
|
|
4
4
|
def history(user_external_id)
|
5
5
|
raise Spear::ParametersRequired.new('UserExternalId') if user_external_id.blank?
|
6
6
|
|
7
|
-
Spear::Request.new(:get,
|
8
|
-
|
7
|
+
Spear::Request.new(:get, Spear.uri_application_history, {
|
8
|
+
query: {:ExternalID => user_external_id}}).execute
|
9
9
|
end
|
10
10
|
|
11
11
|
# Application Creation
|
12
12
|
def create_application(host_site, data={})
|
13
13
|
raise Spear::ParametersRequired.new('HostSite') if host_site.blank?
|
14
|
-
raise Spear::ParametersRequired.new(%w{JobID Resume Responses}) if data[:JobDID].blank? or data[:Resume].nil? or data[:Responses].nil?
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
if data[:JobDID].blank? or data[:Resume].nil? or data[:Responses].nil?
|
16
|
+
raise Spear::ParametersRequired.new(%w{JobID Resume Responses})
|
17
|
+
end
|
18
|
+
|
19
|
+
Spear::Request.new(:apply, Spear.uri_application_create, {
|
20
|
+
header: {:HostSite => host_site}, body: data}).execute
|
21
|
+
end
|
22
|
+
|
23
|
+
def application_status(app_dids=[])
|
24
|
+
Spear::Request.new(:get, Spear.uri_application_status, {
|
25
|
+
query: {sApplDID: app_dids.join(',')}}).execute
|
26
|
+
end
|
27
|
+
|
28
|
+
def application_blank(job_did)
|
29
|
+
raise Spear::ParametersRequired.new('JobDID') if job_did.blank?
|
30
|
+
Spear::Request.new(:get, Spear.uri_application_blank, {query: {JobDID: job_did}}).execute
|
31
|
+
end
|
32
|
+
|
33
|
+
def application_submit(job_did, questions=[])
|
34
|
+
raise Spear::ParametersRequired.new('JobDID') if job_did.blank?
|
35
|
+
Spear::Request.new(:post, Spear.uri_application_submit, {
|
36
|
+
api_options: {root_element: 'RequestApplication'}, body: {JobDID: job_did, Responses: questions}}).execute
|
18
37
|
end
|
19
38
|
end
|
20
39
|
end
|
data/lib/spear/resource/job.rb
CHANGED
@@ -2,7 +2,7 @@ module Spear
|
|
2
2
|
module Resource
|
3
3
|
module Job
|
4
4
|
def search_job(params={})
|
5
|
-
Spear::Request.new(:get,
|
5
|
+
Spear::Request.new(:get, Spear.uri_job_search, {:query => params}).execute
|
6
6
|
end
|
7
7
|
|
8
8
|
# job_id:
|
@@ -11,7 +11,7 @@ module Spear
|
|
11
11
|
def retrieve_job(job_id)
|
12
12
|
raise Spear::ParametersRequired.new('JobID') if job_id.blank?
|
13
13
|
|
14
|
-
Spear::Request.new(:get,
|
14
|
+
Spear::Request.new(:get, Spear.uri_job_retrieve, {:query => {:DID => job_id}}).execute
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -8,22 +8,18 @@ module Spear
|
|
8
8
|
end
|
9
9
|
|
10
10
|
file.rewind
|
11
|
-
Spear::Request.new(:post,
|
12
|
-
:
|
13
|
-
:FileName => file.original_filename,
|
14
|
-
:FileBytes => Base64.encode64(file.read)
|
15
|
-
}
|
16
|
-
}).execute
|
11
|
+
Spear::Request.new(:post, Spear.uri_resume_parse, {
|
12
|
+
body: {FileName: file.original_filename, FileBytes: Base64.encode64(file.read)}}).execute
|
17
13
|
end
|
18
14
|
|
19
15
|
def create_resume(data={})
|
20
|
-
Spear::Request.new(:post,
|
16
|
+
Spear::Request.new(:post, Spear.uri_resume_create, {body: data}).execute
|
21
17
|
end
|
22
18
|
|
23
19
|
def edit_resume(data={})
|
24
20
|
raise Spear::ParametersRequired.new('Resume ExternalId') if data[:ExternalID].blank?
|
25
21
|
|
26
|
-
Spear::Request.new(:post,
|
22
|
+
Spear::Request.new(:post, Spear.uri_resume_edit, {body: data}).execute
|
27
23
|
end
|
28
24
|
|
29
25
|
def upload_file(file, resume_external_id, user_external_id)
|
@@ -34,30 +30,27 @@ module Spear
|
|
34
30
|
raise Spear::ParametersRequired.new(%w{UserExternalId ResumeExternalId}) if user_external_id.blank? or resume_external_id.blank?
|
35
31
|
|
36
32
|
file.rewind
|
37
|
-
Spear::Request.new(:upload_file,
|
38
|
-
:body => {
|
39
|
-
:FileBytes => Base64.encode64(file.read)
|
40
|
-
},
|
33
|
+
Spear::Request.new(:upload_file, Spear.uri_resume_upload, {
|
34
|
+
:body => {:FileBytes => Base64.encode64(file.read)},
|
41
35
|
:query => {
|
42
36
|
:FileName => file.original_filename,
|
43
37
|
:ExternalID => resume_external_id,
|
44
|
-
:ExternalUserID => user_external_id
|
45
|
-
}
|
46
|
-
}).execute
|
38
|
+
:ExternalUserID => user_external_id }
|
39
|
+
}).execute
|
47
40
|
end
|
48
41
|
|
49
42
|
# list all of my resumes
|
50
43
|
def own_all(user_external_id, host_site)
|
51
44
|
raise Spear::ParametersRequired.new(%w{UserExternalId HostSite}) if user_external_id.blank? or host_site.blank?
|
52
45
|
|
53
|
-
Spear::Request.new(:get,
|
46
|
+
Spear::Request.new(:get, Spear.uri_resume_ownall, {
|
54
47
|
:query => {:ExternalUserID => user_external_id, :HostSite => host_site}}).execute
|
55
48
|
end
|
56
49
|
|
57
50
|
def retrieve_resume(resume_external_id, user_external_id)
|
58
51
|
raise Spear::ParametersRequired.new(%w{UserExternalId ResumeExternalId}) if user_external_id.blank? or resume_external_id.blank?
|
59
52
|
|
60
|
-
Spear::Request.new(:get,
|
53
|
+
Spear::Request.new(:get, Spear.uri_resume_retrieve, {
|
61
54
|
:query => {:ExternalUserID => user_external_id, :ExternalID => resume_external_id}}).execute
|
62
55
|
end
|
63
56
|
end
|
@@ -4,13 +4,13 @@ module Spear
|
|
4
4
|
def join_form_questions(talent_network_did)
|
5
5
|
raise Spear::ParametersRequired.new('TalentNetworkDID') if talent_network_did.blank?
|
6
6
|
|
7
|
-
Spear::Request.new(:get, '',
|
8
|
-
|
7
|
+
Spear::Request.new(:get, Spear.uri_tn_join_form_question % [talent_network_did, 'json'], {
|
8
|
+
api_options: {need_test_element: true}}).execute
|
9
9
|
end
|
10
10
|
|
11
11
|
def create_member(data={})
|
12
|
-
Spear::Request.new(:post, '', {
|
13
|
-
|
12
|
+
Spear::Request.new(:post, Spear.uri_tn_menber_create % ['json'], {
|
13
|
+
api_options: {need_test_element: true}, body: data}).execute
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/spear/resource/user.rb
CHANGED
@@ -3,18 +3,20 @@ module Spear
|
|
3
3
|
module User
|
4
4
|
def check_existing(email, password='')
|
5
5
|
if password.blank?
|
6
|
-
Spear::Request.new(:post,
|
6
|
+
Spear::Request.new(:post, Spear.uri_user_checkexisting, {body: {:Email => email}}).execute
|
7
7
|
else
|
8
|
-
Spear::Request.new(:post,
|
8
|
+
Spear::Request.new(:post, Spear.uri_user_checkexisting, {
|
9
|
+
body: {:Email => email, :Password => password}}).execute
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
def create_user(data={})
|
13
|
-
Spear::Request.new(:post,
|
14
|
+
Spear::Request.new(:post, Spear.uri_user_create, {body: data}).execute
|
14
15
|
end
|
15
16
|
|
16
17
|
def retrieve_user(user_external_id, password)
|
17
|
-
Spear::Request.new(:post,
|
18
|
+
Spear::Request.new(:post, Spear.uri_user_retrieve, {
|
19
|
+
body: {:ExternalID => user_external_id, :Password => password}}).execute
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Spear
|
2
|
+
module Structure
|
3
|
+
module Application
|
4
|
+
class Blank < Structure::Base
|
5
|
+
attr_reader :job_did, :job_title, :total_questions, :total_required_questions,
|
6
|
+
:application_submit_service_url, :apply_url
|
7
|
+
attr_accessor :questions
|
8
|
+
|
9
|
+
def initialize(response)
|
10
|
+
super(response)
|
11
|
+
|
12
|
+
blank_application = @root['BlankApplication']
|
13
|
+
|
14
|
+
unless blank_application.nil?
|
15
|
+
@job_did = blank_application['JobDID']
|
16
|
+
@job_title = blank_application['JobTitle']
|
17
|
+
@total_questions = blank_application['TotalQuestions']
|
18
|
+
@total_required_questions = blank_application['TotalRequiredQuestions']
|
19
|
+
@application_submit_service_url = blank_application['ApplicationSubmitServiceURL']
|
20
|
+
@apply_url = blank_application['ApplyURL']
|
21
|
+
|
22
|
+
@questions = generate_questions(blank_application['Questions']['Question'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Question
|
27
|
+
attr_accessor :id, :type, :required, :text
|
28
|
+
|
29
|
+
def initialize(id, type, required, text)
|
30
|
+
@id = id
|
31
|
+
@type = type
|
32
|
+
@required = required
|
33
|
+
@text = text
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def generate_questions(questions)
|
39
|
+
if !questions.nil?
|
40
|
+
if questions.kind_of?(Array)
|
41
|
+
questions.map {|q|
|
42
|
+
Question.new(q['QuestionID'], q['QuestionType'], q['IsRequired'], q['QuestionText'])
|
43
|
+
}
|
44
|
+
else # Hash
|
45
|
+
[] << Question.new(questions['QuestionID'],
|
46
|
+
questions['QuestionType'], questions['IsRequired'], questions['QuestionText'])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
[]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/spear/structure/base.rb
CHANGED
@@ -8,14 +8,21 @@ module Spear
|
|
8
8
|
raise Spear::ParametersRequired.new('Response') if response.nil?
|
9
9
|
|
10
10
|
@response = response
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
|
12
|
+
# Application Form Api return html string.
|
13
|
+
|
14
|
+
if response.kind_of?(Hash)
|
15
|
+
# get the root keyvalue of the hash
|
16
|
+
if response.to_h.has_key?('Errors')
|
17
|
+
@root = response.to_h
|
18
|
+
else
|
19
|
+
@root = response.to_h.first.last
|
20
|
+
end
|
21
|
+
|
22
|
+
# Application status is different
|
23
|
+
@status = @root["Status"] || @root['ApplicationStatus']
|
24
|
+
@error_message = get_error_message(@root)
|
16
25
|
end
|
17
|
-
@status = @root["Status"]
|
18
|
-
@error_message = get_error_message(@root)
|
19
26
|
end
|
20
27
|
|
21
28
|
def success?
|
@@ -4,9 +4,9 @@ module Spear
|
|
4
4
|
class CheckExisting < Structure::Base
|
5
5
|
attr_reader :external_id, :oauth_token, :check_status
|
6
6
|
|
7
|
-
# http://api.careerbuilder.com/UserInfo.aspx
|
8
7
|
def initialize(response)
|
9
8
|
super(response)
|
9
|
+
|
10
10
|
@external_id = @root["ResponseExternalID"]
|
11
11
|
@oauth_token = @root["ResponseOAuthToken"]
|
12
12
|
@check_status = @root['UserCheckStatus']
|
data/lib/spear/version.rb
CHANGED
data/spear-cb-api.gemspec
CHANGED
@@ -21,7 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "sucker_punch", "~> 1.0"
|
22
22
|
spec.add_dependency "httparty", "~> 0.13"
|
23
23
|
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.2"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
26
|
+
spec.add_development_dependency "pry-stack_explorer", "~> 0.4"
|
27
|
+
spec.add_development_dependency "pry-byebug", "~> 3.0"
|
28
|
+
|
25
29
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
30
|
spec.add_development_dependency "rake", "~> 10.4"
|
27
31
|
|
data/spec/spear_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
describe Spear do
|
2
2
|
before :each do
|
3
|
-
Spear.config({dev_key: 'xxx', project: 'ProjectName',
|
3
|
+
Spear.config({dev_key: 'xxx', project: 'ProjectName', use_model: true})
|
4
4
|
end
|
5
5
|
|
6
6
|
it "check user existing" do
|
@@ -9,7 +9,7 @@ describe Spear do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "application history" do
|
12
|
-
s = Spear.history('
|
12
|
+
s = Spear.history('J3H0YY6LLK553R3Z32Z')
|
13
13
|
puts s.response
|
14
14
|
end
|
15
15
|
|
@@ -19,7 +19,7 @@ describe Spear do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "retrieve job" do
|
22
|
-
s = Spear.retrieve_job('
|
22
|
+
s = Spear.retrieve_job('J3H0YY6LLK553R3Z32Z')
|
23
23
|
puts s.response
|
24
24
|
end
|
25
25
|
|
@@ -47,4 +47,23 @@ describe Spear do
|
|
47
47
|
})
|
48
48
|
puts s.response
|
49
49
|
end
|
50
|
+
|
51
|
+
it "get application status" do
|
52
|
+
s = Spear.application_status(['JAWS4L16LFXD7ZL87LLC', 'JAWW63876DWNQGSWZ384', 'JA4M44C77CDSR0QHTRJ6'])
|
53
|
+
puts s.response
|
54
|
+
end
|
55
|
+
|
56
|
+
it "get application blank" do
|
57
|
+
s = Spear.application_blank('J3H0YY6LLK553R3Z32Z')
|
58
|
+
puts s.response
|
59
|
+
end
|
60
|
+
|
61
|
+
it "application submit" do
|
62
|
+
s = Spear.application_submit('J3H0YY6LLK553R3Z32Z', [
|
63
|
+
{QuestionID: 'ApplicantName', ResponseText: 'Zhangfei'},
|
64
|
+
{QuestionID: 'ApplicantEmail', ResponseText: 'zhangfei@sina.com.cn'},
|
65
|
+
{QuestionID: 'Resume', ResponseText: 'test resume'}
|
66
|
+
])
|
67
|
+
puts s.response
|
68
|
+
end
|
50
69
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spear-cb-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CBluowei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -87,9 +87,6 @@ dependencies:
|
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '3.2'
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 3.2.0
|
93
90
|
type: :development
|
94
91
|
prerelease: false
|
95
92
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -97,9 +94,48 @@ dependencies:
|
|
97
94
|
- - "~>"
|
98
95
|
- !ruby/object:Gem::Version
|
99
96
|
version: '3.2'
|
100
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-stack_explorer
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.4'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.4'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
101
137
|
- !ruby/object:Gem::Version
|
102
|
-
version: 3.
|
138
|
+
version: '3.0'
|
103
139
|
- !ruby/object:Gem::Dependency
|
104
140
|
name: bundler
|
105
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,8 +194,11 @@ files:
|
|
158
194
|
- lib/spear/resource/talent_network.rb
|
159
195
|
- lib/spear/resource/user.rb
|
160
196
|
- lib/spear/resources.rb
|
197
|
+
- lib/spear/structure/application/blank.rb
|
161
198
|
- lib/spear/structure/application/create.rb
|
162
199
|
- lib/spear/structure/application/history.rb
|
200
|
+
- lib/spear/structure/application/state.rb
|
201
|
+
- lib/spear/structure/application/submit.rb
|
163
202
|
- lib/spear/structure/base.rb
|
164
203
|
- lib/spear/structure/job/embeded_class.rb
|
165
204
|
- lib/spear/structure/job/retrieve.rb
|