ndr_lookup 0.2.0 → 0.3.0

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: 4b166463e25022038550ad9bae665670beb892bb3db7571c09433697c50fcb80
4
+ data.tar.gz: 3aca4b0a8550ea824a8d01dd0f84c9e0abc17be5fedb19d3f85d2af925ee2c94
5
5
  SHA512:
6
- metadata.gz: d70a25899667f9006538f119a430fff5984a62aa3e97390d0e0fa99b60da33f4084ae6c2f49527d36f84b49d848568738a206d176b46bed33b1baf83aa96a4e1
7
- data.tar.gz: 68efe8f25d0763497b39d1e1e847b523a75e5c63123c4fcf4b618a14bad0d70a834d5c1e2155d14972e4be6ce6b79fff351f81ad3a0aaba966155855c881156d
6
+ metadata.gz: 4d04c47f6edff7ccb720b62bc27d6e5183658e15995e363ce47a036ec4cc175b2e0c808aca0f5546a40fadbc208e8f480e9a62fea0eeff45e29234cb9d17eb5c
7
+ data.tar.gz: 8b13686621258be52f9c62e6ec06f7dea39a0eea6a95932d374de1a8e81a0b99982b4b3f65d3d22f0f2873e0af225356643c3d77d909b30d15270ebd71c5ea73
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
- * no unreleased changes
2
+
3
+ ## 0.3.0 / 2026-02-26
4
+ ### Added
5
+ * Added specific error classes (InvalidURIError, UnauthorizedError) for granular error handling
6
+ * Extracted common error handling into `with_error_handling` method
7
+
8
+ ### Fixed
9
+ * Support Ruby 3.4. Drop support for Rails 7.0, Ruby 3.1
3
10
 
4
11
  ## 0.1.4 / 2025-09-19
5
12
  ### 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,10 @@ 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
+ with_error_handling("#{resource_type} with ID '#{id}' not found") do
31
+ response = connection.get("#{endpoint}/#{resource_type}/#{id}", headers)
32
+ JSON.parse(response.body)
33
+ end
38
34
  end
39
35
 
40
36
  def endpoint
@@ -51,24 +47,33 @@ module NdrLookup
51
47
  # @example Search for relationships
52
48
  # Client.search('OrganizationAffiliation', organization: 'RHAGX')
53
49
  def search(resource_type, params = {})
54
- url = construct_url(endpoint, resource_type, params)
55
-
56
- # Make the request
57
- response = connection.get(url, headers)
50
+ with_error_handling do
51
+ url = construct_url(endpoint, resource_type, params)
52
+ response = connection.get(url, headers)
53
+ payload = JSON.parse(response.body)
54
+ raise_unless_response_success(response, payload)
55
+ payload
56
+ end
57
+ end
58
58
 
59
- # Process response
60
- payload = JSON.parse(response.body)
61
- raise_unless_response_success(response, payload)
59
+ private
62
60
 
63
- payload
61
+ # Wraps API calls with consistent error handling, converting external exceptions
62
+ # (ActiveResource, JSON, URI) into our own error classes.
63
+ def with_error_handling(not_found_message = nil)
64
+ yield
65
+ rescue ActiveResource::ResourceNotFound
66
+ raise ResourceNotFound, not_found_message || 'Resource not found'
67
+ rescue ActiveResource::UnauthorizedAccess
68
+ raise UnauthorizedError, 'Authentication failed'
64
69
  rescue JSON::ParserError
65
70
  raise InvalidResponse, 'Invalid JSON response from server'
71
+ rescue URI::InvalidURIError => e
72
+ raise InvalidURIError, "Invalid ID format: #{e.message}"
66
73
  rescue StandardError => e
67
- raise ApiError, "Search failed: #{e.message}"
74
+ raise ApiError, "Unexpected error: #{e.message}"
68
75
  end
69
76
 
70
- private
71
-
72
77
  def construct_url(endpoint, resource_type, params = {})
73
78
  url = "#{endpoint}/#{resource_type}"
74
79
 
@@ -1,3 +1,3 @@
1
1
  module NdrLookup
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.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.0
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-02-26 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
  - - ">="