@@ -30,7 +30,7 @@ class Client
30
30
# @return
31
31
#
32
32
def initialize ( baseServiceUrl )
33
- $LOG . info "Initializing client with #{ @baseServiceUrl } "
33
+ FHIR . logger . info "Initializing client with #{ @baseServiceUrl } "
34
34
@baseServiceUrl = baseServiceUrl
35
35
@use_format_param = false
36
36
@default_format = FHIR ::Formats ::ResourceFormat ::RESOURCE_XML
@@ -40,7 +40,7 @@ def initialize(baseServiceUrl)
40
40
41
41
# Set the client to use no authentication mechanisms
42
42
def set_no_auth
43
- $LOG . info "Configuring the client to use no authentication."
43
+ FHIR . logger . info "Configuring the client to use no authentication."
44
44
@use_oauth2_auth = false
45
45
@use_basic_auth = false
46
46
@security_headers = { }
@@ -49,7 +49,7 @@ def set_no_auth
49
49
50
50
# Set the client to use HTTP Basic Authentication
51
51
def set_basic_auth ( client , secret )
52
- $LOG . info "Configuring the client to use HTTP Basic authentication."
52
+ FHIR . logger . info "Configuring the client to use HTTP Basic authentication."
53
53
token = Base64 . encode64 ( "#{ client } :#{ secret } " )
54
54
value = "Basic #{ token } "
55
55
@security_headers = { 'Authorization' => value }
@@ -60,7 +60,7 @@ def set_basic_auth(client,secret)
60
60
61
61
# Set the client to use Bearer Token Authentication
62
62
def set_bearer_token ( token )
63
- $LOG . info "Configuring the client to use Bearer Token authentication."
63
+ FHIR . logger . info "Configuring the client to use Bearer Token authentication."
64
64
value = "Bearer #{ token } "
65
65
@security_headers = { 'Authorization' => value }
66
66
@use_oauth2_auth = false
@@ -74,7 +74,7 @@ def set_bearer_token(token)
74
74
# authorizePath -- absolute path of authorization endpoint
75
75
# tokenPath -- absolute path of token endpoint
76
76
def set_oauth2_auth ( client , secret , authorizePath , tokenPath )
77
- $LOG . info "Configuring the client to use OpenID Connect OAuth2 authentication."
77
+ FHIR . logger . info "Configuring the client to use OpenID Connect OAuth2 authentication."
78
78
@use_oauth2_auth = true
79
79
@use_basic_auth = false
80
80
@security_headers = { }
@@ -146,7 +146,7 @@ def get_oauth2_metadata_from_conformance
146
146
end
147
147
end
148
148
rescue Exception => e
149
- $LOG . error 'Failed to locate SMART-on-FHIR OAuth2 Security Extensions.'
149
+ FHIR . logger . error 'Failed to locate SMART-on-FHIR OAuth2 Security Extensions.'
150
150
end
151
151
options . delete_if { |k , v |v . nil? }
152
152
options . clear if options . keys . size !=2
@@ -199,15 +199,15 @@ def fhir_headers(options={})
199
199
end
200
200
201
201
def parse_reply ( klass , format , response )
202
- $LOG . info "Parsing response with {klass: #{ klass } , format: #{ format } , code: #{ response . code } }."
202
+ FHIR . logger . info "Parsing response with {klass: #{ klass } , format: #{ format } , code: #{ response . code } }."
203
203
return nil if ![ 200 , 201 ] . include? response . code
204
204
res = nil
205
205
begin
206
206
res = FHIR . from_contents ( response . body )
207
207
res . client = self if !res . nil?
208
- $LOG . warn "Expected #{ klass } but got #{ res . class } " if res . class !=klass
208
+ FHIR . logger . warn "Expected #{ klass } but got #{ res . class } " if res . class !=klass
209
209
rescue Exception => e
210
- $LOG . error "Failed to parse #{ format } as resource #{ klass } : #{ e . message } %n #{ e . backtrace . join ( "\n " ) } #{ response } "
210
+ FHIR . logger . error "Failed to parse #{ format } as resource #{ klass } : #{ e . message } %n #{ e . backtrace . join ( "\n " ) } #{ response } "
211
211
nil
212
212
end
213
213
res
@@ -290,7 +290,7 @@ def scrubbed_response_headers(result)
290
290
291
291
def get ( path , headers )
292
292
url = URI ( build_url ( path ) ) . to_s
293
- $LOG . info "GETTING: #{ url } "
293
+ FHIR . logger . info "GETTING: #{ url } "
294
294
headers = clean_headers ( headers )
295
295
if @use_oauth2_auth
296
296
# @client.refresh!
@@ -311,7 +311,7 @@ def get(path, headers)
311
311
:headers => response . headers ,
312
312
:body => response . body
313
313
}
314
- $LOG . info "GET - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
314
+ FHIR . logger . info "GET - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
315
315
@reply = FHIR ::ClientReply . new ( req , res )
316
316
else
317
317
headers . merge! ( @security_headers ) if @use_basic_auth
@@ -321,7 +321,7 @@ def get(path, headers)
321
321
response = e . response if e . response
322
322
end
323
323
324
- $LOG . info "GET - Request: #{ response . request . to_json } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
324
+ FHIR . logger . info "GET - Request: #{ response . request . to_json } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
325
325
response . request . args [ :path ] = response . request . args [ :url ] . gsub ( @baseServiceUrl , '' )
326
326
headers = response . headers . inject ( { } ) { |h , ( k , v ) | h [ k . to_s . gsub ( '_' , '-' ) ] = v . to_s ; h }
327
327
res = {
@@ -336,7 +336,7 @@ def get(path, headers)
336
336
337
337
def post ( path , resource , headers )
338
338
url = URI ( build_url ( path ) ) . to_s
339
- $LOG . info "POSTING: #{ url } "
339
+ FHIR . logger . info "POSTING: #{ url } "
340
340
headers = clean_headers ( headers )
341
341
payload = request_payload ( resource , headers ) if resource
342
342
if @use_oauth2_auth
@@ -358,12 +358,12 @@ def post(path, resource, headers)
358
358
:headers => response . headers ,
359
359
:body => response . body
360
360
}
361
- $LOG . info "POST - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
361
+ FHIR . logger . info "POST - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
362
362
@reply = FHIR ::ClientReply . new ( req , res )
363
363
else
364
364
headers . merge! ( @security_headers ) if @use_basic_auth
365
365
@client . post ( url , payload , headers ) { |response , request , result |
366
- $LOG . info "POST - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
366
+ FHIR . logger . info "POST - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
367
367
request . args [ :path ] = url . gsub ( @baseServiceUrl , '' )
368
368
res = {
369
369
:code => result . code ,
@@ -377,7 +377,7 @@ def post(path, resource, headers)
377
377
378
378
def put ( path , resource , headers )
379
379
url = URI ( build_url ( path ) ) . to_s
380
- $LOG . info "PUTTING: #{ url } "
380
+ FHIR . logger . info "PUTTING: #{ url } "
381
381
headers = clean_headers ( headers )
382
382
payload = request_payload ( resource , headers ) if resource
383
383
if @use_oauth2_auth
@@ -399,12 +399,12 @@ def put(path, resource, headers)
399
399
:headers => response . headers ,
400
400
:body => response . body
401
401
}
402
- $LOG . info "PUT - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
402
+ FHIR . logger . info "PUT - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
403
403
@reply = FHIR ::ClientReply . new ( req , res )
404
404
else
405
405
headers . merge! ( @security_headers ) if @use_basic_auth
406
406
@client . put ( url , payload , headers ) { |response , request , result |
407
- $LOG . info "PUT - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
407
+ FHIR . logger . info "PUT - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
408
408
request . args [ :path ] = url . gsub ( @baseServiceUrl , '' )
409
409
res = {
410
410
:code => result . code ,
@@ -418,7 +418,7 @@ def put(path, resource, headers)
418
418
419
419
def patch ( path , patchset , headers )
420
420
url = URI ( build_url ( path ) ) . to_s
421
- $LOG . info "PATCHING: #{ url } "
421
+ FHIR . logger . info "PATCHING: #{ url } "
422
422
headers = clean_headers ( headers )
423
423
payload = request_patch_payload ( patchset , headers [ 'format' ] )
424
424
if @use_oauth2_auth
@@ -440,13 +440,13 @@ def patch(path, patchset, headers)
440
440
:headers => response . headers ,
441
441
:body => response . body
442
442
}
443
- $LOG . info "PATCH - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
443
+ FHIR . logger . info "PATCH - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
444
444
@reply = FHIR ::ClientReply . new ( req , res )
445
445
else
446
446
headers . merge! ( @security_headers ) if @use_basic_auth
447
447
# url = 'http://requestb.in/o8juy3o8'
448
448
@client . patch ( url , payload , headers ) { |response , request , result |
449
- $LOG . info "PATCH - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
449
+ FHIR . logger . info "PATCH - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
450
450
request . args [ :path ] = url . gsub ( @baseServiceUrl , '' )
451
451
res = {
452
452
:code => result . code ,
@@ -460,7 +460,7 @@ def patch(path, patchset, headers)
460
460
461
461
def delete ( path , headers )
462
462
url = URI ( build_url ( path ) ) . to_s
463
- $LOG . info "DELETING: #{ url } "
463
+ FHIR . logger . info "DELETING: #{ url } "
464
464
headers = clean_headers ( headers )
465
465
if @use_oauth2_auth
466
466
# @client.refresh!
@@ -481,12 +481,12 @@ def delete(path, headers)
481
481
:headers => response . headers ,
482
482
:body => response . body
483
483
}
484
- $LOG . info "DELETE - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
484
+ FHIR . logger . info "DELETE - Request: #{ req . to_s } , Response: #{ response . body . force_encoding ( "UTF-8" ) } "
485
485
@reply = FHIR ::ClientReply . new ( req , res )
486
486
else
487
487
headers . merge! ( @security_headers ) if @use_basic_auth
488
488
@client . delete ( url , headers ) { |response , request , result |
489
- $LOG . info "DELETE - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
489
+ FHIR . logger . info "DELETE - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
490
490
request . args [ :path ] = url . gsub ( @baseServiceUrl , '' )
491
491
res = {
492
492
:code => result . code ,
@@ -501,9 +501,9 @@ def delete(path, headers)
501
501
def head ( path , headers )
502
502
headers . merge! ( @security_headers ) unless @security_headers . blank?
503
503
url = URI ( build_url ( path ) ) . to_s
504
- $LOG . info "HEADING: #{ url } "
504
+ FHIR . logger . info "HEADING: #{ url } "
505
505
RestClient . head ( url , headers ) { |response , request , result |
506
- $LOG . info "HEAD - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
506
+ FHIR . logger . info "HEAD - Request: #{ request . to_json } , Response: #{ response . force_encoding ( "UTF-8" ) } "
507
507
request . args [ :path ] = url . gsub ( @baseServiceUrl , '' )
508
508
res = {
509
509
:code => result . code ,
0 commit comments