red_cap 0.11.0 → 0.12.0
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: 88f8115fbb2bfe8348227c0d986562831b9a80127652e01b01772dab3079b614
|
4
|
+
data.tar.gz: f4adaa045e58e265fc2d47dea594a521361653eca94f9114563162cefd4d6092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8422a83dbbd9380f01c5ad3c171c50c05e7349d1984a8b4d4f387945e666ad2fe7eaceaba969aac37939ac66cc5ab2dd3a7c0682860872a204a369dba67b10b1
|
7
|
+
data.tar.gz: 7f0d8b5760d68accf9d2911644b2175768ba68815e54776ca2eae1c766f8ab1c72ebdf35feab3ab14261bf38e29b4149268815d3bd93f0a5bfdd523ea4c1fcd0
|
@@ -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.exists?(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.0
|
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-02-08 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.5.4
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Library for connecting to REDCap and parsing forms and data
|