red_cap 0.10.2 → 0.12.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 +4 -4
- data/.gitignore +2 -0
- 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 +10 -4
- metadata +4 -5
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
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
|
data/.gitignore
CHANGED
@@ -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,13 +8,21 @@ 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
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def initialize url: REDCap.url, token: REDCap.token, per_page: REDCap.per_page
|
19
|
+
@url = url
|
20
|
+
@token = token
|
21
|
+
@per_page = per_page
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_accessor :url, :token, :per_page
|
25
|
+
|
18
26
|
def form
|
19
27
|
@form ||= Form.new(client.metadata)
|
20
28
|
end
|
@@ -43,10 +51,8 @@ class REDCap
|
|
43
51
|
client.delete_records [study_id]
|
44
52
|
end
|
45
53
|
|
46
|
-
private
|
47
|
-
|
48
54
|
def client
|
49
|
-
@client ||= Client.new
|
55
|
+
@client ||= Client.new(url: url, token: token, per_page: per_page)
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
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
|
@@ -89,8 +89,6 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
-
- ".ruby-gemset"
|
93
|
-
- ".ruby-version"
|
94
92
|
- ".travis.yml"
|
95
93
|
- Gemfile
|
96
94
|
- LICENSE.txt
|
@@ -99,6 +97,7 @@ files:
|
|
99
97
|
- bin/console
|
100
98
|
- bin/setup
|
101
99
|
- lib/red_cap.rb
|
100
|
+
- lib/red_cap/cache.rb
|
102
101
|
- lib/red_cap/client.rb
|
103
102
|
- lib/red_cap/form.rb
|
104
103
|
- lib/red_cap/form/fields.rb
|
@@ -123,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
122
|
- !ruby/object:Gem::Version
|
124
123
|
version: '0'
|
125
124
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.5.4
|
127
126
|
signing_key:
|
128
127
|
specification_version: 4
|
129
128
|
summary: Library for connecting to REDCap and parsing forms and data
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
red_cap
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.4.3
|