Skip to content

Commit 772e090

Browse files
authored
Merge pull request #103 from honestica/proxy_settings
Added the possibility to set a proxy URL for the client
2 parents 63d0c6f + 52bcb14 commit 772e090

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ patient = FHIR::DSTU2::Patient.read('example')
8484
patient = client.read(FHIR::DSTU2::Patient, 'example').resource
8585
```
8686

87+
### Configuration
88+
89+
You can specify additional properties for the `client`:
90+
91+
```ruby
92+
client.additional_headers = {Prefer: 'return=representation'}
93+
client.proxy = 'https://your-proxy.com/'
94+
```
95+
8796
### CRUD Examples
8897
```ruby
8998
# read an existing patient with id "example"

lib/fhir_client/client.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Client
2323
attr_accessor :fhir_version
2424
attr_accessor :cached_capability_statement
2525
attr_accessor :additional_headers
26+
attr_accessor :proxy
2627
attr_accessor :exception_class
2728

2829
# Call method to initialize FHIR client. This method must be invoked
@@ -32,13 +33,14 @@ class Client
3233
# @param default_format Default Format Mime type
3334
# @return
3435
#
35-
def initialize(base_service_url, default_format: FHIR::Formats::ResourceFormat::RESOURCE_XML)
36+
def initialize(base_service_url, default_format: FHIR::Formats::ResourceFormat::RESOURCE_XML, proxy: nil)
3637
@base_service_url = base_service_url
3738
FHIR.logger.info "Initializing client with #{@base_service_url}"
3839
@use_format_param = false
3940
@exception_class = ClientException
4041
@default_format = default_format
4142
@fhir_version = :stu3
43+
@proxy = proxy
4244
set_no_auth
4345
end
4446

@@ -104,6 +106,8 @@ def set_no_auth
104106
@use_basic_auth = false
105107
@security_headers = {}
106108
@client = RestClient
109+
@client.proxy = proxy unless proxy.nil?
110+
@client
107111
end
108112

109113
# Set the client to use HTTP Basic Authentication
@@ -115,6 +119,8 @@ def set_basic_auth(client, secret)
115119
@use_oauth2_auth = false
116120
@use_basic_auth = true
117121
@client = RestClient
122+
@client.proxy = proxy unless proxy.nil?
123+
@client
118124
end
119125

120126
# Set the client to use Bearer Token Authentication
@@ -125,6 +131,8 @@ def set_bearer_token(token)
125131
@use_oauth2_auth = false
126132
@use_basic_auth = true
127133
@client = RestClient
134+
@client.proxy = proxy unless proxy.nil?
135+
@client
128136
end
129137

130138
# Set the client to use OpenID Connect OAuth2 Authentication
@@ -144,6 +152,7 @@ def set_oauth2_auth(client, secret, authorize_path, token_path, site = nil)
144152
raise_errors: true
145153
}
146154
client = OAuth2::Client.new(client, secret, options)
155+
client.connection.proxy(proxy) unless proxy.nil?
147156
@client = client.client_credentials.get_token
148157
end
149158

lib/fhir_client/ext/reference.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def read
5959
if relative? || reference == client.full_resource_url(resource: resource_class, id: reference_id)
6060
read_client = client
6161
else
62-
read_client = FHIR::Client.new base_uri, default_format: client.default_format
62+
read_client = FHIR::Client.new base_uri, default_format: client.default_format, proxy: client.proxy
6363
end
6464
resource_class.read(reference_id, read_client)
6565
end
@@ -69,7 +69,7 @@ def vread
6969
if relative? || reference == client.full_resource_url(resource: resource_class, id: reference_id)
7070
read_client = client
7171
else
72-
read_client = FHIR::Client.new base_uri, default_format: client.default_format
72+
read_client = FHIR::Client.new base_uri, default_format: client.default_format, proxy: client.proxy
7373
end
7474
resource_class.vread(reference_id, version_id, read_client)
7575
end

0 commit comments

Comments
 (0)