Skip to content

Instantly share code, notes, and snippets.

@reiro
Created November 7, 2019 10:27
Show Gist options
  • Save reiro/8c73c92e9f4e93c66fadaf84c882e3c1 to your computer and use it in GitHub Desktop.
Save reiro/8c73c92e9f4e93c66fadaf84c882e3c1 to your computer and use it in GitHub Desktop.
# first case
def get_data(endpoint = '/match')
headers = { 'Content-Type' => 'application/json' }
auth = { username: RADAR_CONFIG['username'], password: RADAR_CONFIG['password'] }
raise Net::ReadTimeout if @retries < 2
self.class.get(endpoint, headers: headers, basic_auth: auth, query: { url: @site_url })
end
# second case
def perform
debugger
if @retries < 2
resp = OpenStruct.new(success: false, code: 504)
else
resp = get_data
end
if @success = resp.success?
@perfect_matches = JSON(resp.body)['perfect_matches']
@other_matches = JSON(resp.body)['other_matches']
else
if resp.code == 504 && (@retries += 1) <= 2
perform
else
@error_code = resp.code
@error_message = resp.message
end
end
rescue Net::ReadTimeout => e
if (@retries += 1) <= 2
retry
else
@error_message = e.message
end
rescue => e
@error_message = e.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment