Skip to content

Commit

Permalink
Merge branch 'DEX-0000-put-query' into 'master'
Browse files Browse the repository at this point in the history
[DEX-0000] feature: add put query support

Closes DEX-0000

See merge request nstmrt/rubygems/sbmt-strangler!22
  • Loading branch information
dsalahutdinov committed Jul 2, 2024
2 parents a20981d + 37bba89 commit c04c9b4
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.9.1] - 2024-07-02

### Added
- Add put request support

## [0.9.0] - 2024-06-06

### Added
Expand Down
3 changes: 3 additions & 0 deletions lib/sbmt/strangler/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def call(url, http_verb, payload: {}, headers: {})
transport.get_request(url, params: payload, headers: prepare_headers(headers))
when :post
transport.post_request(url, body: payload, headers: prepare_headers(headers))
when :put
transport.put_request(url, body: payload, headers: prepare_headers(headers))

else
raise "unsupported http verb - #{http_verb}"
end
Expand Down
9 changes: 8 additions & 1 deletion lib/sbmt/strangler/http/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def post_request(url, body: {}, headers: {})
end
end

def put_request(url, body: {}, headers: {})
with_error_handling(url) do
response = connection.put(url, body, headers)
Success(body: response.body, status: response.status, headers: response.headers)
end
end

private

attr_reader :http_options
Expand Down Expand Up @@ -54,7 +61,7 @@ def with_error_handling(url)
)

retry if (retry_count += 1) && retry_count <= http_options.retries_count

Failure(status: :bad_gateway)
rescue Faraday::UnprocessableEntityError, Faraday::ForbiddenError => error
Failure(body: error.response_body, status: error.response_status, headers: error.response_headers)
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/strangler/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module Strangler
VERSION = "0.9.0"
VERSION = "0.9.1"
end
end
19 changes: 19 additions & 0 deletions spec/fixtures/vcr/transport_put_success.yml

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

20 changes: 20 additions & 0 deletions spec/lib/sbmt/strangler/http/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,25 @@
end
end
end

context "with put request" do
let(:url) { "http://example.com/put_request" }

it "does put_request" do
expect(transport).to receive(:put_request).with(url, body: {}, headers: {})

client.call(url, :put, payload: {})
end

context "with http headers" do
let(:headers) { {"HTTP_AUTH_IDENTITY" => "uuid"} }

it "prepares headers" do
expect(transport).to receive(:put_request).with(url, body: {}, headers: {"AUTH-IDENTITY" => "uuid"})

client.call(url, :put, payload: {}, headers: headers)
end
end
end
end
end
19 changes: 19 additions & 0 deletions spec/lib/sbmt/strangler/http/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@
end
end

describe "#put_request" do
let(:url) { "http://example.com/put_request" }
let(:response) { {"key" => "value"} }

around do |example|
VCR.use_cassette("transport_put_success") do
example.run
end
end

it "does put_request" do
result = transport.put_request(url)

expect(result).to be_success
expect(result.value![:body]).to eq(response.to_json)
expect(result.value![:status]).to eq(200)
end
end

context "when TimeoutError" do
let(:connection) { instance_double(Faraday::Connection) }
let(:error_class) do
Expand Down

0 comments on commit c04c9b4

Please sign in to comment.