Skip to content

Commit

Permalink
Refactor parse_json method
Browse files Browse the repository at this point in the history
Fixes "TypeError (no implicit conversion of URI::HTTPS into String)" exceptions with Ruby 3.x.
  • Loading branch information
jvendetti committed May 20, 2023
1 parent 0f1d766 commit 72ccf83
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'uri'
require 'open-uri'
require 'net/http'
require 'net/https'
require 'net/ftp'
Expand Down Expand Up @@ -29,6 +28,8 @@ class ApplicationController < ActionController::Base
EXPIRY_RECENT_MAPPINGS = 60 * 60 # 1:00 hours
EXPIRY_ONTOLOGY_SIMPLIFIED = 60 * 1 # 0:01 minute

RETRY_LIMIT = 1

$trial_license_initialized = false

if !$EMAIL_EXCEPTIONS.nil? && $EMAIL_EXCEPTIONS == true
Expand Down Expand Up @@ -579,22 +580,18 @@ def get_apikey()
end

def parse_json(uri)
uri = URI.parse(uri)
begin
response = open(uri, "Authorization" => "apikey token=#{get_apikey}").read
rescue Exception => error
response = Net::HTTP.get(URI(uri), { 'Authorization' => "apikey token=#{get_apikey}" })
rescue StandardError => e
@retries ||= 0
if @retries < 1 # retry once only
@retries += 1
retry
else
raise error
end
raise e unless @retries < RETRY_LIMIT

@retries += 1
retry
end
JSON.parse(response)
end


def get_batch_results(params)
begin
response = RestClient.post REST_URI_BATCH, params.to_json, :content_type => :json, :accept => :json, :authorization => "apikey token=#{get_apikey}"
Expand Down

0 comments on commit 72ccf83

Please sign in to comment.