Skip to content

Commit

Permalink
Merge pull request #33 from sul-dlss/post-params-in-body
Browse files Browse the repository at this point in the history
Post params in body
  • Loading branch information
ndushay authored Jan 29, 2020
2 parents 33ee799 + 1b81598 commit ea833c2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ Style/Documentation:
Exclude:
- 'spec/**/*'


Style/WordArray:
Enabled: false
8 changes: 6 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-12-03 15:41:39 -0800 using RuboCop version 0.74.0.
# on 2020-01-27 18:06:55 -0800 using RuboCop version 0.77.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Offense count: 2
Metrics/AbcSize:
Max: 34

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7
9 changes: 8 additions & 1 deletion lib/preservation/client/versioned_api_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ def post(path, params)
# @param params [Hash] optional params
def http_response(method, path, params)
req_url = api_version.present? ? "#{api_version}/#{path}" : path
resp = connection.send(method, req_url, params)
resp =
case method
when :get
connection.get(req_url, params)
when :post
request_json = params.to_json if params&.any?
connection.post(req_url, request_json, 'Content-Type' => 'application/json')
end
return resp.body if resp.success?

errmsg = ResponseErrorFormatter.format(response: resp, client_method_name: caller_locations.first.label)
Expand Down
7 changes: 7 additions & 0 deletions spec/preservation/client/versioned_api_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@
stub_request(:post, "#{prez_api_url}/#{path}").to_return(body: 'blank api version', status: 200)
expect(pc.send(:post, path, params)).to eq 'blank api version'
end
it 'request sends params in body and content-type in header' do
pc = described_class.new(connection: conn, api_version: '')
stub_request(:post, "#{prez_api_url}/#{path}")
.with(body: params.to_json, headers: { 'Content-Type' => 'application/json' })
.to_return(body: 'blank api version', status: 200)
expect(pc.send(:post, path, params)).to eq 'blank api version'
end

context 'when response status success' do
let(:resp_body) { JSON.generate(foo: 'bar') }
Expand Down

0 comments on commit ea833c2

Please sign in to comment.