ndr_lookup 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef8ffa13786096c8d95f8d8454d8b1e60611d71c9d54a72f57d6d64a8c13eeda
4
- data.tar.gz: 87ded454a35954c619f0b785af5a1eaf6b95070d7a628f60d56dd662f3de628f
3
+ metadata.gz: c67e55ec9b88c908bc7f68e98ac30da65c563d693da24c43dfea644c1cb2eeaa
4
+ data.tar.gz: e65b75ddde2fa3201cb0352d6db6215b3ff1faa871b6b7ec923625a8345e77b0
5
5
  SHA512:
6
- metadata.gz: d70a25899667f9006538f119a430fff5984a62aa3e97390d0e0fa99b60da33f4084ae6c2f49527d36f84b49d848568738a206d176b46bed33b1baf83aa96a4e1
7
- data.tar.gz: 68efe8f25d0763497b39d1e1e847b523a75e5c63123c4fcf4b618a14bad0d70a834d5c1e2155d14972e4be6ce6b79fff351f81ad3a0aaba966155855c881156d
6
+ metadata.gz: 972783e32d189ee2e00ba641f5c9f4d4589844616f22fe3c71f8e7eb5db06daaab1a5004987b052050ef18e70603b04eaac52d1de412aded1c8c539124b3d1ed
7
+ data.tar.gz: c970724bc8e20c8771677a7e4bb1a0cef52614c793f87b7daefc7c3e019f30fed483075dc7aa52f4443e94009ca9c49b861ba276c8f38cef088b119af77fcdc4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
- * no unreleased changes
2
+
3
+ ## 0.3.1 / 2026-03-05
4
+ ### Fixed
5
+ * Strip whitespace from IDs in FHIR Base.find to prevent bad URI errors
6
+ * Handle ApiError/InvalidURIError gracefully in Organisation.find
7
+
8
+ ## 0.3.0 / 2026-02-26
9
+ ### Added
10
+ * Added specific error classes (InvalidURIError, UnauthorizedError) for granular error handling
11
+ * Extracted common error handling into `with_error_handling` method
12
+
13
+ ### Fixed
14
+ * Support Ruby 3.4. Drop support for Rails 7.0, Ruby 3.1
3
15
 
4
16
  ## 0.1.4 / 2025-09-19
5
17
  ### Added
@@ -6,9 +6,12 @@ module NdrLookup
6
6
  module Fhir
7
7
  # Client for interacting with the NHS Digital FHIR API
8
8
  class Base < ActiveResource::Base
9
+ # Specific error classes for different API failure modes
9
10
  class ApiError < StandardError; end
10
11
  class ResourceNotFound < ApiError; end
11
12
  class InvalidResponse < ApiError; end
13
+ class InvalidURIError < ApiError; end
14
+ class UnauthorizedError < ApiError; end
12
15
 
13
16
  class << self
14
17
  attr_writer :additional_headers
@@ -24,17 +27,11 @@ module NdrLookup
24
27
  # Finds a specific FHIR resource by type and ID
25
28
  # @return [Hash] Parsed FHIR resource
26
29
  def find(resource_type, id)
27
- response = connection.get(
28
- "#{endpoint}/#{resource_type}/#{id}",
29
- headers
30
- )
31
- JSON.parse(response.body)
32
- rescue ActiveResource::ResourceNotFound
33
- raise ResourceNotFound, "#{resource_type} with ID '#{id}' not found"
34
- rescue JSON::ParserError
35
- raise InvalidResponse, 'Invalid JSON response from server'
36
- rescue StandardError => e
37
- raise ApiError, "Unexpected error: #{e.message}"
30
+ sanitized_id = id.to_s.strip
31
+ with_error_handling("#{resource_type} with ID '#{sanitized_id}' not found") do
32
+ response = connection.get("#{endpoint}/#{resource_type}/#{sanitized_id}", headers)
33
+ JSON.parse(response.body)
34
+ end
38
35
  end
39
36
 
40
37
  def endpoint
@@ -51,24 +48,33 @@ module NdrLookup
51
48
  # @example Search for relationships
52
49
  # Client.search('OrganizationAffiliation', organization: 'RHAGX')
53
50
  def search(resource_type, params = {})
54
- url = construct_url(endpoint, resource_type, params)
55
-
56
- # Make the request
57
- response = connection.get(url, headers)
51
+ with_error_handling do
52
+ url = construct_url(endpoint, resource_type, params)
53
+ response = connection.get(url, headers)
54
+ payload = JSON.parse(response.body)
55
+ raise_unless_response_success(response, payload)
56
+ payload
57
+ end
58
+ end
58
59
 
59
- # Process response
60
- payload = JSON.parse(response.body)
61
- raise_unless_response_success(response, payload)
60
+ private
62
61
 
63
- payload
62
+ # Wraps API calls with consistent error handling, converting external exceptions
63
+ # (ActiveResource, JSON, URI) into our own error classes.
64
+ def with_error_handling(not_found_message = nil)
65
+ yield
66
+ rescue ActiveResource::ResourceNotFound
67
+ raise ResourceNotFound, not_found_message || 'Resource not found'
68
+ rescue ActiveResource::UnauthorizedAccess
69
+ raise UnauthorizedError, 'Authentication failed'
64
70
  rescue JSON::ParserError
65
71
  raise InvalidResponse, 'Invalid JSON response from server'
72
+ rescue URI::InvalidURIError => e
73
+ raise InvalidURIError, "Invalid ID format: #{e.message}"
66
74
  rescue StandardError => e
67
- raise ApiError, "Search failed: #{e.message}"
75
+ raise ApiError, "Unexpected error: #{e.message}"
68
76
  end
69
77
 
70
- private
71
-
72
78
  def construct_url(endpoint, resource_type, params = {})
73
79
  url = "#{endpoint}/#{resource_type}"
74
80
 
@@ -21,6 +21,9 @@ module NdrLookup
21
21
  rescue Client::ResourceNotFound => e
22
22
  logger.info("Organization not found: #{e.message}")
23
23
  nil
24
+ rescue Client::ApiError, Client::InvalidURIError => e
25
+ logger.warn("Organization lookup failed for '#{id}': #{e.message}")
26
+ nil
24
27
  end
25
28
 
26
29
  # ActiveRecord subs .all in to /all which then becomes like finding the id 'all'
@@ -1,3 +1,3 @@
1
1
  module NdrLookup
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndr_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NCRS Development Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-25 00:00:00.000000000 Z
11
+ date: 2026-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '7.0'
39
+ version: '7.1'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '8.1'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '7.0'
49
+ version: '7.1'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '8.1'
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="
192
192
  - !ruby/object:Gem::Version
193
- version: '3.0'
193
+ version: '3.2'
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements:
196
196
  - - ">="