lifen_fhir 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 444903207c6344dafb7a9fc38f6bec501fa136c4
4
- data.tar.gz: 823d8c0d7bd31e27c15f6d39cc31ebdf8d2ecd35
3
+ metadata.gz: 4f268ed9c624f69baa94cf0c7b9ad04cf5778ffc
4
+ data.tar.gz: cfdeb52172b4385d3fce6a0a1f497931156669d2
5
5
  SHA512:
6
- metadata.gz: 4bc7ee300eb9427f5100c08e996e406d2d14a4235b8e4340543c065c727a656dae4c610e731e174f532fe8bbbd67a9eb4f8605598ec2b3a14b4a81952f929001
7
- data.tar.gz: c6a2b3e3baf246bc3494e1e7feff523b14563f31a325bfe8a743e6d391ea5912626c0a2a85bfcad28a90301c89efc7b844d53dfbaaaf900e65ed5636e68fa5bb
6
+ metadata.gz: '003841d9ab0e8df08ae247d1c5d7c9b05c42e095af4c6c298778e1de768527f0f697679f95249a516e39240093cfb79d0aa3e1e8711d0ea59c012bce2b6185d3'
7
+ data.tar.gz: f05094f969f7c04dd8b8b5ba7774c89c21c6e84870b44a291bcac42cf5a9e9c91c394389d733c662d5aa04306e381e29060fcbf0a5e663c610cd91f48299e007
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.5.0
2
+ -----
3
+
4
+ - Added custom logger and rails logger integration
5
+
1
6
  0.4.2
2
7
  -----
3
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifen_fhir (0.4.2)
4
+ lifen_fhir (0.5.0)
5
5
  faraday (>= 0.9)
6
6
  inflecto
7
7
  virtus (>= 1.0)
data/README.md CHANGED
@@ -31,12 +31,14 @@ LifenFhir.configure do |config|
31
31
 
32
32
  # optionnal
33
33
  config.proxy_url = "http://my.proxy.fr/"
34
+ config.logger = Logger.new
34
35
  end
