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

Implement #update_application #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ group :development do
end

group :test do
gem "codeclimate-test-reporter", group: :test, require: nil
gem "codeclimate-test-reporter", require: false
gem "simplecov", require: false
end

gemspec
4 changes: 4 additions & 0 deletions lib/greenhouse_io/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def post_response(url, options)
self.class.post(url, options)
end

def patch_response(url, options)
self.class.patch(url, options)
end

def parse_json(response)
JSON.parse(response.body, symbolize_names: GreenhouseIo.configuration.symbolize_keys)
end
Expand Down
26 changes: 25 additions & 1 deletion lib/greenhouse_io/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def applications(id = nil, options = {})
get_from_harvest_api "/applications#{path_id(id)}", options
end

def update_application(id, options, on_behalf_of)
patch_to_harvest_api(
"/applications/#{id}",
options,
{ 'On-Behalf-Of' => on_behalf_of.to_s }
)
end

def offers_for_application(id, options = {})
get_from_harvest_api "/applications/#{id}/offers", options
end
Expand Down Expand Up @@ -96,7 +104,7 @@ def permitted_options(options)

def get_from_harvest_api(url, options = {})
response = get_response(url, {
:query => permitted_options(options),
:query => permitted_options(options),
:basic_auth => basic_auth
})

Expand Down Expand Up @@ -125,6 +133,22 @@ def post_to_harvest_api(url, body, headers)
end
end

def patch_to_harvest_api(url, body, headers)
response = patch_response(url, {
:body => JSON.dump(body),
:basic_auth => basic_auth,
:headers => headers
})

set_headers_info(response.headers)

if response.code == 200
parse_json(response)
else
raise GreenhouseIo::Error.new(response.code)
end
end

def set_headers_info(headers)
self.rate_limit = headers['x-ratelimit-limit'].to_i
self.rate_limit_remaining = headers['x-ratelimit-remaining'].to_i
Expand Down
44 changes: 44 additions & 0 deletions spec/fixtures/cassettes/client/update_application.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions spec/greenhouse_io/api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,50 @@
end
end

describe "#update_application" do
it "update the specified application" do
VCR.use_cassette('client/update_application') do
update_application = @client.update_application(
64087658,
{
source_id: 130370
},
509925
)
expect(update_application).to_not be_nil
expect(update_application[:source][:id]).to eq 130370
end
end

it "errors when given invalid On-Behalf-Of id" do
VCR.use_cassette('client/update_application_invalid_on_behalf_of') do
expect {
@client.update_application(
64087658,
{
source_id: 130370
},
101010
)
}.to raise_error(GreenhouseIo::Error)
end
end

it "errors when given an invalid application id" do
VCR.use_cassette('client/update_application_invalid_candidate_id') do
expect {
@client.update_application(
1010101,
{
source_id: 130370
},
509925
)
}.to raise_error(GreenhouseIo::Error)
end
end
end

describe "#scorecards" do
before do
VCR.use_cassette('client/scorecards') do
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "simplecov"
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
SimpleCov.start

require 'rubygems'
require 'bundler'
Expand Down