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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/lib/red_cap/client.rb +18 -2
- data/lib/red_cap/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2e03c5ef10902b7ce9982dcbf2443f73b6f8b234f1553ed21ff154c17dc49ac
|
|
4
|
+
data.tar.gz: 36455a58677a5c81223945cba142bd6daae458a419048733ce38efcbc8ab238e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d202de08ad7ae6ba2a5649e12b50ddd68d606fab6ed2ea284b31d4ac0bf5eb480929306acbae2e0f358f2033c7590b5f7adda1ca389288d29060f1ade95e4a34
|
|
7
|
+
data.tar.gz: 67ae41683654e716f1356280bb7daf86ae2a038c659c57fe9578e88de0f66cd44597662be94e226d667a2fbd2019b75ae38c5f840823f9ec79caf956d73df631
|
data/.github/workflows/ci.yml
CHANGED
data/lib/red_cap/client.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
data/lib/red_cap/version.rb
CHANGED
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.
|
|
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:
|
|
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:
|
|
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: []
|