Skip to content

Commit

Permalink
Merge pull request #1616 from alphagov/594-bulk-upload-issue/replace-…
Browse files Browse the repository at this point in the history
…rest-client-with-httparty

594 bulk upload issue/replace rest client with httparty
  • Loading branch information
anatron authored Jan 8, 2024
2 parents 4e729aa + e11ffeb commit 8ce7fcd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ group :test do
gem "govuk_test"
gem "webmock"
end

gem "httparty", "~> 0.21.0"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ GEM
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
Expand Down Expand Up @@ -703,6 +706,7 @@ DEPENDENCIES
govuk_sidekiq
govuk_test
hashdiff
httparty (~> 0.21.0)
jquery-ui-rails
kaminari
pg
Expand Down
2 changes: 1 addition & 1 deletion app/lib/remote_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def sheet_data
end

def response
RestClient.get @csv_url
HTTParty.get @csv_url
end
end
9 changes: 7 additions & 2 deletions app/services/bulk_tagging/fetch_remote_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def call
response
process_spreadsheet
errors
rescue RestClient::Exception => e
rescue StandardError => e
GovukError.notify(e)
[spreadsheet_download_error]
end
Expand Down Expand Up @@ -57,7 +57,12 @@ def spreadsheet_download_error
end

def response
@response ||= RestClient.get tagging_spreadsheet.url
@response = HTTParty.get tagging_spreadsheet.url
if @response.code == 200
@response
else
raise StandardError, "error code from httparty"
end
end

def sheet_data
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/remote_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

it "raises an error when the URI is invalid" do
expect { described_class.new("not a URL").rows_with_headers }
.to raise_error RemoteCsv::ParsingError, 'URI::InvalidURIError: bad URI(is not URI?): "http://not a URL"'
.to raise_error RemoteCsv::ParsingError, 'URI::InvalidURIError: bad URI(is not URI?): "not a URL"'
end

it "raises an error when the connection failed" do
stub_request(:get, csv_url).to_timeout

expect { described_class.new(csv_url).rows_with_headers }
.to raise_error RemoteCsv::ParsingError, "RestClient::Exceptions::OpenTimeout: Timed out connecting to server"
.to raise_error RemoteCsv::ParsingError, "Net::OpenTimeout: execution expired"
end

it "raises an error when the CSV is malformed" do
Expand Down

0 comments on commit 8ce7fcd

Please sign in to comment.