red_cap 0.8.0 → 0.10.2
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/client.rb +16 -4
- data/lib/red_cap/form/fields.rb +1 -1
- data/lib/red_cap/form.rb +1 -1
- data/lib/red_cap/version.rb +2 -2
- data/lib/red_cap.rb +35 -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: 6fc5286a5227f33663a6a68e819fe69927d553f2471ddbac24188fc8ad37bc2d
|
4
|
+
data.tar.gz: 42f7e00abc8da8759f64ae352c5c246194d0b31814f46aeab2643d1ea49d41d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b142fbcd60c041cab4eab6a86d7f3edb64054a293e80a81289d7b77e5f5bebbf3846698b6a0b3683846b03f833f6c43968a1d8ffceae74958580eba2d32f9e
|
7
|
+
data.tar.gz: 4c57abb84500a0fabb17b4b90d2aa323aef8a3f10321eb293732623e1139a0712e2f8d9c67cfa6865df84cdbdd7320315a023dbedfdb07782508f866fc18a471
|
data/lib/red_cap/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "json"
|
2
2
|
require "faraday"
|
3
3
|
|
4
|
-
|
4
|
+
class REDCap
|
5
5
|
class Client
|
6
6
|
def initialize url: REDCap.url, token: REDCap.token, per_page: REDCap.per_page
|
7
7
|
@url = url
|
@@ -24,6 +24,18 @@ module REDCap
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def find_record study_id
|
28
|
+
json_api_request(content: "record", records: study_id).first
|
29
|
+
end
|
30
|
+
|
31
|
+
def save_records records
|
32
|
+
json_api_request(content: "record", data: records.to_json, overwriteBehavior: "overwrite")
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_records study_ids
|
36
|
+
json_api_request(content: "record", action: "delete", records: study_ids)
|
37
|
+
end
|
38
|
+
|
27
39
|
def metadata
|
28
40
|
json_api_request(content: "metadata")
|
29
41
|
end
|
@@ -35,7 +47,7 @@ module REDCap
|
|
35
47
|
record: record_id,
|
36
48
|
field: file_id,
|
37
49
|
})
|
38
|
-
_, type, filename = *response.headers["content-type"].match(/\A(.+); name=\"(.+)\"
|
50
|
+
_, type, filename = *response.headers["content-type"].match(/\A(.+); name=\"(.+)\"/)
|
39
51
|
File.new(response.body, type, filename)
|
40
52
|
end
|
41
53
|
|
@@ -60,8 +72,8 @@ module REDCap
|
|
60
72
|
connection.options.open_timeout = 300
|
61
73
|
connection.options.timeout = 300
|
62
74
|
response = connection.post nil, options.reverse_merge(token: @token)
|
63
|
-
if
|
64
|
-
raise Error.new(
|
75
|
+
if response.body =~ /^{"error":"/
|
76
|
+
raise Error.new(response.body)
|
65
77
|
end
|
66
78
|
response
|
67
79
|
end
|
data/lib/red_cap/form/fields.rb
CHANGED
data/lib/red_cap/form.rb
CHANGED
data/lib/red_cap/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class REDCap
|
2
|
+
VERSION = "0.10.2"
|
3
3
|
end
|
data/lib/red_cap.rb
CHANGED
@@ -2,7 +2,7 @@ require "red_cap/version"
|
|
2
2
|
require "red_cap/client"
|
3
3
|
require "red_cap/form"
|
4
4
|
|
5
|
-
|
5
|
+
class REDCap
|
6
6
|
class << self
|
7
7
|
def configure
|
8
8
|
yield self
|
@@ -14,5 +14,39 @@ module REDCap
|
|
14
14
|
@per_page ||= 100
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
def form
|
19
|
+
@form ||= Form.new(client.metadata)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find study_id
|
23
|
+
client.find_record study_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def all &block
|
27
|
+
client.records &block
|
28
|
+
end
|
29
|
+
|
30
|
+
def where conditions, &block
|
31
|
+
filters = conditions.reduce([]) do |filters, (field, value)|
|
32
|
+
filters << "[#{field}]=#{value}"
|
33
|
+
end
|
34
|
+
client.records(filters.join(" AND "), &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update study_id, attributes
|
38
|
+
record = attributes.merge(study_id: study_id).stringify_keys
|
39
|
+
client.save_records [record]
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete study_id
|
43
|
+
client.delete_records [study_id]
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def client
|
49
|
+
@client ||= Client.new
|
50
|
+
end
|
17
51
|
end
|
18
52
|
|
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.10.2
|
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: 2021-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.0.
|
126
|
+
rubygems_version: 3.0.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Library for connecting to REDCap and parsing forms and data
|