35
36
  ```
36
37
 
37
38
  Optionnal configuration:
38
39
 
39
- - `proxy_url`: enables you to route all your requests via a proxy
40
+ - `proxy_url`: route all your requests via a proxy
41
+ - `logger`: log all requests to a custom logger (on Rails, `Rails.logger` is selected automatically)
40
42
 
41
43
  ### Internal
42
44
 
@@ -1,6 +1,8 @@
1
1
  module LifenFhir
2
2
  class Client
3
3
 
4
+ LOGGED_INFO_STATUS = [200, 201]
5
+
4
6
  def request(mode, url, params = {})
5
7
  before_request
6
8
 
@@ -17,6 +19,7 @@ module LifenFhir
17
19
  req.body = JSON.generate(params)
18
20
  end
19
21
 
22
+ handle_logger(response)
20
23
  handle_errors(response, params)
21
24
 
22
25
  handle_response(response)
@@ -47,6 +50,14 @@ module LifenFhir
47
50
  end
48
51
  end
49
52
 
53
+ def handle_logger(response)
54
+ if LOGGED_INFO_STATUS.include? response.status
55
+ logger.info "*** [LIFEN] Success on #{response.env.method.upcase} '#{response.env.url}'"
56
+ else
57
+ logger.fatal "*** [LIFEN] #{response.status} Error on #{response.env.method.upcase} '#{response.env.url}'"
58
+ end
59
+ end
60
+
50
61
  def handle_response(response)
51
62
  if response.headers['Content-Type'].match "json"
52
63
  JSON.parse response.body
@@ -77,6 +88,10 @@ module LifenFhir
77
88
  LifenFhir.configuration.proxy_url
78
89
  end
79
90
 
91
+ def logger
92
+ LifenFhir.configuration.logger
93
+ end
94
+
80
95
  def before_request
81
96
  end
82
97
 
@@ -1,7 +1,19 @@
1
1
  module LifenFhir
2
2
  class Configuration
3
3
 
4
- attr_accessor :site, :application_access_token, :proxy_url
4
+ attr_accessor :site
5
+
6
+ attr_accessor :application_access_token
7
+
8
+ attr_accessor :proxy_url
9
+
10
+ # Logger used by Lifen FHIR. In Rails, this is the Rails logger, otherwise
11
+ # Lifen FHIR provides its own LifenFhir::Logger.
12
+ attr_accessor :logger
13
+
14
+ def initialize
15
+ self.logger = ::LifenFhir::Logger.new(STDOUT)
16
+ end
5
17
 
6
18
  def site=(url)
7
19
  if !/(.*)\/$/.match(url)
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module LifenFhir
4
+ class Rails < ::Rails::Railtie
5
+
6
+ config.before_initialize do
7
+ LifenFhir.configuration.logger = ::Rails.logger
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require 'lifen_fhir/integrations/rails'
@@ -0,0 +1,18 @@
1
+ require 'logger'
2
+
3
+ module LifenFhir
4
+ class Logger < ::Logger
5
+ LOG_PREFIX = "*** [LIFEN] ".freeze
6
+ PROGNAME = "lifen_fhir".freeze
7
+
8
+ def initialize(*)
9
+ super
10
+ @level = ::Logger::INFO
11
+ original_formatter = ::Logger::Formatter.new
12
+ @default_formatter = proc do |severity, datetime, _progname, msg|
13
+ msg = "#{LOG_PREFIX}#{msg}"
14
+ original_formatter.call(severity, datetime, PROGNAME, msg)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module LifenFhir
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/lifen_fhir.rb CHANGED
@@ -19,6 +19,7 @@ module LifenFhir
19
19
 
20
20
  require "lifen_fhir/version"
21
21
 
22
+ require 'lifen_fhir/logger'
22
23
  require 'lifen_fhir/error'
23
24
  require 'lifen_fhir/client'
24
25
  require 'lifen_fhir/user_authenticated_client'
@@ -41,4 +42,29 @@ module LifenFhir
41
42
 
42
43
  Virtus.finalize
43
44
 
45
+ AVAILABLE_INTEGRATIONS = %w(railties).freeze
46
+
47
+ class << self
48
+ extend Forwardable
49
+
50
+ def_delegators :logger
51
+
52
+ def inject
53
+ integrations_to_load = LifenFhir::AVAILABLE_INTEGRATIONS
54
+
55
+ integrations_to_load &= Gem.loaded_specs.keys
56
+ integrations_to_load.each do |integration|
57
+ load_integration(integration)
58
+ end
59
+ end
60
+
61
+ def load_integration(integration)
62
+ require "lifen_fhir/integrations/#{integration}"
63
+ rescue Exception => error
64
+ logger.warn "Unable to load lifen_fhir/integrations/#{integration}: #{error}"
65
+ end
66
+ end
67
+
44
68
  end
69
+
70
+ LifenFhir.inject
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/invalid
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.11.0
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/pdf
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - nginx/1.6.2
25
+ Date:
26
+ - Wed, 05 Apr 2017 12:08:41 GMT
27
+ Content-Type:
28
+ - application/xml+fhir;charset=UTF-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-B3-Sampled:
34
+ - '1'
35
+ X-B3-Spanid:
36
+ - fb30b5b1b27d94fe
37
+ X-B3-Traceid:
38
+ - fb30b5b1b27d94fe
39
+ X-Content-Type-Options:
40
+ - nosniff
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ Cache-Control:
44
+ - no-cache, no-store, max-age=0, must-revalidate
45
+ Pragma:
46
+ - no-cache
47
+ Expires:
48
+ - '0'
49
+ X-Powered-By:
50
+ - HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
51
+ Access-Control-Allow-Credentials:
52
+ - 'true'
53
+ body:
54
+ encoding: UTF-8
55
+ string: |-
56
+ http_version:
57
+ recorded_at: Wed, 05 Apr 2017 12:08:41 GMT
58
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://develop.lifen.fr/valid
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.11.0
12
+ Authorization:
13
+ - Bearer valid_application_access_token
14
+ Accept:
15
+ - application/pdf
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: Success
22
+ headers:
23
+ Server:
24
+ - nginx/1.6.2
25
+ Date:
26
+ - Wed, 05 Apr 2017 12:08:41 GMT
27
+ Content-Type:
28
+ - application/xml+fhir;charset=UTF-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-B3-Sampled:
34
+ - '1'
35
+ X-B3-Spanid:
36
+ - fb30b5b1b27d94fe
37
+ X-B3-Traceid:
38
+ - fb30b5b1b27d94fe
39
+ X-Content-Type-Options:
40
+ - nosniff
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ Cache-Control:
44
+ - no-cache, no-store, max-age=0, must-revalidate
45
+ Pragma:
46
+ - no-cache
47
+ Expires:
48
+ - '0'
49
+ X-Powered-By:
50
+ - HAPI FHIR 2.2 REST Server (FHIR Server; FHIR 1.0.2/DSTU2)
51
+ Access-Control-Allow-Credentials:
52
+ - 'true'
53
+ body:
54
+ encoding: UTF-8
55
+ string: |-
56
+ http_version:
57
+ recorded_at: Wed, 05 Apr 2017 12:08:41 GMT
58
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe LifenFhir::Logger do
4
+
5
+ context "stand alone usage" do
6
+ it "logs to a given IO" do
7
+ stringio = StringIO.new
8
+ log = LifenFhir::Logger.new(stringio)
9
+
10
+ log.fatal("Une erreur est survenue")
11
+
12
+ expect(stringio.string).to end_with("FATAL -- lifen_fhir: *** [LIFEN] Une erreur est survenue\n")
13
+ end
14
+ end
15
+
16
+
17
+ context 'client usage' do
18
+
19
+ let(:client) { LifenFhir::AppAuthenticatedClient.new }
20
+ let(:stringio) { StringIO.new }
21
+
22
+ before do
23
+ LifenFhir.configure do |config|
24
+ config.logger = Logger.new(stringio)
25
+ end
26
+ end
27
+
28
+ it "logs to a given logger" do
29
+ begin
30
+ VCR.use_cassette "logger/invalid" do
31
+ client.get("/invalid")
32
+ end
33
+ rescue LifenFhir::Error => e
34
+
35
+ end
36
+
37
+ expect(stringio.string).to end_with("FATAL -- : *** [LIFEN] 404 Error on GET 'https://develop.lifen.fr/invalid'\n")
38
+ end
39
+
40
+ context 'with a success response' do
41
+
42
+ it "logs to a given logger with info level" do
43
+ VCR.use_cassette "logger/valid" do
44
+ client.get("/valid")
45
+ end
46
+
47
+ expect(stringio.string).to end_with("INFO -- : *** [LIFEN] Success on GET 'https://develop.lifen.fr/valid'\n")
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -31,6 +31,7 @@ RSpec.configure do |c|
31
31
  LifenFhir.configure do |config|
32
32
  config.site = "https://develop.lifen.fr/"
33
33
  config.application_access_token = "valid_application_access_token"
34
+ config.logger = Logger.new(nil)
34
35
  end
35
36
  end
36
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifen_fhir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonard Sellam
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-02 00:00:00.000000000 Z
12
+ date: 2017-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -210,6 +210,9 @@ files:
210
210
  - lib/lifen_fhir/content_string.rb
211
211
  - lib/lifen_fhir/element.rb
212
212
  - lib/lifen_fhir/error.rb
213
+ - lib/lifen_fhir/integrations/rails.rb
214
+ - lib/lifen_fhir/integrations/railties.rb
215
+ - lib/lifen_fhir/logger.rb
213
216
  - lib/lifen_fhir/medium.rb
214
217
  - lib/lifen_fhir/patient.rb
215
218
  - lib/lifen_fhir/practitioner.rb
@@ -231,6 +234,8 @@ files:
231
234
  - spec/cassettes/communication_request/send/unknown_recipient.yml
232
235
  - spec/cassettes/communication_request/send/valid_attributes.yml
233
236
  - spec/cassettes/communication_request/send/valid_attributes_binary.yml
237
+ - spec/cassettes/logger/invalid.yml
238
+ - spec/cassettes/logger/valid.yml
234
239
  - spec/cassettes/patient/create/invalid_attributes.yml
235
240
  - spec/cassettes/patient/create/with_all_information.yml
236
241
  - spec/cassettes/patient/create/with_first_name_as_a_string.yml
@@ -246,6 +251,7 @@ files:
246
251
  - spec/cassettes/practitioner/find_by_rpps/wrong_rpps.yml
247
252
  - spec/category_spec.rb
248
253
  - spec/communication_request_spec.rb
254
+ - spec/logger_spec.rb
249
255
  - spec/patient_spec.rb
250
256
  - spec/practitioner_spec.rb
251
257
  - spec/reference_spec.rb
@@ -290,6 +296,8 @@ test_files:
290
296
  - spec/cassettes/communication_request/send/unknown_recipient.yml
291
297
  - spec/cassettes/communication_request/send/valid_attributes.yml
292
298
  - spec/cassettes/communication_request/send/valid_attributes_binary.yml
299
+ - spec/cassettes/logger/invalid.yml
300
+ - spec/cassettes/logger/valid.yml
293
301
  - spec/cassettes/patient/create/invalid_attributes.yml
294
302
  - spec/cassettes/patient/create/with_all_information.yml
295
303
  - spec/cassettes/patient/create/with_first_name_as_a_string.yml
@@ -305,6 +313,7 @@ test_files:
305
313
  - spec/cassettes/practitioner/find_by_rpps/wrong_rpps.yml
306
314
  - spec/category_spec.rb
307
315
  - spec/communication_request_spec.rb
316
+ - spec/logger_spec.rb
308
317
  - spec/patient_spec.rb
309
318
  - spec/practitioner_spec.rb
310
319
  - spec/reference_spec.rb