red_cap 0.11.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/red_cap/cache.rb +23 -0
- data/lib/red_cap/client.rb +17 -7
- data/lib/red_cap/form/fields.rb +2 -1
- data/lib/red_cap/version.rb +1 -1
- data/lib/red_cap.rb +1 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd9606811238e9bdb1b1631958b96015870257419b4c83165631028ddbf2fdd2
|
4
|
+
data.tar.gz: a2604ed8e68436afbdcc4a7be836d827c9331a2610a8d245fdd04c000ff04aa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 701a73e5cb940b753e4bfdf618d0667fa5a2a67a5267c4fafdadb6a5213805e83971a08c333c96f46cb1ebeb76e8f308939697f4a6b184a4dd15666d0ba9253b
|
7
|
+
data.tar.gz: c95e08ea6752e3c403c9abe84351cf1adb92bdfe20b249311e069c696b64266232f45a7b9276764e215e37cacc6bfb49f32c8c400971e1644aee4ad8619575a2
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class REDCap
|
2
|
+
class Cache
|
3
|
+
def self.fetch url, &block
|
4
|
+
key = Digest::MD5.hexdigest(url)
|
5
|
+
|
6
|
+
dir = "tmp/redcap_cache"
|
7
|
+
path = dir + "/#{key}"
|
8
|
+
|
9
|
+
if REDCap.cache && ::File.exist?(path)
|
10
|
+
::File.read(path)
|
11
|
+
else
|
12
|
+
raw = block.call
|
13
|
+
|
14
|
+
if REDCap.cache
|
15
|
+
FileUtils.mkdir_p dir
|
16
|
+
::File.write(path, raw)
|
17
|
+
end
|
18
|
+
raw
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/red_cap/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "json"
|
2
2
|
require "faraday"
|
3
|
+
require "red_cap/cache"
|
3
4
|
|
4
5
|
class REDCap
|
5
6
|
class Client
|
@@ -40,12 +41,13 @@ class REDCap
|
|
40
41
|
json_api_request(content: "metadata")
|
41
42
|
end
|
42
43
|
|
43
|
-
def file record_id, file_id
|
44
|
+
def file record_id, file_id, event: nil
|
44
45
|
response = base_request({
|
45
46
|
content: "file",
|
46
47
|
action: "export",
|
47
48
|
record: record_id,
|
48
49
|
field: file_id,
|
50
|
+
event: event,
|
49
51
|
})
|
50
52
|
_, type, filename = *response.headers["content-type"].match(/\A(.+); name=\"(.+)\"/)
|
51
53
|
File.new(response.body, type, filename)
|
@@ -56,15 +58,23 @@ class REDCap
|
|
56
58
|
private
|
57
59
|
|
58
60
|
def fetch_study_ids filter=nil
|
59
|
-
json_api_request(
|
60
|
-
|
61
|
+
json_api_request({
|
62
|
+
content: "record",
|
63
|
+
fields: "study_id",
|
64
|
+
filterLogic: filter,
|
65
|
+
}).map { |hash| hash["study_id"] }
|
61
66
|
end
|
62
67
|
|
68
|
+
require "active_support/core_ext/object/to_query"
|
63
69
|
def json_api_request options
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
full_url = @url + "?" + options.to_query
|
71
|
+
json = Cache.fetch(full_url) do
|
72
|
+
response = base_request(options.reverse_merge({
|
73
|
+
format: "json",
|
74
|
+
}))
|
75
|
+
response.body
|
76
|
+
end
|
77
|
+
JSON.load(json)
|
68
78
|
end
|
69
79
|
|
70
80
|
def base_request options
|
data/lib/red_cap/form/fields.rb
CHANGED
@@ -57,7 +57,6 @@ class REDCap
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
class Descriptive < Field; end
|
60
|
-
class Dropdown < Field; end
|
61
60
|
class Sql < Field; end
|
62
61
|
|
63
62
|
class File < Field
|
@@ -96,6 +95,8 @@ class REDCap
|
|
96
95
|
# default "radio" implementation
|
97
96
|
Radio = RadioButtons
|
98
97
|
|
98
|
+
class Dropdown < RadioButtons; end
|
99
|
+
|
99
100
|
class Checkboxes < RadioButtons
|
100
101
|
def value responses
|
101
102
|
selected_options(responses).values
|
data/lib/red_cap/version.rb
CHANGED
data/lib/red_cap.rb
CHANGED
@@ -8,7 +8,7 @@ class REDCap
|
|
8
8
|
yield self
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_accessor :url, :token, :per_page
|
11
|
+
attr_accessor :url, :token, :per_page, :cache
|
12
12
|
|
13
13
|
def per_page
|
14
14
|
@per_page ||= 100
|
@@ -51,8 +51,6 @@ class REDCap
|
|
51
51
|
client.delete_records [study_id]
|
52
52
|
end
|
53
53
|
|
54
|
-
private
|
55
|
-
|
56
54
|
def client
|
57
55
|
@client ||= Client.new(url: url, token: token, per_page: per_page)
|
58
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red_cap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- bin/console
|
98
98
|
- bin/setup
|
99
99
|
- lib/red_cap.rb
|
100
|
+
- lib/red_cap/cache.rb
|
100
101
|
- lib/red_cap/client.rb
|
101
102
|
- lib/red_cap/form.rb
|
102
103
|
- lib/red_cap/form/fields.rb
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.2.32
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Library for connecting to REDCap and parsing forms and data
|