Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Saved Jobs API #238

Merged
merged 7 commits into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Version History
====
* All Version bumps are required to update this file as well!!
----
* 20.6.0 Add new saved jobs API (/consumer/saved-jobs)
* 20.5.0 Adding resume insights client
* 20.4.0 Add posting_date to recommendations for job model.
* 20.3.0 Add new resume list API (/consumer/resumes)
Expand Down Expand Up @@ -65,4 +66,4 @@ Version History
* 13.0.1 This change is to turn off metadata parsing and raise exception if the api response does not contain metadata.
* This means we can optionally control wether or not a specific API call expects metadata to come back
* 13.0.0 Adds a new resume recommendations call and removes the old one *(BREAKING)*
* https://github.com/cbdr/ruby-cb-api/pull/154/files
* https://github.com/careerbuilder/ruby-cb-api/pull/154/files
56 changes: 56 additions & 0 deletions lib/cb/clients/saved_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2016 CareerBuilder, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
require_relative 'base'
module Cb
module Clients
class SavedJobs < Base
class << self
def get(args = {})
uri = Cb.configuration.uri_saved_job
uri += "/#{ args[:id] }" if args[:id]
cb_client.cb_get(uri, headers: headers(args))
end

def create(args = {})
cb_client.cb_put(Cb.configuration.uri_saved_job,
body: body(args),
headers: headers(args))
end

def delete(args = {})
cb_client.cb_delete(uri_with_id(args), body: body(args), headers: headers(args))
end

def update(args = {})
cb_client.cb_post(uri_with_id(args), body: body(args), headers: headers(args))
end

private

def uri_with_id(args)
"#{ Cb.configuration.uri_saved_job }/#{ args[:id] }"
end

def body(args)
body = {}
body[:id] = args[:id] if args[:id]
body[:job_id] = args[:job_id] if args[:job_id]
body[:job_title] = args[:job_title] if args[:job_title]
body[:notes] = args[:notes] if args[:notes]
body[:status] = args[:status] if args[:status]
body[:application_date] = args[:application_date] if args[:application_date]
body[:site] = args[:site] if args[:site]
body.to_json
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/cb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def set_default_api_uris
@uri_saved_search_list ||= '/cbapi/savedsearches'
@uri_subscription_retrieve ||= '/v2/user/subscription/retrieve'
@uri_subscription_modify ||= '/v2/user/subscription'
@uri_saved_job ||= '/consumer/saved-jobs'
@uri_saved_job_search_create ||= '/v2/savedsearch/create'
@uri_state_list ||= '/ajax/citysuggest.aspx'
@uri_tn_join_questions ||= '/talentnetwork/config/join/questions'
Expand Down
4 changes: 4 additions & 0 deletions lib/cb/convenience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def resume_insights
Cb::Clients::ResumeInsights
end

def saved_jobs
Cb::Clients::SavedJobs
end

def saved_search
Cb::Clients::SavedSearch
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cb/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
module Cb
VERSION = '20.5.0'
VERSION = '20.6.0'
end
210 changes: 210 additions & 0 deletions spec/cb/clients/saved_jobs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# Copyright 2015 CareerBuilder, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
require 'spec_helper'

module Cb
describe Cb::Clients::SavedJobs do
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }
let(:post_data) { { 'job_id' => 'J1234567891234567890', 'notes' => 'these are my notes' } }
let(:saved_job) do
{
'id' => 'id', 'job_id' => 'J1234567891234567890', 'notes' => 'these are my notes',
'site' => 'US', 'status' => 'Saved',
'created_data' => '2016-03-02T14:29:30.617998-05:00', 'modified_date' => '2016-03-02T14:29:30.617998-05:00',
'job_expired' => 'false', 'job_expired_date' => '2017-03-28T03:29:27.367', 'application_date' => '1970-01-01T00:00:00'

}
end
let(:response) do
{
'data' => [data].flatten,
'page' => 1,
'page_size' => 1,
'total' => 1
}
end
let(:error_response) do
{
'errors' => [data].flatten,
'page' => -1,
'page_size' => 0,
'total' => 0
}
end
let(:headers) do
{
'Accept' => 'application/json',
'Accept-Encoding' => 'deflate, gzip',
'Authorization' => 'Bearer token',
'Content-Type' => 'application/json',
'Developerkey' => Cb.configuration.dev_key
}
end

context '#create' do
let(:data) { saved_job }
context 'when posting succeeds' do
it 'performs a put with a saved-job in json format' do
stub = stub_request(:put, uri)
.with(body: post_data.to_json, headers: headers)
.to_return(status: 200, body: response.to_json)
response = Cb::Clients::SavedJobs.create(job_id: 'J1234567891234567890', notes: 'these are my notes', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['data'].class).to eq(Array)
expect(response['data'][0]).to eq(data)
end
end

