Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/fhir_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def get(path, headers = {})
FHIR.logger.info "GETTING: #{url}"
headers = clean_headers(headers) unless headers.empty?
if @use_oauth2_auth
# @client.refresh!
refresh_oauth2_session
begin
response = @client.get(url, headers: headers)
rescue => e
Expand Down Expand Up @@ -510,7 +510,7 @@ def post(path, resource, headers)
headers = clean_headers(headers)
payload = request_payload(resource, headers) if resource
if @use_oauth2_auth
# @client.refresh!
refresh_oauth2_session
begin
response = @client.post(url, headers: headers, body: payload)
rescue => e
Expand Down Expand Up @@ -557,7 +557,7 @@ def put(path, resource, headers)
headers = clean_headers(headers)
payload = request_payload(resource, headers) if resource
if @use_oauth2_auth
# @client.refresh!
refresh_oauth2_session
begin
response = @client.put(url, headers: headers, body: payload)
rescue => e
Expand Down Expand Up @@ -604,7 +604,7 @@ def patch(path, patchset, headers)
headers = clean_headers(headers)
payload = request_patch_payload(patchset, headers['Content-Type'])
if @use_oauth2_auth
# @client.refresh!
refresh_oauth2_session
begin
response = @client.patch(url, headers: headers, body: payload)
rescue => e
Expand Down Expand Up @@ -672,7 +672,7 @@ def delete(path, headers)
FHIR.logger.info "DELETING: #{url}"
headers = clean_headers(headers)
if @use_oauth2_auth
# @client.refresh!
refresh_oauth2_session
begin
response = @client.delete(url, headers: headers)
rescue => e
Expand Down Expand Up @@ -736,5 +736,10 @@ def build_url(path)
"#{base_path(path)}#{path}"
end
end

def refresh_oauth2_session
return unless @use_oauth2_auth
@client = @client.refresh! if (@client.expired? && @client.refresh_token)
end
end
end