red_cap 0.14.1 → 0.14.3

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: 36636ca97ecbc285bee3b241613528ac0613a7b659e748371b2f5b1ec77e9f01
4
- data.tar.gz: 1b0ebfb0a5c072da1547eba1895fce194acc6e448fdc3d75c6c2a389793da8a4
3
+ metadata.gz: b2e03c5ef10902b7ce9982dcbf2443f73b6f8b234f1553ed21ff154c17dc49ac
4
+ data.tar.gz: 36455a58677a5c81223945cba142bd6daae458a419048733ce38efcbc8ab238e
5
5
  SHA512:
6
- metadata.gz: faad7dafd7aca38aae641ffab0f4c1f39510d7bd4304276f4da06325e7325de0e0f0ab898ac952b7891d90efc89d77a6a05d4dc102881f22079879214382e97d
7
- data.tar.gz: d909c706b988d376fa10f77d64417466cf3139127f68ede9c29905777248b876edf9841ea8ef3bf814baf2bb7540dd24a0c84914bd09f9aa747f24c57a15372e
6
+ metadata.gz: d202de08ad7ae6ba2a5649e12b50ddd68d606fab6ed2ea284b31d4ac0bf5eb480929306acbae2e0f358f2033c7590b5f7adda1ca389288d29060f1ade95e4a34
7
+ data.tar.gz: 67ae41683654e716f1356280bb7daf86ae2a038c659c57fe9578e88de0f66cd44597662be94e226d667a2fbd2019b75ae38c5f840823f9ec79caf956d73df631
@@ -9,7 +9,7 @@ jobs:
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
- ruby: ['3.2', '3.3', '3.4']
12
+ ruby: ['3.3', '3.4', '4.0']
13
13
 
14
14
  steps:
15
15
  - uses: actions/checkout@v4
@@ -68,7 +68,7 @@ class REDCap
68
68
  def json_api_request options
69
69
  request_options = options.reverse_merge(format: "json")
70
70
  json = base_request(request_options).body
71
- JSON.load(json)
71
+ parse json
72
72
  end
73
73
 
74
74
  def cached_json_api_request options
@@ -77,11 +77,24 @@ class REDCap
77
77
  request_options = options.reverse_merge(format: "json")
78
78
  base_request(request_options).body
79
79
  end
80
- JSON.load(json)
80
+ parse json
81
81
  end
82
82
 
83
83
  private
84
84
 
85
+ require "active_support/core_ext/string/filters"
86
+ require "cgi/escape"
87
+ def parse json
88
+ JSON.load(json)
89
+ rescue JSON::ParserError
90
+ if json.lstrip.start_with?("<")
91
+ text = json.gsub(%r{<(script|style)\b.*?</\1\s*>}mi, " ").gsub(/<[^>]*>/, " ")
92
+ raise NonJSONResponseError, "REDCap sent an HTML error instead of JSON: #{CGI.unescapeHTML(text).squish.truncate(1000)}"
93
+ else
94
+ raise NonJSONResponseError, "REDCap sent a response that isn't JSON: #{json.squish.truncate(200)}"
95
+ end
96
+ end
97
+
85
98
  def base_request options
86
99
  connection = Faraday.new(url: @url)
87
100
  connection.options.open_timeout = 300
@@ -94,5 +107,8 @@ class REDCap
94
107
  end
95
108
 
96
109
  class Error < StandardError; end
110
+
111
+ # a JSON::ParserError, so callers that rescue Error don't mistake a broken REDCap for an API refusal
112
+ class NonJSONResponseError < JSON::ParserError; end
97
113
  end
98
114
  end
@@ -1,3 +1,3 @@
1
1
  class REDCap
2
- VERSION = "0.14.1"
2
+ VERSION = "0.14.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: faraday
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.6.2
139
+ rubygems_version: 4.0.20
140
140
  specification_version: 4
141
141
  summary: Library for connecting to REDCap and parsing forms and data
142
142
  test_files: []