context 'when there is an error' do
let(:data) { { 'type' => '500', 'message' => 'Some kind of error happened', 'code' => '500' } }
it 'returns the error hash' do
stub_request(:put, uri)
.with(body: post_data.to_json, headers: headers)
.to_return(status: 500, body: error_response.to_json)
response = Cb::Clients::SavedJobs.create(job_id: 'J1234567891234567890', notes: 'these are my notes', oauth_token: 'token')
expect(response['errors'][0]).to eq(data)
end
end
end

context '#get' do
context 'asking for all saved jobs' do
let(:data) { [saved_job, saved_job, saved_job] }
it 'performs a get and returns the results hash' do
stub = stub_request(:get, uri)
.with(headers: headers)
.to_return(status: 200, body: response.to_json)

response = Cb::Clients::SavedJobs.get(oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['data'].class).to eq(Array)
expect(response['data'].length).to eq(3)
expect(response['data'][0]).to eq(saved_job)
end
end

context 'asking for a specific saved job' do
let(:data) { saved_job }
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs/id?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }

it 'performs a get and returns the coverletter asked for' do
stub = stub_request(:get, uri)
.with(headers: headers)
.to_return(status: 200, body: response.to_json)

response = Cb::Clients::SavedJobs.get(id: 'id', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['data'].class).to eq(Array)
expect(response['data'].length).to eq(1)
expect(response['data'][0]).to eq(saved_job)
end
end

context 'when the saved job is not found' do
let(:data) { { 'type' => '404', 'message' => 'Could not find the saved job specified', 'code' => '404' } }
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs/id?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }

it 'returns the error hash' do
stub = stub_request(:get, uri)
.with(headers: headers)
.to_return(status: 404, body: error_response.to_json)

response = Cb::Clients::SavedJobs.get(id: 'id', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['errors'].class).to eq(Array)
expect(response['errors'].length).to eq(1)
expect(response['errors'][0]).to eq(data)
end
end
end

context '#delete' do
context 'asking for a specific saved job' do
let(:data) { 'The saved job was deleted successfully' }
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs/id?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }

it 'performs a get and returns the coverletter asked for' do
stub = stub_request(:delete, uri)
.with(headers: headers)
.to_return(status: 200, body: response.to_json)

response = Cb::Clients::SavedJobs.delete(id: 'id', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['data'].class).to eq(Array)
expect(response['data'].length).to eq(1)
expect(response['data'][0]).to eq(data)
end
end

context 'when an error occurs' do
let(:data) { { 'type' => '500', 'message' => 'Could not find the saved job specified', 'code' => '404' } }
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs/id?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }

it 'returns the error hash' do
stub = stub_request(:delete, uri)
.with(headers: headers)
.to_return(status: 500, body: error_response.to_json)

response = Cb::Clients::SavedJobs.delete(id: 'id', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['errors'].class).to eq(Array)
expect(response['errors'].length).to eq(1)
expect(response['errors'][0]).to eq(data)
end
end
end

context '#update' do
let(:post_data) { { 'id' => 'id', 'notes' => 'notes' } }
context 'when updating an existing saved job' do
let(:data) { saved_job }
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs/id?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }

it 'performs a post and returns the updated coverletter asked for' do
stub = stub_request(:post, uri)
.with(body: post_data.to_json, headers: headers)
.to_return(status: 200, body: response.to_json)

response = Cb::Clients::SavedJobs.update(id: 'id', notes: 'notes', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['data'].class).to eq(Array)
expect(response['data'].length).to eq(1)
expect(response['data'][0]).to eq(data)
end
end

context 'when an error occurs' do
let(:data) { { 'type' => '500', 'message' => 'Could not find the saved job specified', 'code' => '404' } }
let(:uri) { "https://api.careerbuilder.com/consumer/saved-jobs/id?developerkey=#{ Cb.configuration.dev_key }&outputjson=true" }

it 'returns the error hash' do
stub = stub_request(:post, uri)
.with(body: post_data.to_json, headers: headers)
.to_return(status: 500, body: error_response.to_json)

response = Cb::Clients::SavedJobs.update(id: 'id', notes: 'notes', oauth_token: 'token')
expect(stub).to have_been_requested
expect(response.class).to eq(Hash)
expect(response['errors'].class).to eq(Array)
expect(response['errors'].length).to eq(1)
expect(response['errors'][0]).to eq(data)
end
end
end
end
end